OpenAPI Specification Schemas

From NovaOrdis Knowledge Base
Revision as of 02:07, 26 January 2024 by Ovidiu (talk | contribs) (→‎type)
Jump to navigation Jump to search

External

Internal

Overview

The /components/schemas section of the OpenAPI specification defines reusable types that are used as input and output data types. These types can represent objects, but also primitives and arrays. The specification is based on JSON Schema Specification Draft 2020-12. A client or server code generator creates programming language types from these schemas. This article is annotated with details related to how oapi-codegen generates Go code.

Schema

SchemaName
  type:
  required:
  properties:
  format:
  description:
  discriminator:
  externalDocs:

Schema Name

type

One of the supported data types.

format

Example

components:
  schemas:
    Pet:
      allOf:
        - $ref: '#/components/schemas/NewPet'
        - type: object
          required:
            - id
          properties:
            id:
              type: integer
              format: int64
    NewPet:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        tag:
          type: string
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Composition

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#composition-and-inheritance-polymorphism

allOf

Polymorphism

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#composition-and-inheritance-polymorphism

discriminator