Skip to content

Define common types in schemas instead of repeating them everywhere. #27

@ferrywlto

Description

@ferrywlto

From the OpenAPI specification files, there are multiple entries of the exact same definition.

For example, for unique identifier we have this in almost every parameter, path, request and response:

"tenantId": {
    "description": "The object ID of the tenant to operate against.",
    "in": "path",
    "name": "tenantId",
    "required": true,
    "schema": {
        "examples": ["b2fd105a-2594-437e-b934-1a62a51c28b4"],
        "format": "uuid",
        "maxLength": 36,
        "minLength": 36,
        "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$",
        "type": "string"
    },

To save maintenance and modification pain we can define the UUID type in ``components.schemaand then reuse it via$ref`, similar to `SecurityClass` definition.

"components" {
  "schemas": {
      "uuid": {
           "examples": ["b2fd105a-2594-437e-b934-1a62a51c28b4"],
            "format": "uuid",
            "maxLength": 36,
            "minLength": 36,
            "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$",
            "type": "string"
         }
      }
}

then reuse it elsewhere:

"tenantId": {
  "description": "The object ID of the tenant to operate against.",
  "in": "path",
  "name": "tenantId",
  "required": true,
  "schema": {
     "$ref": "#/components/schemas/uuid"
  }
}

By using this approach for all the common types it will save us hundreds to thousands lines from both specification json files plus avoiding subtle, hard to detect human errors during modification.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or requestquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions