Skip to content

Support passing OpenAPI spec version and document name via dotnet-getdocument #55823

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

Merged
merged 8 commits into from
May 22, 2024

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented May 21, 2024

The getdocument API for resolving documents at build-time only supports serializing documents to the spec version serialized via OpenAPI options. We want to add support for overriding this option for integration scenarios where 3rd-party tools might support only certain versions of the OpenAPI specification.

This PR:

  • Adds a new --openapi-version flag to the getdocument CLI application to support setting the OpenAPI spec version to use when generating documents
  • Adds a new --document-name flag to the getdocument CLI application to support generating the OpenAPI file for a given document
  • Add a new GenerateAsync method to the IDocumentProvider interface to support passing the OpenAPI spec version during serialization
  • Adds tests for the GetDocument tool

Sample invocation:

$ dotnet dotnet-getdocument.dll --assembly ~/gh/aspnetcore/artifacts/bin/Sample/Debug/net9.0/Sample.dll
	--project ./Sample.csproj --file-list ~/gh/aspnetcore/artifacts/obj/Sample/Debug/net9.0/Sample.OpenApi.cache
	--output ~/test.json --openapi-version OpenApi2_0
	--tools-directory /Users/captainsafia/gh/aspnetcore/artifacts/bin/GetDocument.Insider/Debug/net9.0/
	--framework ".NETCoreApp,Version=v9.0"
	--document-name internal

@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 21, 2024
@captainsafia captainsafia added area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-openapi and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 21, 2024
@captainsafia captainsafia changed the title Support passing OpenAPI spec version via dotnet-getdocument Support passing OpenAPI spec version and document name via dotnet-getdocument May 21, 2024
@captainsafia captainsafia marked this pull request as ready for review May 22, 2024 01:02
@captainsafia captainsafia requested a review from a team as a code owner May 22, 2024 01:02
@amcasey
Copy link
Member

amcasey commented May 22, 2024

--openapi-version OpenApi2_0

I'm assuming this is an enum member, but it seems a little clunky - I feel like I'd expect to pass "2.0" or something. But maybe we don't expect the tool to have any human users?

@captainsafia
Copy link
Member Author

--openapi-version OpenApi2_0

I'm assuming this is an enum member, but it seems a little clunky - I feel like I'd expect to pass "2.0" or something. But maybe we don't expect the tool to have any human users?

Yep, this maps directly to the OpenApiSpecVersion enum supported by the OpenAPI package (ref). We could prettify the value expected here but I liked being able to pass it directly to Enum.TryParse without any further modification.

I don't anticipate that users will interact with these parameters and if they do it would be through MSBuild properties/Visual Studio config.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some concerns about validation but seems generally good.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits about resource strings, but LGTM. Thanks for the changes!

@captainsafia captainsafia enabled auto-merge (squash) May 22, 2024 21:22
@captainsafia captainsafia merged commit da02847 into main May 22, 2024
26 checks passed
@captainsafia captainsafia deleted the safia/oapi-vers-cli branch May 22, 2024 23:32
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview5 milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-openapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants