Hi
thanks for the explanation.
On 18/08/16 11:57, J. Fiala wrote:
Hi,
If I'm using BeanValidation-annotations in my model classes, they are
not picked up by the WADLGenerator and so are lost if I do code first
and I have to look them up and model them in the WADL manually.
At least @NotNull support would be nice, because this is really easy to
do (see the PR).
WADLGenerator will set a required flag if it is 'int'/'boolean' as
opposed to Boolean/Integer
The others are a bit more tricky as they have to be generated as inline
simpletypes and probably in the WADL would be replaced by existing
simpletypes in the WADL/schema, but at least the developer has the hint
there is a pattern/restriction in place.
I already implemented @Size/@Min/@Max/@Pattern so you just have to pull
it in.
I'd rather prefer to avoid going into all these schema manipulations.
These hints can me made available in WADL grammar directly - have you
checked if JAXB annotations can be used to set some of those
restrictions ? Another option: WADL generator can be configured with a
prepared XML schema as opposed to generating it.
So better support for the BeanValidation annotations makes code first a
lot easier and also extending an existing WADL using code first for new
model classes...
thanks, Sergey
Best regards,
Johannes
Am 18.08.2016 um 00:29 schrieb Sergey Beryozkin:
Hi
Can you explain please what exactly the purpose of it can be ?
WADL generator simply reports the model info by using a JAXB compiler
to generate XML schema, I'm trying to figure out how does the bean
validation can help here or what it can change
Sergey
On 17/08/16 18:18, J. Fiala wrote:
I added this PR for bean-validation-support for query parameters:
https://github.com/apache/cxf/pull/146
This also adds the required-flag for params by supporting @NotNull (see
related question here:
http://stackoverflow.com/questions/13968261/required-queryparam-in-jax-rs-and-what-to-do-in-their-absence).
Additionally the PR adds support for @Size, @Min/@Max and @Pattern to
the query parameters and will add the proper restrictions inline:
* @NotNull - minOccurs="1"
* @Size - "<xs:minLengthvalue = " + size.min() + "/>",
"<xs:maxLengthvalue = " + size.max() + "/>"
* @Min - "<xs:minInclusive value = " + min.value() + "/>"
* @Min - "<xs:maxInclusive value = " + max.value() + "/>"
* @Pattern - <xs:pattern value=" + pattern.regexp() + " />"
For adding bean-validation-support to the complex types the JAXB
processing / schema has to be parsed/filtered.
The Java to schema mappings seems to be done here in WadlGenerator.java,
line 1541:
for (DOMResult r : JAXBUtils.generateJaxbSchemas(context,
CastUtils.cast(Collections.emptyMap(),
String.class,
DOMResult.class))) {
Am I correct in assuming we need a JAXB adapter which picks up the
beanvalidation-annotations?
https://docs.oracle.com/cd/E19316-01/819-3669/bnbdf/index.html
So it seems we need to prepare the proper XmlAdapters
(https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html)
to generate the necessary restrictions in the schema.
However, it would also be nice to also add proper SimpleTypes and
reference them from the complexTypes (e.g. simpleType string_50 for a
string with a maximum of 50).
Best regards,
Johannes
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/