Open patricksadowski opened 6 years ago
@patricksadowski for Open API 3.0, we use schema driven not manage reference in docs.microsoft.com, but in docfx, we still missing following item:
Manage reference is only for dotnet API, and we will move to schema driven in v3.
Ok, thank you. I'll be patient and watch https://github.com/dotnet/docfx/projects/1 for updates.
Does DocFx support OpenAPI 3.0.1 definition by adding the swagger.json. I am getting an error while building my project.
Good day. Could you clarify, pls. Do you have any plans to support OpenAPI 3.0.1? And when you are planning to implement this
If anything, we should know if we need to re-open this issue. The methodology to "downgrade" to the swagger 2.0 definition is not a good solution. Is anyone working on this? maybe on v3?
OpenAPI v3 is nearly ready on docs.microsoft.com, but there is still no page served.
@adanb007 You are right. v3 uses docs.microsoft.com template, and we need to wait for v3 to ship this feature.
/cc @yishengjin1413
@superyyrrzz Thanks!
thank you
Any changes on this topic lately? maybe release date is known or some preview version is available? Thank you!
Is Open Api 3.0 support added on any of docfx v3 preview versions?
Any updates would be great.
Good afternoon! Please tell me if there is any progress on working with Open Api 3.0 in docfx. This is a very important issue for our company using your product. Thanks!
Is there any news regarding this?
I had same problem. Whith this tool I solved it DocFxOpenApi
I thought it's needs Microsoft.OpenAPI
library integration to support OpenAPI 2.0/3.0.
And map OpenAPI models to existing FileModel
at RestApiDocumentProcessor.
This has become a critical issue for us because NSwag v14 has dropped support for generating Swagger 2.0 files; their command line tools have dropped the aspnetcore2swagger option.
Any ETA on when can we expect docfx to support OpenApi 3.0 files?
2024/1/26 - I was incorrect in asserting that NSwag v14 dropped support for Swagger 2.0. Sorry.
@dougclutter we are all excited for your contribution
I've started looking into adding support for OpenApi 3 but I have some questions for the Dev Team:
SwaggerModelConverter
creates a RestApiRootItemViewModel
. Initially, I thought RestApiRootItemViewModel
would be a good target for OpenApi 3 docs, so the rest of the code could remain unchanged. However, it looks like RestApiRootItemViewModel
may be too closely tied to Swagger 2.0. Any thoughts?I forked the repo and created a branch named addSupportForOpenApi3. This is a very rough cut, but I was hoping for feedback before spending any additional time on this approach. Thanks!
Hi @dougclutter,
Thank you so much for contributing the OpenApi 3 support!
OpenAPI.NET is definitely the library we would use for OpenApi 3 support and I agree that redefining the models was not a great technical choice, same could be said about the .NET MREF approach.
I would suggest start fresh by leveraging the new API Page that was designed as a base to support multiple languages. You can refer to how .NET generates API Pages as a reference, but basically, create a standalone component that reads OpenApi 3 specs using OpenAPI.NET and translate the models to TOC files and API Page YAML files. We could use a separate docfx openapi
command and config sections for generating REST API YAML files, similar to what docfx metadata
is for generating .NET YAML files. In case you need anything that the current API Page schema cannot represent for OpenAPI 3, let me know and we can figure out how to enrich the API page schema.
Hi @yufeih,
OpenAPI.NET is definitely the library we would use for OpenApi 3 support and I agree that redefining the models was not a great technical choice, same could be said about the .NET MREF approach.
Please understand that I meant no critisism of your code. docfx has been tremendously useful to our Team and we can't thank you enough for all you've done to get it to where it is.
I read over the links you provided, and it looks like you're recommending a radically different approach for OpenApi 3 support. Currently, Swagger 2.0 documentation is generated as a single page. If I'm understanding you, you're recommending that OpenApi 3 generation works more like the code API generation: a toc.yml file with separate topic files. While I agree this would be a better approach, I'm worried about what this will do for folks that are currently generating REST API docs. So, I have a few new questions:
Also, you didn't answer all the questions I posted earlier, so I'm kinda blocked until I get your feedback.
Thanks!
There is another way to support OpenAPI integration. By using Redoc to generate api document page.
How to use ReDoc (CDN version)
---
_layout: landing
---
<redoc spec-url="https://petstore3.swagger.io/api/v3/openapi.json"></redoc>
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
Output sample
https://filzrev.github.io/docfx.samples.redoc/restapi/OpenAPI/index.html
Limitations
If docfx openapi
command are expected to be added.
It might be better to supports Redoc-based Static HTML
generation by using Redocly CLI
.
@filzrev - thanks for the suggestion. The link you provided is really nice looking, but the limitations you mentioned really kill it for most corporate/gov't use:
@davesmits / @yufeih - any thoughts on Redocly?
@dougclutter
Should we leave the current code intact, so there is no change in how Swagger 2.0 files are generated?
Yes.
If we do leave the current code intact, it might be really confusing because the 2.0 vs 3.0 generation will work so differently.
We may want to use a different config option for the new OpenAPI pipeline. The old pipeline is configured as:
{
"build": {
"content": [{
"files": [ "**/*.swagger.json" ] // <-- Include swagger JSON files
}]
}
}
In the new OpenAPI pipeline, we may want to include a top openapi
config section (same shape as metadata
config) and potentially a standalone docfx openapi
command to trigger OpenAPI doc generation:
{
"openapi": {
"src": [{
"files": ["**/*.swagger.json"]
}],
"dest": "api"
}
}
As I've worked on the 3.0 code so far, I've left all the 2.0 as is. Once I got it all working, I planned to go back and delete the 2.0 code so that 2.0 and 3.0 specs were both handled by the new code. Of course, this assumed we were generating a single file. If we generate separate files for OpenApi 3.0, how should they be broken into separate pages? Should each API method get its own page (my preference) or should we break on controller/tags (e.g. create a separate file for each H1 section of the current Swagger 2.0 page)? If we generate separate files, what do we do for the models? One page for all models or separate pages for each model (my preference)?
Today 2.0 spec supports generating a single page, as well as multiple pages grouped by tag or operation using plugins.
For the new pipeline, we can start with generating operation level pages similar to MS Learn. MS Learn duplicates the models and embeds them in the corresponding operation level page, there is no dedicated models page, we can follow the same pattern.
It appears the current code is very forgiving of JSON that doesn't follow the Swagger 2.0 specifications. Was this an intentional decision? Can we be a little stricter with OpenApi 3?
Yes we could be strict with OpenAPI 3, if that is needed by OpenAPI.NET
, I suppose we aren't doing additional checks that are not related to loading the models and generating docs.
The current code is heavily dependent on Newtonsoft. Should we transition to STJ? Currently, SwaggerModelConverter creates a RestApiRootItemViewModel. Initially, I thought RestApiRootItemViewModel would be a good target for OpenApi 3 docs, so the rest of the code could remain unchanged. However, it looks like RestApiRootItemViewModel may be too closely tied to Swagger 2.0. Any thoughts?
With the API Page approach, we should be able to move to STJ and decouple from RestApiRootItemViewModel
.
any thoughts on Redocly?
Looks like a great alternative. Docfx probably won't provide built-in support for Redocly that integrates with various aspects of docfx (theme/search/PDF, etc.) due to the maintenance cost of keeping up with a big dependency.
Support for OpenAPI 3.0 is a "must have" feature for documentation in 2024...
DocFX Version Used: 2.35.4
Template used:
default
Steps to Reproduce:
restapi/
### YamlMime:ManagedReference
in the first line ofrestapi/petstore.yaml
Expected Behavior:
Actual Behavior: