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

Online editor reports several nonsensical errors #1519

Closed
ztrange opened this issue Oct 5, 2017 · 6 comments · Fixed by #1985
Closed

Online editor reports several nonsensical errors #1519

ztrange opened this issue Oct 5, 2017 · 6 comments · Fixed by #1985

Comments

@ztrange
Copy link

ztrange commented Oct 5, 2017

Bug

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-Editor version? 3.1.9
How did you install Swagger-Editor? npm i -S swagger-editor-dist
Which broswer & version? chrome 62
Which operating system? ubuntu 17.04

Demonstration API definition

openapi: 3.0.0
info:
  title: Example API
  description: Service API.
  version: 1.0.0
servers:
  - url: 'http://api.example.com'
paths:
  /login/local:
    post:
      tags:
        - login
      summary: Login using email or nickname
      description: Returns customer info and jwt access and refresh tokens
      security:
        - apiKey: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                emailOrNickname:
                  type: string
                  required: true
                password:
                  type: string
                  required: true
      responses:
        '200':
          description: Login successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  customer:
                    $ref: "#/components/schemas/Admin"
                  refreshToken:
                    type: string
        "401":
          description: "Unauthorized"
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-application-key
  schemas:
    Admin:
      type: object
      properties:
        _id:
          type: string
        name:
          type: object
          properties:
            first:
              type: string
            last:
              type: string
        email:
          type: object
          properties:
            address:
              type: string
            verified:
              type: boolean
            token:
              type: string
        password:
          type: string
        recoveryToken:
          type: string
        lastLogin:
          type: string
          format: date-time

Configuration (browser query string, constructor, config.yaml)

I'm using the default config

const editor = SwaggerEditorBundle({
      dom_id: '#swagger-editor',
      layout: 'StandaloneLayout',
      presets: [
        SwaggerEditorStandalonePreset
      ]
    })

Expected Behavior

I think my path definition is correct. I've read and re-read the 3.0 spec several times, I based my code on the examples on spec but I still get several weird errors: Mainly I don't want to use a component $ref on the requestBody. I've seen example code on the spec documentation and it looks like I should have that option

Current Behavior

Errors
Hide
Schema error at paths['/login/local'].post.requestBody
should have required property '$ref'
missingProperty: $ref
Jump to line 17
Schema error at paths['/login/local'].post.requestBody
should match exactly one schema in oneOf
Jump to line 17
Schema error at paths['/login/local'].post.requestBody.content['application/json']
should have required property 'examples'
missingProperty: examples
Jump to line 19
Schema error at paths['/login/local'].post.requestBody.content['application/json']
should match exactly one schema in oneOf
Jump to line 19
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema
should have required property '$ref'
missingProperty: $ref
Jump to line 20
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema
should match exactly one schema in oneOf
Jump to line 20
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema.properties['emailOrNickname']
should have required property '$ref'
missingProperty: $ref
Jump to line 23
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema.properties['emailOrNickname']
should match exactly one schema in oneOf
Jump to line 23
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema.properties['emailOrNickname'].required
should be array
Jump to line 25
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema.properties['password']
should have required property '$ref'
missingProperty: $ref
Jump to line 26
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema.properties['password']
should match exactly one schema in oneOf
Jump to line 26
Schema error at paths['/login/local'].post.requestBody.content['application/json'].schema.properties['password'].required
should be array
Jump to line 28

Context

I'm trying to migrate some bad documentation to something better using swagger 3

@ztrange
Copy link
Author

ztrange commented Oct 5, 2017

Nevermind. I found out what breaks it. It is that I was using a required: boolean parameter inside a SchemaObject. I got confused with old swagger syntax. the correct syntax is:

openapi: 3.0.0
info:
  title: Example API
  description: Service API.
  version: 1.0.0
servers:
  - url: 'http://api.example.com'
paths:
  /login/local:
    post:
      tags:
        - login
      summary: Login using email or nickname
      description: Returns customer info and jwt access and refresh tokens
      security:
        - apiKey: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - emailOrNickname
                - password
              properties:
                emailOrNickname:
                  type: string
                password:
                  type: string
      responses:
        '200':
          description: Login successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  customer:
                    $ref: "#/components/schemas/Admin"
                  refreshToken:
                    type: string
        "401":
          description: "Unauthorized"
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-application-key
  schemas:
    Admin:
      type: object
      properties:
        _id:
          type: string
        name:
          type: object
          properties:
            first:
              type: string
            last:
              type: string
        email:
          type: object
          properties:
            address:
              type: string
            verified:
              type: boolean
            token:
              type: string
        password:
          type: string
        recoveryToken:
          type: string
        lastLogin:
          type: string
          format: date-time

@webron
Copy link
Contributor

webron commented Oct 5, 2017

Thanks for reporting the issue and the fix. I'm going to reopen the ticket since we need to rework that validation message. It's not useful to users and we should do a better job at it.

@webron webron reopened this Oct 5, 2017
@shockey shockey added this to the Friday, November 10 milestone Nov 3, 2017
@shockey shockey removed this from the Friday, November 10 milestone Nov 17, 2017
@AlbinoDrought
Copy link

Similar nonsensical error when using bool (a non-existent type) instead of boolean. Here's an example:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: A thing
  license:
    name: AGPL-3.0

paths:
  /excellence:
    get:
      responses:
        '200':
          description: "An excellent response"
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ExcellentThing"
components:
  schemas:
    ExcellentThing:
      description: "Something excellent"
      properties:
        extremelyExcellent:
          description: "If false, this item is only somewhat excellent"
          type: bool
          example: true

Errors:

image

Above schema with actual problem fixed: (bool -> boolean)

openapi: "3.0.0"
info:
  version: 1.0.0
  title: A thing
  license:
    name: AGPL-3.0

paths:
  /excellence:
    get:
      responses:
        '200':
          description: "An excellent response"
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ExcellentThing"
components:
  schemas:
    ExcellentThing:
      description: "Something excellent"
      properties:
        extremelyExcellent:
          description: "If false, this item is only somewhat excellent"
          type: boolean
          example: true

shockey added a commit to shockey/swagger-editor that referenced this issue Apr 11, 2019
shockey added a commit to shockey/swagger-editor that referenced this issue Apr 11, 2019
shockey added a commit to shockey/swagger-editor that referenced this issue Apr 11, 2019
shockey added a commit to shockey/swagger-editor that referenced this issue Apr 11, 2019
@shockey
Copy link
Contributor

shockey commented Apr 12, 2019

I've opened a pull request (#1985) that will close this issue.

Here's what Swagger Editor reports with my changes:

Structural error at [...]schema.properties.emailOrNickname.required
 should be an array of property names required within an object schema

Structural error at [...]schema.properties.password.required
 should be an array of property names required within an object schema

PS: @AlbinoDrought, the messaging for your example has been improved as well:

Structural error at [...]ExcellentThing.properties.extremelyExcellent.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string

shockey added a commit to shockey/swagger-editor that referenced this issue Apr 17, 2019
shockey added a commit to shockey/swagger-editor that referenced this issue Apr 17, 2019
shockey added a commit that referenced this issue Apr 18, 2019
* adopt @webron's OpenAPI 3.0 schema from OAI/OpenAPI-Specification#1270

permalink: https://github.com/OAI/OpenAPI-Specification/blob/92e15eba1d4591ebfe8c11898c48241e72854381/schemas/v3.0/schema.yaml

* add ajv-errors

* address error messages for #1808's Swagger 2.0 example

clarifies the schema and adds custom error messages for unclear error conditions

* address error messages for #1808's OpenAPI 3.0 example

* restrict underlying JSON Schema `type` field to simple types only (for #1832)

* fix limitation in JSON Pointer conversion helper

* add clear `not` error message (for #1489)

* add additionalProperties message (for #1394)

* add ajv-keywords

* use `switch` to intelligently identify inline vs referenced content (for #1853)

* use `switch` to XOR `schema` and `content` (for #1853)

* use `switch` to pivot security scheme based on type

(for #1672)

* use switch to fall-through to inline security scheme validation (for #1672)

* rewrite more Reference oneOfs (for #1519)

* add custom message for `Schema.required` type error (for #1519)

* rewrite Response/Reference oneOf (for #1489)

* use switch in ParameterLocation validation (for #1797)

* define pivot key switches for SecurityDefinitions (for #1711)

* give helpful `format: uri` messages for SecurityDefinitions (for #1711)

* eliminate NonBodyParameter; pivot on `Parameter.in` with a switch (for #1511)

* oneOf -> switch for Parameters.items reference

* (for #1711)

* remove redundant semantic validator (for #1511)

* adjust wording of custom error message (for #1853)

* add regression tests for all related issues

* revert to expect@^1.20.2

* linter fixes

* fix messaging flaw for #1832

* improve messaging for #1394

* use literal key for `$ref` in Reference Object

* remove commented legacy data from OAS3 schema

* remove superfluous quotation marks

* normalize test case paths to `/`

* normalize openapi fields to 3.0.0

* drop unused `paths` information

* ensure clear errors for 3.0 Parameter style/content exclusivity

* add `required` assertions to switch statements that pivot on a key's value

this prevents false positives when the pivot key is missing entirely

* remove stray space
shockey added a commit to shockey/swagger-editor that referenced this issue May 23, 2019
…i#1985)

* adopt @webron's OpenAPI 3.0 schema from OAI/OpenAPI-Specification#1270

permalink: https://github.com/OAI/OpenAPI-Specification/blob/92e15eba1d4591ebfe8c11898c48241e72854381/schemas/v3.0/schema.yaml

* add ajv-errors

* address error messages for swagger-api#1808's Swagger 2.0 example

clarifies the schema and adds custom error messages for unclear error conditions

* address error messages for swagger-api#1808's OpenAPI 3.0 example

* restrict underlying JSON Schema `type` field to simple types only (for swagger-api#1832)

* fix limitation in JSON Pointer conversion helper

* add clear `not` error message (for swagger-api#1489)

* add additionalProperties message (for swagger-api#1394)

* add ajv-keywords

* use `switch` to intelligently identify inline vs referenced content (for swagger-api#1853)

* use `switch` to XOR `schema` and `content` (for swagger-api#1853)

* use `switch` to pivot security scheme based on type

(for swagger-api#1672)

* use switch to fall-through to inline security scheme validation (for swagger-api#1672)

* rewrite more Reference oneOfs (for swagger-api#1519)

* add custom message for `Schema.required` type error (for swagger-api#1519)

* rewrite Response/Reference oneOf (for swagger-api#1489)

* use switch in ParameterLocation validation (for swagger-api#1797)

* define pivot key switches for SecurityDefinitions (for swagger-api#1711)

* give helpful `format: uri` messages for SecurityDefinitions (for swagger-api#1711)

* eliminate NonBodyParameter; pivot on `Parameter.in` with a switch (for swagger-api#1511)

* oneOf -> switch for Parameters.items reference

* (for swagger-api#1711)

* remove redundant semantic validator (for swagger-api#1511)

* adjust wording of custom error message (for swagger-api#1853)

* add regression tests for all related issues

* revert to expect@^1.20.2

* linter fixes

* fix messaging flaw for swagger-api#1832

* improve messaging for swagger-api#1394

* use literal key for `$ref` in Reference Object

* remove commented legacy data from OAS3 schema

* remove superfluous quotation marks

* normalize test case paths to `/`

* normalize openapi fields to 3.0.0

* drop unused `paths` information

* ensure clear errors for 3.0 Parameter style/content exclusivity

* add `required` assertions to switch statements that pivot on a key's value

this prevents false positives when the pivot key is missing entirely

* remove stray space
@maheshJosephSadashiv
Copy link

I too am facing a similar error. When I run the swagger generate spec -o ./doc/resources/swagger.json command it generates a spec that has two structural errors.
Screenshot 2020-01-25 at 7 14 00 PM
PLEASE help me out I can't understand what's going wrong.

@shockey
Copy link
Contributor

shockey commented Jan 25, 2020

@maheshJosephSadashiv this issue has been closed for over 9 months, please open a new one if you need help!

@swagger-api swagger-api locked as resolved and limited conversation to collaborators Jan 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants