OpenAPI: Auto-generated documentation #1371
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds auto-generated documentation for JSON:API endpoints, resource types, and attributes to the OAS file.
Comments on relationships are currently ignored, due to a limitation in OAS 3.0. This can likely be worked around by usingResolved by #1372.allOf
operators. The same limitation applies to attributes of enum types.The comments on endpoints (expanded controller action methods) are hardcoded. Triple-slash comments on resource classes and their properties are extracted by loading the
.xml
file next to their assembly. Add<GenerateDocumentationFile>true</GenerateDocumentationFile>
to your project file to make this work. To get additional documentation, such as triple-slash comments on enum types, callSwaggerGenOptions.IncludeXmlComments()
as described here.Adding partial controllers to your project and decorating the action methods with custom triple-slash comments is possible. They will override the hardcoded descriptions, but to a certain degree. It won't work for endpoints that take a relationship name, due to relationship expansion at runtime.
Additionally, this PR adds in all the applicable HTTP status codes that JsonApiDotNetCore returns per endpoint. And it fixes the bug where response bodies are shown for HEAD requests.
Demo
Screenshots below for an API comprising of skyscrapers, spaces, and elevators.
Endpoints
Parameters and response codes
Triple-slash comments from resource type and attributes
IntelliSense on generated C# client
Closes #1053.
Fixes #1369.
Fixes #1368.
QUALITY CHECKLIST