Skip to content

Conversation

@gabr0236
Copy link

@gabr0236 gabr0236 commented Dec 3, 2025

Updates the IOpenApiDocumentProvider example in
aspnetcore/fundamentals/openapi/using-openapi-documents.md to:

  • Inject the provider as a keyed service using [FromKeyedServices("v1")].
  • Call GetOpenApiDocumentAsync with an optional CancellationToken instead of a document name.
  • Note that the service key "v1" must match the name passed to AddOpenApi.

The previous sample did not compile (because GetOpenApiDocumentAsync does not take a document name parameter) and did not reflect the keyed registration used by AddOpenApi("v1").


Internal previews

📄 File 🔗 Preview link
aspnetcore/fundamentals/openapi/using-openapi-documents.md Use openAPI documents

@gabr0236
Copy link
Author

gabr0236 commented Dec 3, 2025

@captainsafia FYI

@guardrex guardrex requested a review from captainsafia December 3, 2025 10:54
@guardrex
Copy link
Collaborator

guardrex commented Dec 30, 2025

Hi @gabr0236! Sorry for the delay. I don't think Safia saw the ping. I sent her an email. Give her a little time to respond due to the holidays. Most of us are either totally OOF or working limited days until the first week of January. Happy New Year! 🥳

BTW ... Please resolve the conflict, so she can see the changes that you're requesting.

@guardrex guardrex self-assigned this Dec 30, 2025
Updates the `IOpenApiDocumentProvider` example in
`aspnetcore/fundamentals/openapi/using-openapi-documents.md` to:

* Inject the provider as a keyed service using `[FromKeyedServices("v1")]`.
* Call `GetOpenApiDocumentAsync` with an optional `CancellationToken` instead of a document name.
* Note that the service key `"v1"` must match the name passed to `AddOpenApi`.

The previous sample did not compile and did not reflect the keyed registration used by `AddOpenApi("v1")`.
@gabr0236
Copy link
Author

Hi @guardrex, no worries. I resolved the conflicts. Happy new years!

@guardrex
Copy link
Collaborator

guardrex commented Dec 31, 2025

Thanks!

BTW ... You and Safia will work out the final details; but in passing, it seems like ...

  • A primary ctor seems in order here.
  • The method should remain async.
  • The method should be an expression-bodied method.
  • There's no need to underscore the parameter name.

For comparison and consideration (and I'm breaking the lines to adhere to our 85 character line length limit) ...

public class CustomDocumentService(
    [FromKeyedServices("v1")] IOpenApiDocumentProvider documentProvider)
{
    public async Task<OpenApiDocument> GetApiDocumentAsync(
            CancellationToken cancellationToken = default) =>
        await documentProvider.GetOpenApiDocumentAsync(cancellationToken);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants