swagger-codegen-tooling
swagger-codegen-tooling copied to clipboard
JSR 303 Validation for generated Models
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 |
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
Is there a way yet to generate bean validation annotations on the generated pojos?
@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 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.