A domain is a library of common components – such as parameters, responses and data models – that are used across multiple API definitions. Domains can be written by using the OpenAPI 2.0 or OpenAPI 3.0 syntax. API definitions can use domains with the matching OpenAPI version.
Note for SwaggerHub On-Premise users: OpenAPI 3.0 domains are supported since v. 1.19.3.
Domains can contain the following components:
Definitions (in OpenAPI 2.0) or Schemas (in OpenAPI 3.0) – Data models that describe your API inputs and outputs.
Path items – API paths (such as GET, POST, PUT operations) that can be reused across APIs.
Parameters – Parameters for an API call: path parameters, query string parameters, custom headers, and so on.
Responses – Responses returned by API calls: HTTP status codes and the response data models.
Additional component types in OpenAPI 3.0 domains:
Request bodies – Common request bodies for POST, PUT, and PATCH operations.
Headers – Common response headers (such as rate limit headers) and multipart body part headers.
Note: Common request headers are defined as parameters, not as header components.
Examples – Reusable Example objects for use in parameters, request bodies, and response bodies. These examples can be referenced from the
exampleskeyword (not to be confused with
Links – Definitions of the relationship and traversal mechanism between operations. Learn more.
Callbacks –Callback definitions.
Note: The OpenAPI 3.0
components section can contain
securitySchemes, however, domains cannot contain them. Domains are for components that are referenced via the
$ref keyword, such as
$ref: '#/components/schemas/MySchema'. Security schemes, however, are referenced directly by their name:
security: - bearerAuth:  # "bearerAuth" is the name of the security scheme
so they must be defined in the API where they will be used.
Create and manage domains
The domain structure is similar to API definitions. Domains can be defined by using the OpenAPI 2.0 or OpenAPI 3.0 syntax.
When you create a domain, you specify the OpenAPI Specification version of this domain,
swagger: '2.0' or
openapi: 3.0.0. Use the same OpenAPI version as in your APIs – SwaggerHub supports cross-referencing only within the same OpenAPI version.
The OpenAPI version defines the domain syntax and the available component types.
Existing domains without the OpenAPI version identifier are assumed to be
In OpenAPI 2.0 domains, place your components in the
pathitems sections at the root level of the domain. The
pathitems syntax is similar to the API
paths section, but it uses arbitrary identifiers instead of the actual path names.
definitions: ... parameters: ... responses: ... pathitems: EntityOperations: # An arbitrary name, does not have to be a /path/to/something get: ... post: ...
OpenAPI 3.0 domains need to have everything under the
components section. Note that OpenAPI 3.0 uses
schemas instead of
components: schemas: ... pathitems: ... parameters: ... requestBodies: ... responses: ... headers: ... examples: ... links: ... callbacks: ...
info section is optional, but it can be used to give your domain a
description and developer contact information. SwaggerHub displays this information in the interactive documentation and in MY hub.
info: title: Components version: 1.0.0 description: Common components for Acme REST APIs contact: name: Core team email: firstname.lastname@example.org
info section structure is the same as in APIs. See Info Object.
Like API definitions, domains can contain extensions – arbitrary keys with the
x- prefix. You can use them to add custom metadata to your domains and components. Extension properties can be used almost anywhere in domains, but not directly under the
responses and similar keys.
openapi: 3.0.0 components: parameters: filter: in: query name: filter x-beta: true # <------- schema: type: string description: Filter string
How to reference domains
To reference the domain components in an API, use absolute
$ref links as follows:
# OpenAPI 2.0 $ref: https://api.swaggerhub.com/domains/OWNER/DOMAIN/VERSION#/TYPE/COMPONENT_NAME # OpenAPI 3.0 $ref: https://api.swaggerhub.com/domains/OWNER/DOMAIN/VERSION#/components/TYPE/COMPONENT_NAME
or if you use SwaggerHub On-Premise:
# OpenAPI 2.0 $ref: http(s)://SWAGGERHUB/v1/domains/OWNER/DOMAIN/VERSION#/TYPE/COMPONENT_NAME # OpenAPI 3.0 $ref: http(s)://SWAGGERHUB/v1/domains/OWNER/DOMAIN/VERSION#/components/TYPE/COMPONENT_NAME
See Referring to a Domain for details.