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

bug: anyOf in schemas are not resolved #119

Closed
Shockolate opened this issue Aug 8, 2018 · 8 comments
Closed

bug: anyOf in schemas are not resolved #119

Shockolate opened this issue Aug 8, 2018 · 8 comments

Comments

@Shockolate
Copy link

Detailed description

When given a Schema Object where the type field is within an anyOf, the linter reports an error.

Consider the schema:

components:
  schemas:
    AnyOfExample:
      type: object
      properties:
        intOrFloatProperty:
          anyOf:
            - type: number
               format: float
            - type: integer
               format: int32
      required:
        - intOrFloatProperty

The linter reports:

expected Object {
  anyOf: Array [
    Object { type: 'number', format: 'float' },
    Object { type: 'integer', format: 'int32' }
  ],
  ... snip ...
} to have property type

Context

anyOf is an important aspect of JSON Schema, which OAS has adopted. It's a valid part of the specification and should be supported in linters.

Your environment

  • Node Version: 8.11.3
  • macOS 10.13.6
@philsturgeon
Copy link
Contributor

Hey thank you. anyOf certainly is important!

Would you try out npm install speccy@beta and see if you get the same error? The move to a JSON Schema validation instead of code-based assertions should improve this sort of error.

If the error persists, we can probably just delete that line, safe in the knowledge that the JSON Schema validation has done its job.

@Shockolate
Copy link
Author

Hey @philsturgeon ! I love it when collaborators follow up quickly :)

I tried the beta release but it didn't seem to work:

$ npm i --save-dev speccy@beta

<peer dependency warnings>

+ speccy@0.8.0-beta1
updated 1 package and audited 1365 packages in 4.804s
found 0 vulnerabilities

$ npm run lint

> MyPackage@0.0.0-development lint /Users/tarmstrong/src/MyPackage
> eslint . && speccy lint v2.0.1/openapi.yaml && speccy lint v2.1.0/openapi.yaml

Specification is valid, with 0 lint errors
Specification schema is invalid.

#/components/schemas/AnyOfExample/properties/intOrFloatProperty
expected Object {
  anyOf: Array [
    Object { type: 'number', format: 'float' },
    Object { type: 'integer', format: 'int32' }
  ],
  ... snip ...
} to have property type
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! standard@0.0.0-development lint: `eslint . && speccy lint v2.0.1/openapi.yaml && speccy lint v2.1.0/openapi.yaml`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the standard@0.0.0-development lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tarmstrong/.npm/_logs/2018-08-08T20_19_25_298Z-debug.log

@philsturgeon
Copy link
Contributor

Whats that debug log got? This doesn't say anything much.

@Shockolate
Copy link
Author

0 info it worked if it ends with ok
1 verbose cli [ '/Users/tarmstrong/.nodenv/versions/8.11.3/bin/node',
1 verbose cli   '/Users/tarmstrong/.nodenv/versions/8.11.3/bin/npm',
1 verbose cli   'run',
1 verbose cli   'lint' ]
2 info using npm@6.3.0
3 info using node@v8.11.3
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle standard@0.0.0-development~prelint: standard@0.0.0-development
6 info lifecycle standard@0.0.0-development~lint: standard@0.0.0-development
7 verbose lifecycle standard@0.0.0-development~lint: unsafe-perm in lifecycle true
8 verbose lifecycle standard@0.0.0-development~lint: PATH: /Users/tarmstrong/.nodenv/versions/8.11.3/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/tarmstrong/src/standard/node_modules/.bin:/Users/tarmstrong/.nodenv/versions/8.11.3/bin:/usr/local/Cellar/nodenv/1.1.2/libexec:/opt/local/bin:/opt/local/sbin:/Users/tarmstrong/.nodenv/shims:/Users/tarmstrong/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle standard@0.0.0-development~lint: CWD: /Users/tarmstrong/src/standard
10 silly lifecycle standard@0.0.0-development~lint: Args: [ '-c',
10 silly lifecycle   'eslint . && speccy lint v2.0.1/openapi.yaml && speccy lint v2.1.0/openapi.yaml' ]
11 silly lifecycle standard@0.0.0-development~lint: Returned: code: 1  signal: null
12 info lifecycle standard@0.0.0-development~lint: Failed to exec lint script
13 verbose stack Error: standard@0.0.0-development lint: `eslint . && speccy lint v2.0.1/openapi.yaml && speccy lint v2.1.0/openapi.yaml`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/tarmstrong/.nodenv/versions/8.11.3/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/Users/tarmstrong/.nodenv/versions/8.11.3/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid standard@0.0.0-development
15 verbose cwd /Users/tarmstrong/src/standard
16 verbose Darwin 17.7.0
17 verbose argv "/Users/tarmstrong/.nodenv/versions/8.11.3/bin/node" "/Users/tarmstrong/.nodenv/versions/8.11.3/bin/npm" "run" "lint"
18 verbose node v8.11.3
19 verbose npm  v6.3.0
20 error code ELIFECYCLE
21 error errno 1
22 error standard@0.0.0-development lint: `eslint . && speccy lint v2.0.1/openapi.yaml && speccy lint v2.1.0/openapi.yaml`
22 error Exit status 1
23 error Failed at the standard@0.0.0-development lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

@philsturgeon
Copy link
Contributor

I really don't know what all this other stuff is about. Can you interact with speccy directly instead of through whatever npm linting something or other you're doing?

@Shockolate
Copy link
Author

$ speccy lint v2.1.0/openapi.yaml 
Specification schema is invalid.

#/components/schemas/AnyOfExample/properties/intOrFloatProperty
expected Object {
  anyOf: Array [
    Object { type: 'number', format: 'float' },
    Object { type: 'integer', format: 'int32' }
  ],
  ... snip ...
} to have property type

@philsturgeon
Copy link
Contributor

Darn. Well if its still happening in v0.8.0-beta1 then it's not anything we can do here in speccy, and it'll need to be handled in oas-kit. Mermade/oas-kit#84

@Shockolate
Copy link
Author

Thank you for your attention, @philsturgeon !
I'll watch that issue

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

2 participants