ScottLogic / openapi-forge

⚒️🔥 Effortlessly create OpenAPI clients, in a range of languages, from the fiery furnace of our forge
8 stars 7 forks source link

Support validation of model objects via JSON Schema #26

Open ColinEberhardt opened 2 years ago

ColinEberhardt commented 2 years ago

As per https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#properties

OpenAPI supports a subset of JSON Schema rules for validating values.

jhowlett-scottlogic commented 2 years ago

If im not mistaken generate.js:49 await SwaggerParser.validate(cloneSchema(schema)); does this.

I tested by changing the Pet model in the petstore.json swagger schema. object -> objct and it failed to validate schema. I did the same with the type -> tyrpe and it failed to validate

I also tested the petsotre.json schema that i converted into yml and it also gave validation errors.

the petstore.json is OpenAPI v3.0.2

ColinEberhardt commented 2 years ago

What I'm considering with this issue is that when an object has constraints associated with it, we generate a model object that enforces those constraints. Does that make sense?

jhowlett-scottlogic commented 2 years ago

Ok, yes that makes sense. @osouthwell-scottlogic had a little exploration into this and found that for CSharp it will be simple as you can add validation to model objects but TypeScript will be a little more time consuming as all supported validators will need to be written by hand.