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

Linter problem with `oneOf` and integer #288

Closed
juanignaciosl opened this issue Jul 5, 2019 · 10 comments

Comments

@juanignaciosl
Copy link

commented Jul 5, 2019

I'm submitting a...

  • bug report
  • feature request

What is the current behavior?

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: Swagger Petstore
  license:
    name: MIT
  contact:
    name: Test
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      description: Get a pet
      tags:
        - pets
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  oneOf:
                    - type: string
                    - type: number
                    - type: integer
                example:
                  a_property: 1234567890
$ spectral lint ~/Development/spectral-error.yml
Adding OpenAPI 3.x functions
OpenAPI 3.x detected

/home/juanignaciosl/Development/spectral-error.yml
 25:22  warning  valid-example  "a_property" property should be string
 25:22  warning  valid-example  "a_property" property should match exactly one schema in oneOf

✖ 2 problems (0 errors, 2 warnings, 0 infos)

What is the expected behavior?

$ spectral lint ~/Development/spectral-error.yml
Adding OpenAPI 3.x functions
OpenAPI 3.x detected
No errors or warnings found!

In fact, if you remove the - type: integer section, you get it right.

What is the motivation / use case for changing the behavior?

It's a bug.

Please tell us about your environment:

$ spectral --version
@stoplight/spectral/3.1.0 linux-x64 node-v8.14.1
@philsturgeon

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

Hey @juanignaciosl thanks for the bug report! This is actually fixed already in the develop branch which will be released in the next few days as v4.0. It's part of #265.

We will hopefully have a beta tagged for you today that you can play with.

@juanignaciosl

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

👍 Thanks! That was fast! :D

@XVincentX

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

@juanignaciosl We've released a new beta of the version 4.0 — try it out npm i @stoplight/spectral@beta

@juanignaciosl

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

FYI I had to manually install globby:

api (openapi_testing *$=) $ spectral lint ~/Development/spectral-error.yml 
(node:19636) [MODULE_NOT_FOUND] Error Plugin: @stoplight/spectral: Cannot find module 'globby'
module: @oclif/config@1.13.0
task: not loading commands, globby not found
plugin: @stoplight/spectral
root: /home/juanignaciosl/.nvm/versions/node/v8.14.1/lib/node_modules/@stoplight/spectral
See more details with DEBUG=*
 ›   Error: command lint not found

Anyway, after that, the run shows the same error:

api (openapi_testing *$=) $ spectral --version
@stoplight/spectral/4.0.0-beta1 linux-x64 node-v8.14.1
api (openapi_testing *$=) $ spectral lint ~/Development/spectral-error.yml 
Adding OpenAPI 3.x functions
OpenAPI 3.x detected

/home/juanignaciosl/Development/spectral-error.yml
 25:22  warning  valid-example  "a_property" property should be string
 25:22  warning  valid-example  "a_property" property should match exactly one schema in oneOf

✖ 2 problems (0 errors, 2 warnings, 0 infos)
@XVincentX

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

@juanignaciosl I'd say I've totally messed up the release :)

Let me look into again.

@XVincentX

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

@juanignaciosl Can you try again?

@juanignaciosl

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

Another problem (I don't know much about npm, maybe I'm missing something):

~ $ npm install -g @stoplight/spectral@beta
npm ERR! path /home/juanignaciosl/.nvm/versions/node/v8.14.1/lib/node_modules/@stoplight/spectral/bin/run
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/juanignaciosl/.nvm/versions/node/v8.14.1/lib/node_modules/@stoplight/spectral/bin/run'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/juanignaciosl/.npm/_logs/2019-07-05T15_41_35_504Z-debug.log

spectral.log.tar.gz

@XVincentX

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

@juanignaciosl

Yeah, apparently we forgot to upload a directory during the process, we're looking into this. You can use the binary in meantime.

P.S: I know Iago Carta from Carto — he's based in Barcelona (I'm based in Madrid), we should meet :)

@P0lip

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

@juanignaciosl
Hey!
I'm afraid oneOf cannot be used in a way you describe.
oneOf combiner is meant to match exactly one 'item', and since the value of a_property you provide is both a valid number and integer, it fails.
Suggest using anyOf since you seem to be willing to match any of matching 'items'.

EDIT:
It's quite nicely illustrated here.

Please let us know if you have any further concerns. :)

@juanignaciosl

This comment has been minimized.

Copy link
Author

commented Jul 8, 2019

Oh, I see! Thank you very much for the explanation, you're totally right, I didn't know that.

About the linter, I'd say that the first message (a_property" property type should be string) is not accurate and misleading, because it should be "just one of string, number or integer", maybe that could be improved.

Anyway, I'll close this, thank you very much! :-)

@XVincentX yep, I know Iago from CARTO, but he's no longer here. I'm based in Valladolid, remote FTW! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.