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

Speccy outputs stacktrace when optional property is misspelled #335

Closed
addap opened this issue May 21, 2019 · 3 comments
Closed

Speccy outputs stacktrace when optional property is misspelled #335

addap opened this issue May 21, 2019 · 3 comments

Comments

@addap
Copy link

addap commented May 21, 2019

Detailed description

If I misspell a property that is not required (like description or summary in some cases) speccy prints out a rather unhelpful stacktrace

Specification schema is invalid.

#/
Error: Couldn't find property ~1pets~1{id} of /paths/~1pets~1{id}/get/parameters/0
    at pointers.reduce (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/json/get-meta-from-path.js:17:19)
    at Array.reduce (<anonymous>)
    at getMetaFromPath (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/json/get-meta-from-path.js:10:19)
    at RequiredValidationError.getLocation (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/validation-errors/base.js:33:35)
    at RequiredValidationError.getLocation (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/validation-errors/required.js:16:15)
    at RequiredValidationError.getCodeFrame (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/validation-errors/base.js:41:64)
    at RequiredValidationError.print (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/validation-errors/required.js:28:31)
    at customErrorToText (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/index.js:22:44)
    at Array.map (<anonymous>)
    at _default (/home/adrian/speccy_error/node_modules/oas-validator/node_modules/better-ajv-errors/lib/modern/index.js:34:25

instead of something like

unrecognized property "decription"

Context

Why is this change important to you? How would you use it?
How can it benefit other users?

A pointer to what property is actually misspelled would save me and I belive others a whole lot of time.

Possible implementation

Not obligatory, but suggest an idea for implementing addition or change.

You already have something to check for required and expected properties so you could check if the property has a valid name to begin with. Maybe you already do that and it just does not work for the description and summary.

Your environment

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

  • Node Version:
    node v11.14.0
  • Operating system and version (e.g. Ubuntu 16.04, Windows 7):
    4.19.36-1-MANJARO, 64bit
  • speccy version
    0.10.1

you can reproduce it with the following file, I used the petstore example as a base. Note that the description in the get parameter is misspelled:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
  termsOfService: http://swagger.io/terms/
  contact:
    name: Swagger API Team
    email: apiteam@swagger.io
    url: http://swagger.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: http://petstore.swagger.io/api
tags:
  - name: test
    description: test tag to satisfy default linter
paths:
  /pets/{id}:
    get:
      summary: If this is misspelled it also crashes
      decription: If this is misspelled it also crashes
      operationId: find pet by id
      tags:
        - test
      parameters:
        - name: id
          in: path
          decription: ID of pet to fetch
          required: true
          schema:
            type: integer
            format: int64
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

components:
  schemas:
    Pet:
      allOf:
        - $ref: '#/components/schemas/NewPet'
        - required:
          - id
          properties:
            id:
              type: integer
              format: int64
    NewPet:
      required:
        - name  
      properties:
        name:
          type: string
        tag:
          type: string    
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
@cbautista1002
Copy link

I just came across this situation as well except that in my case it wasn't a misspelling but the existence of an unsupported keyword (misspelling and unknown keywords fall under the same bucket I suppose). My schema contained additionalItems: false which is a JSONSchema keyword, not an OpenAPI keyword.

The end result is the same, just adding a different use case / cause to this issue.

@pderaaij
Copy link
Contributor

Thanks for mentioning this. Seems there is a regression in formatting errors. I've added a quick fix, but we need to properly fix this.

@djtarazona
Copy link
Contributor

This has been fixed in v0.11.0

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

4 participants