swagger-codegen-tooling icon indicating copy to clipboard operation
swagger-codegen-tooling copied to clipboard

JSR 303 Validation for generated Models

Open maschleg opened this issue 9 years ago • 5 comments

It would be nice to have some validation for defined Models (Schema Objects). Swagger uses the JSON Schema Validation as Validation Specification. This codegen Plugin cloud map the defined validation into JSR 303: Bean Validation. For example:

Swagger JSR 303
required @NotNull
maximum @Max
minimum @Min
pattern @Pattern

maschleg avatar Jun 12 '15 08:06 maschleg

It is implemented (without 'pattern'). Please try out. Use true in the pom.

0.4.9

jbellmann avatar Jun 30 '15 10:06 jbellmann

Hi again! Using version 0.4.12, still getting ''' [INFO] Generate for language : jaxrsinterfaces [INFO] JSR 303 enabled ... [INFO] but not supported by jaxrsinterfaces '''

because of this probles and issue related to swagger-codegen (you may see https://github.com/swagger-api/swagger-codegen/issues/443#issuecomment-124129718 ; guys advices to test their develop_2.0 branch to check if issue still exists; but even it not exists, it need to be released first and then i think version of codegen used by your plugin must also be updated as well...) 'contract validation' implemented as set of ugly if blocks

ghost avatar Jul 30 '15 09:07 ghost

Is there a way yet to generate bean validation annotations on the generated pojos?

jkerak avatar Oct 13 '16 14:10 jkerak

@jkerak I would say it is (without 'pattern'). See here for a configuration-example. Does not work for JAX-RS, only implemented for Spring-***-templates. Let me know how it worked for you (or if not open an issue and paste some stacktraces if possible)

jbellmann avatar Oct 13 '16 15:10 jbellmann

@jbellmann I ran that code sample and did not find it working. In the ApplicationDetails swagger definition, name is defined with minLength: 1. When I ran the integration tests and looked at the resulting ApplicationDetails.java, I expected to see an @Min annotation on the name property, but it is not there.

jkerak avatar Oct 13 '16 15:10 jkerak