OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.32k stars 6.45k forks source link

[REQ] Validator request/response #4923

Open esoni88 opened 4 years ago

esoni88 commented 4 years ago

Is your feature request related to a problem? Please describe.

I need a tool that validate the response of an api if it is compliant respect OpenApi specification.

Describe the solution you'd like

Openapi generator support the validator generation ?

jimschubert commented 4 years ago

Are you looking for generated code which includes validation in models? We do this in some of our generators. We would need to know which language/framework you're targeting to know if it's implemented in the relevant generator.

Bessonov commented 4 years ago

@jimschubert from my point of view the question is more "should openapi generator include validation in generated coder or just provide mapping"? We use typescript-fetch for mapping and use ajv for validation. It's a little bit cumbersome, because there are some differences between them and sometimes we must implement some transformations to satisfy both. For example typescript-fetch doesn't supports nullable very well and ajv doesn't supports oneOf very well.

It would be great to have one tool. Should generated code include validation?

vglushonkov commented 2 years ago

Nowadays, Is there a way to implement some sort of response validation against generated models?

Johnlon commented 2 years ago

There are various validation libs that you can pass a schema and payload to to validate. My observations are that sometimes libs spot different issues from eachother, the error messages are cryptic, but deal breaker for me was that the validators don't seem to include the option of detection of payload fields that are not in the oas. So I apply some opensource validation then apply my own "undeclared field" checker