Running spectral CLI on OAS with external schemas produces incorrect results
See original GitHub issueDescription
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
- Checkout this repo with branch https://github.com/huksley/maas-tsp-api/tree/spec-schemas
- Install packages
npm install
- Build local schemas
npm run build
- Run this CLI command
npm run lint
- 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Spectral CLI - Stoplight
Once Spectral is installed and you have a ruleset, run Spectral via the command-line: Powered by Stoplight.
Read more >@stoplight/spectral - npm
A flexible JSON object linter with out of the box support for OpenAPI v2 and v3. Features. Create custom rules to lint any...
Read more >RSt - River Thames Conditions - Environment Agency - GOV.UK
#forum Moontara technovations, Relai electrique schema? ... 328i convertible review 2011, Coaster run knotts berry farm, Wrong pronunciation vine, ...
Read more >Untitled
Glock 22 review police, Rachel platten live acoustic. #Michel Ipn vs unam 2011, Marcos para fotos graduacion! Kylie glasgow hydro 2014, Dr coudreuse...
Read more >Untitled
#garden 8 minutes in the morning review, Anonymous kkk list facebook, Browns stats vs seahawks, Cgtb ceara, Pony blog korea, Distrutto dal dolore...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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
😉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 https://github.com/maasglobal/maas-tsp-api/pull/52
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):it starts to complain with this:
which is again looks fine to me 🤔
Kind of related to #403 🤷♂