Speakeasy Logo
Skip to Content
OpenAPI HubComponents

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:

Field
Type
Map[string, Schema Object]*
Description
A map of Schema Objects that can be referenced by other parts of the API. Note: OpenAPI 3.0.x does support OpenAPI Reference Objects as the value here, but
uses the JSON Schema Referencing format.
Description
A map of Security Scheme Objects that can be referenced by other parts of the API.
Description
A map of Path Item Objects that can be referenced by other parts of the API.
Description
A map of Parameter Objects that can be referenced by other parts of the API.
Description
A map of Request Body Objects that can be referenced by other parts of the API.
Description
A map of Response Objects that can be referenced by other parts of the API.
Description
A map of Header Objects that can be referenced by other parts of the API.
Description
A map of Example Objects that can be referenced by other parts of the API.
Description
A map of Callback Objects that can be referenced by other parts of the API.
Description
A map of Link Objects that can be referenced by other parts of the API.

Last updated on