Components in OpenAPI
Components in OpenAPI are reusable bits of OpenAPI description, which can then be referenced. Reusing components allows for smaller file-sizes, reduces conflicts, and improves consistency across the API.
Components can even be shared between multiple documents, allowing for improved reuse between multiple APIs.
Components can be referenced in other parts of the OpenAPI document using the $ref
keyword. The $ref
keyword is a JSON Pointer to the component, which is a string that starts with #/components/
and then the component type and name. For example, to reference the User
schema defined in the
Components Object, you would use the following $ref
:
To put it all together, here is an example of how to reference all the various components in that previous example:
Components Object
The Components Object is a map of reusable components broken down by type.
The component name can be any valid string, but it is recommended to use a
consistent naming convention across the API. A common naming convention is PascalCase
or camelCase
.
Here are the supported component types as of OpenAPI v3.1:
Last updated on