Comments (5)
Hey. Can you provide a bit more context about what exactly you're trying to do? Which part of that Swagger schema are you using as the JSON Schema, and what is the JSON payload you're validating?
from ex_json_schema.
Hi,
Which part of that Swagger schema are you using as the JSON Schema
I'm using phoenix_swagger to parse swagger schema into json schema. Actually it just takes two parts of any swagger schema: paths
and definitions
.
Which part of that Swagger schema are you using as the JSON Schema, and what is the JSON payload you're validating?
For example:
{"Field1", "foo bar"}
for the schema which I've posted above:
"Foo": {
"type": "object",
"required": [
"Field1"
],
"properties": {
"Field1": {
"$ref": "#/definitions/Field1"
},
"Field2": {
"$ref": "#/definitions/Field2"
}
}
Is it clear or you need more details?
Thank you.
from ex_json_schema.
Ok, so I had a look at what phoenix_swagger
is doing with the Swagger schema to turn it into a JSON Schema to validate parameters against. There's a bunch of code that tries to determine which parameters are required and merges everything into one JSON Schema that is then used to validate all the params against (https://github.com/xerions/phoenix_swagger/blob/master/lib/phoenix_swagger/validator.ex#L116-L138). I'm not exactly sure what the end result of those transformations is, and there is also no test for that case in the phoenix_swagger
test suite (in fact there is no test for body parameters at all, which are handled differently from path/query/header params in Swagger).
So as long as I don't know what the actual JSON Schema is that it then uses to validate some params map, I can't really figure out what could be the problem. It's very unlikely that there's a bug around required parameters in ex_json_schema
since all that logic is tested quite extensively, both against the official JSON Schema test suite and in additional unit tests.
In general, the approach taken in phoenix_swagger
falls a bit short, and covers only a fraction of what the Swagger schema has to say about validation. And I suspect that some parts of it are also not exactly conforming to the specification. I think it mostly works for checking if some query parameters are there or not.
That being said, I am currently working on an actual Swagger validator in Elixir (https://github.com/jonasschmidt/ex_swagger) that will fully conform to the Swagger specification when it's done. There are some parts of the Swagger schema that use a subset of JSON Schema, but there's also a big part of it that's custom and can't be easily mapped to JSON Schema. There are still some things that need to be implemented, but the parts that are there are thoroughly tested. It will probably take me a few more weeks to have the remaining parts implemented and have things in a state where I can push out an initial version.
from ex_json_schema.
Hello @jonasschmidt, thank you for such detailed reply.
In general, the approach taken in phoenix_swagger falls a bit short, and covers only a fraction of what the Swagger schema has to say about validation.
Yes, maybe. I will check it there. Only one question: I see that required
fields are represented as list. For example ["foo", "bar", "baz"]
.
What if I have following definition in my schema:
"definitions": {
"MyObject": {
"type": "object",
"required": ["Foo", "Bar"],
"properties": {
"Foo": {
"type": "string"
},
"Bar": {
"type": "object",
"$ref": "#/definitions/Baz"
}
}
}
"Baz": {
"required": ["Foo1", "Bar1"]
...
...
...
}
}
How to collect required fields in this way? Should it be ["Foo", "Bar", "Foo1", "Bar1"]
or something else? Actually I'm confusing how to be with Foo1
and Bar1
fields in this case
Thank you.
from ex_json_schema.
Yes, seems it is error of phoenix_swagger. So Im closing the issue. @jonasschmidt thank you for the help
from ex_json_schema.
Related Issues (20)
- Needs more validation error details HOT 3
- Improper resolution of referenced subschema HOT 6
- Map.take deprecation HOT 2
- Add contributors with merge rights HOT 1
- Warning messages when running with Elixir 1.9.1 & OTP 22 HOT 2
- Intent to implement: custom string validation HOT 1
- Changelog HOT 2
- IO.inspect in hex package HOT 2
- Examples on usage HOT 3
- Error on extra attributes? HOT 1
- Elixir 1.11 deprecations HOT 1
- Feature request: make enum, properties, propertyNames and additionalProperties (or the actual schema) available for custom errors HOT 4
- Support custom formats for non-string types HOT 5
- I cant see why I'm getting this error
- Any plans to support 2019 and 2020 ? HOT 6
- Issue with oneOf when used in conjunction with pattern HOT 7
- No support for dependentRequired HOT 2
- Make schema domain configurable HOT 1
- Error line number HOT 1
- Handling refs in a schema HOT 3
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 ex_json_schema.