Forum Discussion

DavidThielen's avatar
DavidThielen
Occasional Contributor
5 years ago

How do I reference the same schema as a property?

I have the following in my oas.yaml file:

components:
  schemas:
    ServiceError:
      type: object
      properties:
        Message:
          type: string
          description: "The exception message."
        ExceptionMessage:
          type: string
        Type:
          type: string
          description: "The exception type.""
        InnerError:
            $ref: '#/components/schemas/ServiceError'
             description: "If there's an inner exception, the InnerException.

    Property:
      type: object
      properties:
        Name:
          type: string
          description: Name of the property.

It does not like the line "description: "If there's an inner exception, the InnerException." and if I remove that, it does not like the line "Property:". I've tried a lot of things and nothing works. What am I not understanding?

thanks - dave

  • The Type.description line has an extra quote at the end. The InnerError.description line is missing an ending quote and also has extra indent.

     

    Here's the correct version:

    components:
      schemas:
        ServiceError:
          type: object
          properties:
            Message:
              type: string
              description: "The exception message."
            ExceptionMessage:
              type: string
            Type:
              type: string
              description: "The exception type."
            InnerError:
                $ref: '#/components/schemas/ServiceError'
                description: "If there's an inner exception, the InnerException."
    
        Property:
          type: object
          properties:
            Name:
              type: string
              description: Name of the property.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    The Type.description line has an extra quote at the end. The InnerError.description line is missing an ending quote and also has extra indent.

     

    Here's the correct version:

    components:
      schemas:
        ServiceError:
          type: object
          properties:
            Message:
              type: string
              description: "The exception message."
            ExceptionMessage:
              type: string
            Type:
              type: string
              description: "The exception type."
            InnerError:
                $ref: '#/components/schemas/ServiceError'
                description: "If there's an inner exception, the InnerException."
    
        Property:
          type: object
          properties:
            Name:
              type: string
              description: Name of the property.