Giter Club home page Giter Club logo

Comments (5)

jonasschmidt avatar jonasschmidt commented on August 16, 2024

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.

0xAX avatar 0xAX commented on August 16, 2024

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.

jonasschmidt avatar jonasschmidt commented on August 16, 2024

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.

0xAX avatar 0xAX commented on August 16, 2024

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.

0xAX avatar 0xAX commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.