-
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
OpenAPI document generation tool feedback #57044
Comments
Another fun thing I just bumped into that I figured I'd at least make a note of here. If a project still has a reference to Explicitly setting |
Glad you were looking into this at the same time 😄. Can confirm this is an issue. Based on the other UI tools (ReDoc, Scalar) we're more than likely going to swap our OpenApi documentation generation to Microsoft's implementation but stick with SwaggerUI, so we would hope to continue referencing Swashbuckle.AspNetCore. Also curious if |
You could try removing the reference to
It's intended to eventually (see #39927 (comment)), but doesn't at the moment. For now I've written a custom transformer that does as much as I need for my own purposes: #56318 (comment) You could copy that and expand as-needed for your own needs. |
Thanks! I'll watch those other threads and take a look at the custom transformer. |
@martincostello Thanks for sharing this feedback! So....I have a love/hate relationship with the strategy that we currently use for build-time OpenAPI document generation. 😅 For context, this functionality is supported by another package we ship (https://www.nuget.org/packages/Microsoft.Extensions.ApiDescription.Server) and was primarily implemented with the assumption that another package (like Swashbuckle or NSwag) would be installed alongside it. You'll observe this in the rather hokey use of the "pubternal" In the long-term, I'd like to move away from the use of this package for build-time document generation and move to something more built-in to the I've been conservative about the changes made to this package for .NET 9 in anticipation of exploring a possible rewrite for this in the future. Here's a braindump of some of the things I've been thinking about here:
So, all this to say, I agree that the tool is carrying a lot of cruft, but my current thinking is that exploring a full rewrite within M.A.OpenApi is a better strategy in the long-term. Thoughts? |
I guess something that committed to one approach or the other (MSBuild or tools) would be better 😄 Separate to that, I can see why moving to something new would allow for greater agility with what the tool does, as it wouldn't be constrained to the duck-typed interface's constraints. Are any of the specific items that are low-cost to address worth addressing for .NET 9 anyway? As it's still the documented approach for this kind of build-time generation, any low-hanging fruit that avoid any paper cuts would be beneficial IMHO. I'd be happy to tackle any that are wanted (and can make it in time for .NET 9) - just let me know which ones. The first three items in the description seem like quick fixes to me. For my own projects, the only reason I actually have for using the generator is to generate a static file for deploying with native AoT deployed apps in wwwroot. However, with M.A.OpenApi supporting native AoT, for my own needs that's now moot for .NET 9 as I can now dynamically generate the content 🥳 |
@MauriceChocoSwiss opened #56974 because he was keen to be able to support modifying the name of the outputted file. This would be above my bar for things I'd feel OK including at this point given the friction point that was identified. It's also good signal for the kinds of things people care about customizing in a possible rewrite. The OpenAPI version option was introduced in this release for a similar reason. There were some niche scenarios in VS where you needed to override the version configured in
I think things like fully qualifying The other unfortunate thing about the tool is the testing story is a little subpar. I added some tests for it in #55823 but we definitely don't have the kind of coverage I'd like to see as we make changes... |
Ok cool - I'll try and do a PR for both of those tomorrow. Which approach would you prefer for suppressing the console warning? |
I'm in favor of
The warning is misleading. If you don't provide a value, it'll fallback to the value defined in |
Convert `$(OpenApiDocumentsDirectory)` to a full path before passing it to the `dotnet-getdocument` tool. Relates to dotnet#57044.
Do not emit warning about an invalid OpenAPI version in the `dotnet-getdocument` tool if no explicit value was passed to the tool via the `` argument. Relates to dotnet#57044.
…57096) * Get full path of OpenApiDocumentsDirectory Convert `$(OpenApiDocumentsDirectory)` to a full path before passing it to the `dotnet-getdocument` tool. Relates to #57044. * Avoid warning about invalid OpenAPI version Do not emit warning about an invalid OpenAPI version in the `dotnet-getdocument` tool if no explicit value was passed to the tool via the `` argument. Relates to #57044. * Fix TargetTest tests Fix tests failing locally in Visual Studio due to test assets not being copied to the output directory. * Fix tests Fix assertions looking for relative paths instead of absolute paths.
@Cjewett To add to what @martincostello shared here, check out the comment I recently posted on the tracking issue. |
Will this package continue to work if we do not switch to the new OpenApi generation? We plan to stick with Swashbuckle, at least until v10. It'd be very unfortunate if it stopped working. I assume OpenApi generation is going to be opt-in and not automatically pulled in by the SDK/SFX, thus making it so there's no conflict, but at this point I'm uncertain. (We also use MS.E.ApiDescription.Client with NSwag.MsBuild to generate our API clients. It doesn't sound like this side of things would be impacted in any case) |
From my testing it's definitely still opt-in. AFAIK, it would still work with Swashbuckle (or any other tool that implements the same interface to expose the generation). |
Playing around with the OpenAPI document CLI generation from Lint generated OpenAPI documents with Spectral I found a few issues and rough edges. Rather than create lots of small issues I figured I'd list them all here, and they can be spun off into dedicated issues based on feedback/triage.
OpenApiDocumentsDirectory is not resolved to a full path
If
OpenApiDocumentsDirectory
is specified as a relative path (e.g.dotnet build ./src/API /p:OpenApiGenerateDocuments=true /p:OpenApiDocumentsDirectory="./artifacts/openapi"
), the path is not resolved to a full path, and then ends up as a path relative to the tool invocation, rather than relative to the current working directory of the command, so the document ends up in thebin\Debug
etc. folder rather than the folder the user expected.Seems like resolving the full path here in the MSBuild targets before invoking the tool would resolve that:
aspnetcore/src/Tools/Extensions.ApiDescription.Server/src/build/Microsoft.Extensions.ApiDescription.Server.targets
Line 56 in 06155c0
"Invalid OpenAPI spec version" warning
If the target is run without explicitly an OpenAPI document version to generate, a warning is output:
This comes from here:
aspnetcore/src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommandWorker.cs
Line 329 in 06155c0
If this
Enum.TryParse()
call fails to parse anything:aspnetcore/src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommandWorker.cs
Line 323 in 06155c0
It looks like there's a few ways to resolve this:
GetDocumentCommandContext.OpenApiVersion
if no value is provided:aspnetcore/src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommand.cs
Line 141 in 06155c0
GetDocumentCommandContext.OpenApiVersion
is null/empty (rather than a value that doesn't parse)--openapi-version
through from the MSBuild target:aspnetcore/src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommand.cs
Line 33 in 06155c0
No MSBuild property for specifying the OpenAPI version
It's possible to add extra options to work around the above using
OpenApiGenerateDocumentsOptions
(e.g./p:OpenApiGenerateDocumentsOptions="--openapi-version OpenApi3_0"
), but there isn't a specific MSBuild property for this.To make usage easier a property could be defined that the user can specify to set the version without needing to explicitly set command line parameters that the MSBuild target could transform and pass through to the tool (e.g.
/p:OpenApiGenerateDocumentVersion=3.0
into--openapi-version OpenApi3_0
).MSBuild properties not affecting "up-to-date-ness"
I noticed when the path wasn't being fully evaluated, if I re-ran the build with a different input property the document wouldn't be regenerated.
For example:
The first command creates the API document at
${OutputDirectory}
in ~20 seconds.The second command with the output path set to
${OutputDirectory}2
doesn't emit anything and takes ~4 seconds.It seems like the properties being passed through aren't affecting MSBuild up-to-date checks and causing the document not to be re-generated.
Output directory value isn't checked for
I made a mistake during playing with the tool and accidentally un-defined the variable for the output path. This then causes an
ArgumentException
to be thrown inside the tool (--output ""
). Should something check a value is specified first?The text was updated successfully, but these errors were encountered: