Skip to content

Question: use of a JSON schema in the models #1480

@CameronGo

Description

@CameronGo

Hi, I'm working on porting over my RAML to OpenAPI spec. I am doing the documentation of the API in a yaml file, but I prefer to document the schemas and the examples in JSON (since the is how all of my responses are returned. This seems to let me do this, but when I have both the schema and the example in JSON, I get rendering errors. I've tried manipulating the spacing in various combinations and cannot get it working.

Is this not allowed? Do I need to change my approach somehow, or is there something simple I can change to get it to work this way?

Here is an excerpt form my #/components/schemas/Address that works:

    Address: 
      title: Address
      required:
      - street1
      - city
      - state
      - zipcode
      - label
      type: object
      properties:
        street1:
          type: string
        city:
          type: string
        state:
          type: string
        zipcode:
          type: string
        label:
          $ref: '#/components/schemas/Label'
        street2:
          type: string
          nullable: true
      example: 
        {
          "street1": "126 Main Street",
          "street2": "Apt 1A",
          "city": "Atlanta",
          "state": "GA",
          "zipcode": "30342",
          "label": "home"
        }

But then when I try to use my JSON schema I get these errors:
Schema error at components.schemas['example']
should NOT have additional properties
additionalProperty: street1, street2, city, state, zipcode, label
Jump to line 4800
Parser error bad indentation of a mapping entry
Jump to line 4801

Here is the same excerpt with the RAML for the schema definition replaced by a true JSON schema:

    Address: 
        {
          "type": "object",
          "properties": {
            "street1": {
              "type": "string"
            },
            "street2": {
              "type": "string"
            },
            "city": {
              "type": "string"
            },
            "state": {
              "type": "string"
            },
            "zipcode": {
              "type": "string"
            },
            "label": {
              "type": "string",
              "enum": [
                "home",
                "work"
              ]
            }
          },
          "required": [
            "street1",
            "city",
            "state",
            "zipcode",
            "label"
          ]
        }
      example: {
          "street1": "126 Main Street",
          "street2": "Apt 1A",
          "city": "Atlanta",
          "state": "GA",
          "zipcode": "30342",
          "label": "home"
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions