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

Running spectral CLI on OAS with external schemas produces incorrect results #751

Closed
huksley opened this issue Nov 7, 2019 · 8 comments · Fixed by stoplightio/json#37
Closed
Assignees
Labels
t/bug Something isn't working

Comments

@huksley
Copy link

huksley commented Nov 7, 2019

Description

When running spectral on OpenAPI 3 specification with externally defined schemas, spectral gives errors for completely valid schemas and OpenAPI Specification.

PLEASE NOTE Running spectral on schemas folder alone gives no errors 🤷‍♂

To Reproduce

  1. Checkout this repo with branch https://github.com/huksley/maas-tsp-api/tree/spec-schemas
  2. Install packages npm install
  3. Build local schemas npm run build
  4. Run this CLI command npm run lint
  5. See errors:
/home/test/maas-tsp-api/schemas/core/components/bike-station.json
 34:3  error  parser  Duplicate key: required

/home/test/maas-tsp-api/schemas/core/components/state-log.json
 49:7  error  parser  Duplicate key: additionalProperties

/home/test/maas-tsp-api/schemas/core/customer.json
 104:7  error  parser  Duplicate key: required
 105:7  error  parser  Duplicate key: additionalProperties

/home/test/maas-tsp-api/schemas/core/components/fare.json
 31:5  error  parser  Duplicate key: type

/home/test/maas-tsp-api/schemas/core/components/terms.json
 120:11  error  parser  Duplicate key: type

/home/test/maas-tsp-api/schemas/core/modes/MODE_BICYCLE.json
 23:9  error  parser  Duplicate key: type

/home/test/maas-tsp-api/schemas/core/modes/MODE_SHARED_BICYCLE.json
 11:9  error  parser  Duplicate key: type

/home/test/maas-tsp-api/specs/booking.yml
 251:15  error  oas3-schema  /paths//bookings/options/get/responses/200 should have required property '$ref'

**Example case schemas/core/components/bike-station.json breakdown **

For following schema (when referenced from OAS):

{
  "$id": "http://maasglobal.com/core/components/bike-station.json",
  "description": "MaaS bike station schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "location": {
      "$ref": "../../../schemas/core/components/units-geo.json#/definitions/location"
    },
    "slots": {
      "type": "object",
      "properties": {
        "total": {
          "type": "number",
          "minimum": 0
        },
        "empty": {
          "type": "number",
          "minimum": 0
        },
        "bikes": {
          "type": "number",
          "minimum": 0
        }
      },
      "required": ["total", "empty", "bikes"]
    }
  },
  "required": ["id", "name", "location"]
}

produces following error:

 34:3  error  parser  Duplicate key: required

Expected behavior
These errors should not be reported.

Environment (remove any that are not applicable):

  • Library version: 4.2.0
  • OS: MacOS 10.14.6
  • Node: 12.11.1
@huksley huksley added the t/bug Something isn't working label Nov 7, 2019
@huksley huksley changed the title Running spectral CLI on OAS spec with complex schemas produces incorrect results Running spectral CLI on OAS with external schemas produces incorrect results Nov 7, 2019
@philsturgeon
Copy link
Contributor

Hey I can’t find the specs you’re talking about, is it the default branch you linked to, develop, or somewhere else? It’s hard to tel what’s going on from just the one file.

@huksley
Copy link
Author

huksley commented Nov 7, 2019

@philsturgeon Hi,
yes you need specific branch and
you need first run npm run build to copy schemas locally

I´ve updated repo and issue description,
sorry for not being clear on this

@huksley
Copy link
Author

huksley commented Nov 19, 2019

@philsturgeon Any updates on this? Could I be of an assistance?

@philsturgeon
Copy link
Contributor

Sorry I'm out of brain space to look into this, but hopefully one of the team will be with you soon!

@P0lip
Copy link
Contributor

P0lip commented Dec 3, 2019

Hey, my sincere apologies for dropping a ball on this one.
I can confirm it's an issue and will fix it very soon.
Thanks for the report.

@P0lip
Copy link
Contributor

P0lip commented Dec 4, 2019

@huksley
The issue has been fixed and will be released in the next version of Spectral.
In the meantime, you can mitigate the issue by setting a resolution in your package.json.

"resolutions": {
  "@stoplight/json": "^3.2.2"
}

Make sure to reinstall dependencies once resolution is set.
If you don't use Yarn, you may need to use npm-force-resolutions.
That said, the release is around, so you can just wait a tiny bit longer 🙂

Last but not least, make sure to remove the actual duplicate property in schemas/core/error.json 😉

@huksley
Copy link
Author

huksley commented Dec 10, 2019

Thanks @P0lip!

I done the changes specified and Schema errors are gone!!!
However it still complains about oas3-schema error, is there something wrong with the specification?

It is in this branch/PR maasglobal/maas-tsp-api#52

> maas-tsp-api@0.0.3 lint-spec /Users/user/src/maas-tsp-api
> node utils/adopt-schemas.js && cross-env NODE_OPTIONS=--max_old_space_size=4096 spectral lint specs/booking.yml

OpenAPI 3.x detected

/Users/user/src/maas-tsp-api/specs/booking.yml
 319:11  error  oas3-schema  /paths//bookings/options/get/parameters/4 should have required property '$ref'

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)

I took a look at parameters, they are all have defined type via schema/$ref

If I remove the mode parameter, which declared like this (and references this):

        - name: mode
          description: 'Transfer mode'
          in: query
          required: false
          schema:
            $ref: ../schemas/core/components/travel-mode.json

it starts to complain with this:

/Users/user/src/maas-tsp-api/specs/booking.yml
 337:15  error  oas3-schema  /paths//bookings/options/get/responses/200 should have required property '$ref'

which is again looks fine to me 🤔

      responses:
        '200':
          x-summary: Array of options
          description: |
            Available transport options matching the given query parameters. If no transport options are available; an empty array is returned.
          content:
            application/json:
              schema:
                $ref: ../schemas/tsp/booking-options-list/response.json
              examples:
                Taxi:
                  summary: Taxi
                  externalValue: '../examples/taxi/booking-options-response.json'

Kind of related to #403 🤷‍♂

@P0lip
Copy link
Contributor

P0lip commented Dec 17, 2019

@huksley
Yeah, we know oas3-schema tends to produce weird errors.
Feel free to post your issue in that ticket!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants