Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CameronGo opened this issue Feb 6, 2018 · 3 comments
Closed

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

CameronGo opened this issue Feb 6, 2018 · 3 comments

Comments

@CameronGo
Copy link

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"
        }
@hkosova
Copy link
Contributor

hkosova commented Mar 9, 2018

The example keyword is part of the schema definition, so it should be inside your schema JSON:

    Address: 
        {
          "type": "object",
          "properties": {
            ...
          },
          "required": [...],

          "example": {   // <-----------
            "street1": "126 Main Street",
            "street2": "Apt 1A",
            "city": "Atlanta",
            "state": "GA",
            "zipcode": "30342",
            "label": "home"
          }
        }

@ioggstream
Copy link
Contributor

@CameronGo Does that work for you?

@CameronGo
Copy link
Author

Sorry for the long delay. Finally got back to my OAS3 conversion and yes, as noted above that is what I was missing. I didn't; however, need to add the comment tag, I just needed to move my example inside the json object for my schema. Thanks so much for showing me what I was doing wrong!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants