mulesoft-labs / raml-for-jax-rs

This project is all about two way transformation of JAX-RS-annotated Java code to RAML API description and back.
Other
295 stars 181 forks source link

JSR 303 - @valid annotation is not getting generated on the List of complex type #361

Closed gr423 closed 6 years ago

gr423 commented 6 years ago

Hi Team ,

I've the below RAML

event:
type: object
properties:
  metadataset:
   required: false
   type: metadatSetType[]

metadatSetType:
  type: object
  properties:
    locale:
    required: true
    type: string
  name:
    required:false
    type: string

Generated Java Objects are as below ,

I'm expecting the @valid annotation on the metadataSet of event .Which is not getting generated. And the JsonMapperConfiguration is never considered while generating the code . includeAdditionalproperties is made false , but still the java objects generated has the field.

@JsonInclude(JsonInclude.Include.NON_NULL)
Class Event
{
    @JsonProperty("metadataSet")
    List<MetadatSetType> metadataSet;
  @JsonIgnore
  private Map<String, Object> additionalProperties = new HashMap<String, Object>();
}
@JsonInclude(JsonInclude.Include.NON_NULL)
Class MetadatasetType
{
 @JsonProperty("locale")
 @NotNull
  String locale;
 @JsonProperty("name")
String name;
  @JsonIgnore
  private Map<String, Object> additionalProperties = new HashMap<String, Object>();
}

Pom File


<plugin>
<groupId>org.raml.jaxrs</groupId>
<artifactId>raml-to-jaxrs-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>GenerateAdminV2</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<ramlFile>${basedir}/src/main/resources/raml/v1/MAS_api.raml</ramlFile>
<resourcePackage>com..mas.v1.resource</resourcePackage>
<modelPackage>com..mas.v1.model</modelPackage>
<removeOldOutput>true</removeOldOutput>
<generateTypesWith>
    <value>jsr303</value>
    <value>jackson2</value>
   </generateTypesWith>
  <jsonMapperConfiguration>
     <includeAdditionalProperties>false</includeAdditionalProperties>
</jsonMapperConfiguration>
</configuration>
</execution>
</executions>
</plugin>
gr423 commented 6 years ago

@jstoiko Hi Jonathan, Please can you help here , Basically i want to validate each element of the collection , which is provided by the Javax validation . But since the @valid annotation is missed on the List type in the generated code, i'm missing on the validation of the List elements .

Thanks in advance, Ramya

jpbelang commented 6 years ago

Just back from vacation, looking at it.

jpbelang commented 6 years ago

includeAdditionalproperties is made false , but still the java objects generated has the field.

Have you tried the current snapshot ? I've fixed that, I think.

https://github.com/mulesoft-labs/raml-java-tools/issues/12

jpbelang commented 6 years ago

For the @Valid annotation, I will add it if the list contains an object type or union type (as opposed to a list type or primitive type).

String and integers require custom annotations. I know that java 8 supports annotating generic types, but right now, we have to support java 7 and this would be a major change. You could still pull it off with a plugin.

jpbelang commented 6 years ago

@gr423 , could you try the SNAPSHOT please ? (On branch 3.0.3)

gr423 commented 6 years ago

@jpbelang , Its working :) Thank you !! The @Valid annotation is getting generated on the list type and the validations are working. I did take the the release 3.0.3 snapshot version and built the project. Since i build the raml-to-jaxrs project locally i was able to use raml-to-jaxrs-maven-plugin with 3.0.3-SNAPSHOT version .

Can we expect the same version in maven repository . Sorry i'm not sure of the procedure of when the latest version of the projects gets reflected in the maven repo . Can you please throw some light on this updates .

Thanks and Regards, Ramya

jpbelang commented 6 years ago

The SNAPSHOTS are on mulesoft's repositories (I don't have them here, I'll get them for you tonight).

Building them locally is certainly ok, but if you need to share them between devs, either you upload them to your own repo or point to the mulesoft repo

gr423 commented 6 years ago

Sure, let me try this option.

Thank you

On Fri, 24 Aug 2018, 11:40 pm JP Belanger, notifications@github.com wrote:

The SNAPSHOTS are on mulesoft's repositories (I don't have them here, I'll get them for you tonight).

Building them locally is certainly ok, but if you need to share them between devs, either you upload them to your own repo or point to the mulesoft repo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mulesoft-labs/raml-for-jax-rs/issues/361#issuecomment-415838823, or mute the thread https://github.com/notifications/unsubscribe-auth/AfGuzpm9U1cb6kmRpAFH--2lZiqhfnA_ks5uUEGngaJpZM4V9r0E .

gr423 commented 6 years ago

@jpbelang
Hi ,

Since our project would go to production by this month end ,i'm not able to proceed with the SNAPSHOT version .

Please could you let me know , if can expect the release version some time closer.

Or else can you suggest me the alternate, with which i can go ahead doing validations .

Thanks in advance , Ramya S

jpbelang commented 6 years ago

I have one bit of the Arrays bug that I need to finish, which I should do tomorrow.

I'm trying to release on the week-end.

gr423 commented 6 years ago

Thanks for the update . Sure we will wait for the release .

Regards, Ramya

jpbelang commented 6 years ago

I've just released 3.0.3. it should come up soon on central.

gr423 commented 5 years ago

@jpbelang Hi , The RAML exposed endpoints are consumed by CXF Rest Client. But getting the issue of deserialization on retrieving the response . The issue is asked for in stackOverflow. https://stackoverflow.com/questions/52521191/jax-rs-client-cant-deserialize-json-response-returned-from-raml-1-0-generated-cl

Please could you give me some insight here .


Below is generated interface.
@Path("/editorialChannels")
public interface EditorialChannels {
  /**
   */
  @PUT
  @Produces("application/json")
  @Consumes("application/json")
  PutEditorialChannelsResponse putEditorialChannels(
      @Valid com.nagra.opentv.mas.v1.model.EditorialChannels entity);

  class PutEditorialChannelsResponse extends ResponseDelegate {
    private PutEditorialChannelsResponse(Response response, Object entity) {
      super(response, entity);
    }

    private PutEditorialChannelsResponse(Response response) {
      super(response);
    }

    public static PutEditorialChannelsResponse respond200WithApplicationJson(PutResponse entity) {
      Response.ResponseBuilder responseBuilder = Response.status(200).header("Content-Type", "application/json");
      responseBuilder.entity(entity);
      return new PutEditorialChannelsResponse(responseBuilder.build(), entity);
    }
}
}