Comments (9)
No problem. The good news is this feature was a pain to implement anyways so removing it makes my life easier. 👍
from swagger-parser.
Hi. Sorry for not replying sooner. I've been away on holiday.
The $ref
in responses.yaml
is invalid, because it's pointing to a definition within the same file, which doesn't exist (see the JSON Reference spec for details).
Instead of referencing a type definition, you need to directly reference the extended_error_model.yaml
file instead, like this:
# Common responses
200:
description: OK
schema:
type: string
DefaultError:
description: Error payload
schema:
$ref: 'definitions/error/extended_error_model.yaml' # <-- referencing the file
from swagger-parser.
Another way to fix the problem would be to point to the type definition in your index.yaml
or definitions/index.yaml
file, like this:
# Common responses
200:
description: OK
schema:
type: string
DefaultError:
description: Error payload
schema:
$ref: 'index.yaml#/definitions/ExtendedErrorModel' # <-- referencing the type definition
from swagger-parser.
Thanks for pointing to the spec.
I couldn't find anything definitive and the closest I found indicated that this is tooling issue. sway and its predecessor swagger-tools seem to do it the other way (remotes first and then local).
So I wasn't sure which way is the right way. @whitlockjc If this is invalid per spec, why Sway and swagger-tool support it?
I'm asking so that I can present a good case for going back and changing the few dozen APIs in my org who are already doing this (i.e. relative refs that are in other files).
from swagger-parser.
When I read the spec, I didn't feel it was very clear. I am sure the point where you suggest I deviate from the spec falls in this statement:
If a URI contains a fragment identifier, then the fragment should be
resolved per the fragment resolution mechansim of the referrant
document.
While this does explain that local references should be resolved against the local document, the specification leaves a lot to interpretation when it comes to the order in which resolution happens. It's this that I think causes the discrepancy. I'll file a bug in json-refs and reference this issue in the report. I'm currently rewriting json-refs anyways and we'll just not do the hierarchical resolution for local references in remote documents. Thanks for bringing this up.
from swagger-parser.
@mrchief - Just to clarify... It's not a matter of "remotes first" vs "local first". The order is irrelevant. The issue is scope resolution. A $ref
such as #/foo/bar
is relative to the root of the current file, not to the root of the entire JSON schema. That said, the JSON Reference spec does allow the resolution scope to be changed using special id
properties, but I don't think that feature of JSON Reference is supported by Swagger.
from swagger-parser.
Well, what I meant by order was if you just create a composite document by including the remote document first and then resolving the local references, the local reference in your remote document could possibly apply to the original (remote) document or the composite document that the remote document was just included into. In fact, that's why it was written the way it was. In all fairness, I do think there was some invalid Swagger usage that led to this.
from swagger-parser.
@whitlockjc - Ah, ok. I see what you mean by "order" now. Thanks for the clarification. 👍
from swagger-parser.
Closing this issue, since Swagger Parser is working as intended.
from swagger-parser.
Related Issues (20)
- Report all errors from Ajv's schema validation
- Open API 3.1 - Additional properties not allowed: $id HOT 1
- swagger-parser 10.1.0 is broken when used with npm < 7 or using --legacy-peer-deps HOT 7
- Latest version missing schema validation changes HOT 1
- Online validator is becoming unresponsive HOT 2
- Insecure Default Resolver Behavior HOT 4
- [HELP] - Please help me add this package on Vite HOT 2
- `swagger-parser@npm:10.0.2 doesn't provide openapi-types` HOT 1
- swagger version field as 'number' type is not detected in one case HOT 1
- Files over 3mb cause com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException HOT 1
- Parameterise the validator function HOT 1
- ts property continueOnError is missing from SwaggerPaser.Options
- Unable to access requestBody after dereferencing my contract yaml
- validator doesn't support anchor tags in the paths (ie /my/base/url#myAnchor) HOT 2
- Import JSON Schema as File Not Over HTTP Request HOT 2
- Not able to parse stripe openapi file HOT 2
- Update OpenAPI 3.0.0 to OpenAPI 3.1 HOT 2
- Multiple minor problems parsing docker API spec HOT 2
- Header Parameters not validated
- Support for Wildcard HTTP Responses
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swagger-parser.