-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Epic: Use Asp.Net Core Api Explorer for Swagger generation #999
Comments
Open questions:
|
I'd suggest not supporting it. We (ASP.NET Core team) strongly discourage anyone from using conventional routing
We currently have no built-in concept of API versioning, so we don't expose any information like that. We'd like to do something like this eventually but it keeps getting bumped down the priority list. |
Ok, then we leave it as is (reflection based). |
What about this? I am thinking about these command line implementation - why cant we use TestServer to get the ApiExplorer/Description in the same process? If I understand you correctly, you want to start the application in another process and get the spec via HTTP? The problem with this approach is:
Using TestServer would solve all that, we could create a TestServer with the dynamically loaded Startup, register ApiExplorer if necessary, get the ApiDescriptions and feed it into a generator instance of the original process (i.e. the expected version). |
@pranavkm - can you answer the above? You are much more familiar with this CLI tools than I am |
@RSuter the way TestServer works is that your unit test project references the application. Consequently, it transitively references the application's dependencies. This allows the test runner to execute the test in the context of the application's dependencies. We're essentially trying to do the same thing but without the benefit of having the user build \ compile the equivalent of a test application. Here's how it's supposed to work:
To answer your questions,
We wouldn't be launching a HTTP server, but passing in all the relevant arguments that are passed to the
I was currently prototyping a model where the application references the inside man package. This is the approach MvcPrecompilation, Scaffolding and dotnet-ef commands take. There might be a solution where the application does not have this reference (dotnet-xunit does this) but I'm not super familiar with the details of it's implementation. We can pursue this further if this scenario is important.
Having ApiExplorer registered would be a requirement for the tool. That said, in the standard scenarios where your app uses
I was attempting to do all of the work in the inside man, but one possibility would be to serialize the output of ApiExplorer to |
Thank you for your replies, I'm curious how this is implemented... I think it is important that this works:
...if this is even possible... Also this should be easy to maintain and add extend in the future (e.g. add new parameters, etc.). |
You can implement the new command directly in NSwag.Commands - this package is usually not used directly in 3rd party apps but only in NSwag apps (eg nswag.npm, nswag.msbuild, nswagstudio, etc) and thus an added dependency should not make a big difference... it would be good if this serialization, communication infrastruction is independent of the command itself so that it could be reused in other projects (eg a signalr code generator, see https://github.com/RSuter/sigspec |
We did a little brainstorming about this today and have a few ideas to try. We'll figure out if this is feasible and get back to you. If this gets too far into the territory of implementing a totally custom loading behavior for dotnet, then I don't think this is something that either of us will want to live with long term. I suppose if we get there and find out this is too hard or fragile then we will want to have a discussion with you about alternatives. |
@rynowak Ok, this is fine. I'll let you experiment and will work on other parts of the project, so that everything is ready for the v12 release and all potential breaking changes can be incorporated in this release... |
@RSuter I have a very WIP commit based on my initial design available as as PR #1034. I thought it might help since it's a little easier to visualize as code as opposed to set of bullet points. The bulk of the code that follows from the workflow is here - https://github.com/RSuter/NSwag/pull/1034/files#diff-61f8e53061cb1398e7b87f4177ccc8c2R147.
|
Some sample Swagger 2.0 and OpenAPI 3.0 specifications can be compared here: https://github.com/RSuter/NSwag/tree/master/src/NSwag.Sample.NETCore20/Output To update, just start the sample app and run |
I used ApiExplorer based generator and it didn't generate the same output for generic controllers. |
@LeCoque can you provide a sample project? |
In the This can be an important feature because you can have some controllers in the assembly that you only expose depending on some runtime options (using Would it be possible to have the |
@piaste in the new generator you need to filter operations with an operation processor (return false to exclude an operation) and insert it at the beginning of the DocumentProcessors list setting (so it's filtered at the beginning). see https://github.com/RSuter/NSwag/wiki/Document-Processors-and-Operation-Processors |
@RSuter Thanks, that works. I didn't need to add it to |
Tasks:
Later: Remove NSwag.SwaggerGeneration.WebApi dependency (moved to v13, Epic: NSwag v13 #1700)Later: Automatically migrate nswag.json configs where IsAspNetCore == true to use this new command(must be done manually/explicitely)Related:
PRs:
The text was updated successfully, but these errors were encountered: