In OpenAPI Spec 3.0, there is a components section where you can define headers,links, schemas etc and then reuse them for various operations.
components:
# Reusable schemas (data models)
schemas:
...
# Reusable path, query, header and cookie parameters
parameters:
...
# Security scheme definitions (see Authentication)
securitySchemes:
...
# Reusable request bodies
requestBodies:
...
# Reusable responses, such as 401 Unauthorized or 400 Bad Request
responses:
...
# Reusable response headers
headers:
//...
I have a number of headers that are common across various operations so it makes sense, from an open API perspective they are defined in the components
section s so they can be re-used.
In Swagger, when you use @Schema
it will be end up in components / schema
section, but I am struggling to see how you can get a parameter or header into the components section so they can be reused.
(Note: I am using jax-rs / Jersey)
I wrote a YAML that has a header and parameter defined in components / schema an then generated the Java JAX-RS / Jersey from that but it defined the header and parameter for very API Operation. There was no re-use. It was also missing the description for header I had defined in components / header in the YAML.
Looking at the JDoc: http://docs.swagger.io/swagger-core/v2.0.8/apidocs/index.html?io/swagger/v3/oas/annotations/OpenAPIDefinition.html
It says (for header, that I use the ref attribute to refer to something in the components section, but the question is how do I get it into the components section)
Any help appreciated.
components
using Java annotations"? (e.g. in Springfox) – Helen