Is your feature request related to a problem? Please describe.
OpenAPI specification declares a so called extensions that could be used to add extra values to the generated documentation
https://swagger.io/specification/#specification-extensions
It gives the flexibility to the different tools to read these values and enhance their documentation as they wish, with this flexibility the library could support a new extension key that can store a location to a file (within the artifact or outside of the artifact) and at runtime this resource could be resolved and added as an example to the operation.
Describe the solution you'd like
Create an OperationCustomizer that can read through the Operations and it reads the different extensions that starts with: x-extender-example-* where the * should represent the name/key of the example. The extension should have a uri field that references the external resource file to be read and it can have an optional description field.
Example with OpenAPI annotations.
@ApiResponses({
@ApiResponse(responseCode = "422", extensions = {
@Extension(name = "x-extender-example-complex", properties = {@ExtensionProperty(name = "uri", value = "test.json"), @ExtensionProperty(name = "description", value = "This is the description/summary")}),
@Extension(name = "x-extender-example-simple", properties = {@ExtensionProperty(name = "uri", value = "test.json")})
})
})
@Operation(requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(extensions = {
@Extension(name = "x-extender-example-complex", properties = {@ExtensionProperty(name = "uri", value = "test.json"), @ExtensionProperty(name = "description", value = "This is the description/summary")}),
@Extension(name = "x-extender-example-simple", properties = {@ExtensionProperty(name = "uri", value = "test.json")})
}))
Generated JSON (in case of SpringDoc dependency)
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"paths": {
"/profile": {
"get": {
"tags": [
"controller"
],
"operationId": "getProfile",
"requestBody": {
"x-extender-example-simple": {
"uri": "test.json"
},
"x-extender-example-complex": {
"description": "This is the description/summary",
"uri": "test.json"
}
},
"responses": {
"422": {
"description": "Unprocessable Entity",
"content": {
"application/json": {
"schema": {
"type": "string"
}
},
"application/xml": {
"schema": {
"type": "string"
}
}
},
"x-extender-example-simple": {
"uri": "test.json"
},
"x-extender-example-complex": {
"description": "This is the description/summary",
"uri": "test.json"
}
}
}
}
}
}
}
Is your feature request related to a problem? Please describe.
OpenAPI specification declares a so called extensions that could be used to add extra values to the generated documentation
https://swagger.io/specification/#specification-extensions
It gives the flexibility to the different tools to read these values and enhance their documentation as they wish, with this flexibility the library could support a new extension key that can store a location to a file (within the artifact or outside of the artifact) and at runtime this resource could be resolved and added as an example to the operation.
Describe the solution you'd like
Create an
OperationCustomizerthat can read through the Operations and it reads the different extensions that starts with:x-extender-example-*where the * should represent the name/key of the example. The extension should have aurifield that references the external resource file to be read and it can have an optionaldescriptionfield.Example with OpenAPI annotations.
Generated JSON (in case of SpringDoc dependency)
{ "openapi": "3.0.1", "info": { "title": "OpenAPI definition", "version": "v0" }, "paths": { "/profile": { "get": { "tags": [ "controller" ], "operationId": "getProfile", "requestBody": { "x-extender-example-simple": { "uri": "test.json" }, "x-extender-example-complex": { "description": "This is the description/summary", "uri": "test.json" } }, "responses": { "422": { "description": "Unprocessable Entity", "content": { "application/json": { "schema": { "type": "string" } }, "application/xml": { "schema": { "type": "string" } } }, "x-extender-example-simple": { "uri": "test.json" }, "x-extender-example-complex": { "description": "This is the description/summary", "uri": "test.json" } } } } } } }