Comments (10)
Hi,
thanks for asking.
The $ref
does not refer to a file, but contains a schema reference ;-)
So if you change the reference to http://example.com/subspec#/paths/~1v0~1auth~1register/post
and then use:
const validator = new Validator();
await validator.addSpecRef('./v0/auth.v0.yaml', 'http://www.example.com/subspec');
const res = await validator.validate("./api.v0.yaml");
Then it should work.
Hope this helps !
Kind regards,
Hans
from openapi-schema-validator.
Thanks for spotting a bug in the README, the arguments to await validator.addSpecRef
should indeed be switched.
See:
openapi-schema-validator/test/test-validation.js
Lines 214 to 219 in aca3046
Sorry for any confusion caused.
Kind regards,
Hans
from openapi-schema-validator.
FYI: Just published https://github.com/seriousme/openapi-schema-validator/releases/tag/v1.6.1 with an updated README.md
from openapi-schema-validator.
Thanks, for whatever reason I still can't get it working. I can add the reference without an error but still get message: 'must NOT have unevaluated properties'
If I get some time later tonight I will put together a working example of the issue.
from openapi-schema-validator.
Have a working example here, let me know if I am missing something?
Steps to run example:
- unzip and cd into root directory
npm install
npm run validate api.v0.yaml
from openapi-schema-validator.
Hi,
thanks for the example.
I think there is some misunderstanding about the use of references.
A reference is like a pointer to some other place in the schema. Typically in the same file, but by using the addSpecRef
you can include contents from other files in your schema as well.
In your example you are referencing a place in the subschema that does not exist, so the field is effectively empty and therefore it gives you message: 'must NOT have unevaluated properties'
.
The file you refer to is typically not a full openapi schema but just a fragment of such schema. See main-spec.v3.yaml that imports sub-spec.v3.yaml and sub-spec2.v3.yaml in
openapi-schema-validator/test/test-validation.js
Lines 214 to 219 in aca3046
Hope this helps.
Kind regards,
Hans
from openapi-schema-validator.
Okay, we can close this. My example should have used /post
instead of /get
and I think that reference was correct, but I don't want to to take up any more of your time until I can be sure.
from openapi-schema-validator.
I updated my example to something that I think should work following the example you provided. Can you explain why this does not work?
from openapi-schema-validator.
Ok, I forgot to mention one thing :-(
JSONschema allows you to have $ref's all over the place.
OpenApi 3.1.0 not so much :-(
Eg a path item can contain a $ref, but an operation object is not allowed to hold a $ref.
The spec also defines explicitly what you can put into components
Best way to start imho is to draft a simple spec in a doc. Then move parts to the components
section (typically at the bottom) using internal refs and if that all works you can start moving those parts into separate files as shown in the test definition above.
Hope this helps.
Kind regards,
Hans
from openapi-schema-validator.
Thanks for the info, I will take your word for it until I have more time to research further.
from openapi-schema-validator.
Related Issues (7)
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 openapi-schema-validator.