-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.AspNetCore.OpenApi: Support API versioning (required for Swashbuckle feature parity) #56314
Comments
@josundt Thanks for filling this issue! Things actually work the other way around with respect to API versioning + OpenAPI in ASP.NET Core. The All OpenAPI implementations in the ASP.NET ecosystem depend on API Explorer (NSwag, Swashbuckle, and our own Microsoft.AspNetCore.OpenApi) and can pick up the additional metadata that Asp.Versioning adds to the ApiExplorer interfaces in order to access versioning information. With regard to how the new Have you tried using |
Removing the
|
@captainsafia I'll try to perform a test migration of one of one of our APIs by looking at eShop repo today or tomorrow. I'll get back to you 👍 |
@captainsafia
After studying the eShop repo PR you mentioned, I managed to get a simple API running with two API versions (separate OpenAPI documents per version) and build-time OpenAPI documents generation. You can see my small sample project here. Findings/feedback:
|
@captainsafia I have not received any feedback on this. |
@josundt Apologies for the delay here! My focus has been on dev-related work over the past few weeks as we barrel closer to RC1. 😄
I think @martincostello provided a great answer here. This space has been evolving in reaction to customer feedback. I'd recommend trying the latest nightly bits of the package to see where things currently are and sharing your feedback there.
The issue that you're describing here is a limitation of the way that This is primarily because we don't have a good way of inferring the HTTP status code that your error result is associated with, which is the primary key for response schemas in both ApiExplorer and OpenAPI. To fix this, you need to clue the famework in on what type of response your ProblemDetails is assocaited with by adding the metadata yourself (either via As a converse to this, you'll observe that the ValidationProblem type in TypedResults does provide the correct metadata by default. That's because there, we can make an inference that your status code is 4xx based on the semantics of the platform. TL;DR: The lack of specificity #52424 is another bug report around this in case you'd like to thumbs that up or chime in there.
Yep, XML support isn't in yet. I've been playing around in this space though and hope to post an update on this issue (#39927) for it soon.
I think the scenario that you are describing here is specific to controller-based APIs in MVC, where users have more flexibility to configure output formatters than they do in minimal APIs. In minimal APIs, the only content-types we'll automatically infer are In this case, ApiExplorer is doing its best to present an accurate representation of what outputs your API might return based on MVC's default output formatting configuration (which supports writing to multiple response content-types by default). In this case, the action that you've taken is one way to clue in the system that you want to restrict the types of response content-types that are supported. Explicitly setting the With respect to documenting this officially, we do cover it in this section of the docs. I'm a little hesitant to include it in the top-level OpenAPI-docs given it is (a) MVC-specific and (b) more relevant to output formatting/content negotation than it is OpenAPI.
Yep, this is a good observation. You might've noticed that the same transformation code is applied in the Asp.Versioning samples for both Swashbuckle and Microsoft.AspNetCore.OpenApi. I agree with you that it probably makes sense for the Asp.Versioning package to provide these as first-class APIs for both implementations so that users don't have to copy them into application code. Would you be able to file an issue on the Asp.Versioning repo for this? |
Hello. I have just updated .NET and Microsoft.AspNetCore.OpenApi to 9.0 preview 7, and I see more improvements.
BTW: I have no new feedback for 4., 5. and 6. |
In a schema transformer you access the |
@martincostello The example you sent me is from a schema transformer, not from an operation transformer. I'm trying to change the content-type for an operation response*; that can only be done through operation or document transformers, correct? |
Here's an operation transformer from the same repo - the information you're looking for can be found via |
@martincostello I finally had time to have another look and this time figured it out. Thanks for guiding me in the right direction!👍 PS! I hope the way I map items in On another note; I'm awaiting feedback to my comment about the current behavior where individual schema definitions are created for collection types:
I assume there's a plan to do change this, right? |
From what I've seen, arrays seem to be inlined if the elements aren't re-used anywhere else, but if there's commonality they're extracted out into their own schema reference so it goes from schema that is an array of items to array of schema reference. |
@martincostello I think we are talking about two different things here, I am not talking about the array items, but the array itself. Array schemas (the arrays, not the items) should in my opinion always be inlined even if there's "commonality". PS! For other .NET generic types; types not derived from Swashbuckle consistently extracts the following .NET types as schema definitions regardless of "commonality"; -regardless of whether schemas are referenced single/multiple times:
When considering which types should be "extracted" to This is also how it works with SwashBuckle. |
I think we are talking about the same thing. Here are some examples of the scenarios I was referring to from my snapshot tests. A property which is an array of a schema: https://github.com/martincostello/aspnetcore-openapi/blob/365c761581473f47212d91bb85bfb51fc4993666/tests/TodoApp.Tests/OpenApiTests.Schema_Is_Correct_schemaUrl%3Dopenapi.verified.txt#L329-L335 A schema that is an array itself, whose items are a schema reference: https://github.com/martincostello/openapi-extensions/blob/3331a70264b302e855c42278dc699f4c370473e6/tests/OpenApi.Extensions.Tests/IntegrationTests.Schema_Is_Correct_For_Classes.verified.txt#L117-L122 A schema that is an array itself, whose items are defined inline and are not a reference: https://github.com/martincostello/openapi-extensions/blob/3331a70264b302e855c42278dc699f4c370473e6/tests/OpenApi.Extensions.Tests/IntegrationTests.Schema_Is_Correct_For_Records.verified.txt#L52-L73 I believe the difference in how they are rendered depends on whether the "shapes" are used more than once. When two identical schemas are found, they're extracted out to a common component for reference. You're right that it's different behaviour to Swashbuckle, as there as nothing it compared for equivalence with regard to the shape of the schemas - it's entirely driven by the runtime types used by the APIs implementation. My understanding is that this is an intentional design decision, but the team can answer that. |
@martincostello So to round things up, whether a schema should be extracted to
I guess both solutions are technically correct, but while the Microsoft uses a traditional "circular reference handling" approach, SwashBuckle's generated documents become more deterministic and well-structured, with improved human readability and discoverability. Example: I know that in a SwashBuckle generated document, the complete, alphabetically sorted list of complex type (+enum) schemas is found under These document characteristics are important for developers when they review validity/quality of OpenAPI documents generated for the AspNetCore APIs that they're writing, but also when they inspect OpenAPI documents for other APIs consumed by software that they're writing. I hope you find my perspectives valuable and I'm hoping you may reconsider the approach. |
This isn't something to pitch to me - I'm just a fellow member of the ASP.NET Core community and user-base. @captainsafia Thoughts on the above? |
@captainsafia Any feedback on my perspectives above? I'd like to add one more argument: "Extracted" schemas are named which provides additional valuable information compared to "inlined" schemas. It makes it easier to correlate swagger schemas to their .NET complex/enum source types. |
I am migrating from In my project, I have an API structured with controllers, each assigned to a specific version using attributes. However, API versions are not explicitly defined in When using Thank you in advance for your support! |
@sgluca Are you using the Asp.Versioning package to implement API versioning? If so, then currently the answer to your question is no. There is no way (that I know of) for the built-in OpenAPI generation to detect the versions that are configured and generate the corresponding documents. I recently went through this process with the eShop demo app and I had to specify the API versions explicitly with separate calls to AddOpenApi. It's possible this could change in the future but for right now that is the only solution available. |
@josundt Regarding the main subject of this issue, I think we have demonstrated with the eShop demo app that the .NET 9 OpenAPI generation does integrate with Asp.Versioning to support API versioning. Admittedly there as some aspects of this that could be improved but the basic functionality seems to be all there. There were a number of other points raised here -- and thank you for all this feedback -- and most of these are either fixed before the 9.0 release (e.g. handling of collection schemas), will be fixed shortly (duplicate schemas), or tracked in other issues (content-types for problem details).
I'm going to mark this as "Needs Author Feedback" to give you an opportunity to point out anything that you think is not covered. |
Hi @josundt. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
We currently use .NET 8.0/AspNetCore with Swashbuckle.AspNetCore in many APIs in our product ecosystem.
The current OpenApi documentations are very good with multiple API versions, good descriptions/comments, security defs/refs etc.
Swashbuckle.AspNetCore integrates with the package Asp.Versioning.Mvc.ApiExplorer to enable and simplify API versioning.
It augments SwashBuckle's capabilities (that we currently depend upon):
[ApiVersion("version")]
attributes.These attributes add metadata describing in which version(s) the Controllers/ActonMethods are included.
{version:apiVersion}
route parameters that maps/has constraints to the tagged versions for Controller/ActionMethod.Swashbuckle parses this metadata to enable splitting into multiple OpenApi documents - one JSON file per version.
I think the currently way of managing API versioning is simple and it works very well, and I hope the goal for Microsoft.AspNetCore.OpenApi is to get close to feature parity with Swashbuckle.AspNetCore and to make migration as easy as possible.
Describe the solution you'd like
This is a feature request to support API versioning, hopefully a similar way.
I don't know if you plan to integrate with Asp.Versioning.Mvc.ApiExplorer, but hope you can use similar concepts.
Can you ellaborate about the current plans to support API versioning?
Additional context
No response
The text was updated successfully, but these errors were encountered: