FAQ

  • GitHub GitHub Repo stars
  • Discord Discord Server
  • ✨ New! Try the OpenAPI Doctor ✨ The OpenAPI Doctor
    Recommended

    oas-missing-type


    Formats: Severity:

    All schemas and their properties should have a type field defined to ensure clarity about expected data types.

    Why did this violation appear?

    A schema or property is missing an explicit type definition. While OpenAPI/JSON Schema allows schemas without types, explicitly defining types improves API documentation clarity and helps prevent validation issues.

    Bad example

    Schema property without a type defined:

    components:
      schemas:
        Pet:
          type: object
          properties:
            id:
              type: string
            name:
              description: "Name of the pet"
              # Missing type field - this will trigger a violation
            age:
              minimum: 0
              # Has constraints but no type - will trigger a violation
    

    Good Example

    All properties have explicit types:

    components:
      schemas:
        Pet:
          type: object
          properties:
            id:
              type: string
            name:
              type: string
              description: "Name of the pet"
            age:
              type: integer
              minimum: 0
    

    Exceptions

    The following schemas don’t require explicit types:

    1. Enum values - type can be inferred:
    status:
      enum: ["active", "inactive"]  # Type inferred from values
    
    1. Const values - type is implicit:
    version:
      const: "1.0.0"  # Type is implicitly string
    
    1. Polymorphic schemas - composed schemas don’t need their own type:
    Pet:
      oneOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'
    
    1. Schemas with structural properties - type can be inferred:
    Address:
      properties:  # Implies type: object
        street:
          type: string
    

    How do I fix this violation?

    Add a type field to all schemas and properties. Valid types are:

    • string
    • number
    • integer
    • boolean
    • array
    • object
    • null (OpenAPI 3.1 only)

    For arrays, also define the items schema. For objects, define properties or use additionalProperties.