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
296 stars 181 forks source link

@valid annotation can't generated in complex type #403

Open ljheric opened 5 years ago

ljheric commented 5 years ago

I am using raml-jaxrs-maven-plugin with verion 1.3.4 to generate resource code, but the @valid annotation can't be generated. Following is the code

raml file

/collaborationRooms: post: body: schema: CollaborationRoomCreateRequest responses: 201:


type

{ "$schema": "http://json-schema.org/draft-4/schema", "type": "object", "description": "Collaboration room", "javaType" : "com.mcp.api.model.CollaborationRoomCreateRequest", "properties": { "name": { "description":"The name of a collaboration room", "required": true, "type": "string" } }

jpbelang commented 5 years ago

I'm at work right now.

This is generated by jsonschematoobject. Have you activated the options on this?

ljheric commented 5 years ago

I have no idea about it, could you give some instruction how to activate this option? Thank you !

jpbelang commented 5 years ago

A quick examples on how to configure the jsonMapper is here:

https://github.com/mulesoft-labs/raml-for-jax-rs/blob/30389cd51bed450b5a91279cf1cd43fab6edaa1a/raml-to-jaxrs/examples/maven-examples/simple-json-example/pom.xml#L52

The options are defined here (specifically the definition on jsr 303 annotations): https://github.com/mulesoft-labs/raml-for-jax-rs/blob/0344116cbb3f8259425a6b9e4575cee62276abed/raml-to-jaxrs/jaxrs-code-generator/src/main/java/org/raml/jaxrs/generator/RamlToJaxRSGenerationConfig.java#L48

ljheric commented 5 years ago

Here is my maven plugin configuration:

               <plugin>
            <groupId>org.raml.plugins</groupId>
            <artifactId>raml-jaxrs-maven-plugin</artifactId>
            <version>1.3.4</version>
            <configuration>
                <!-- Use sourcePaths if you want to provide a single RAML file or a 
                    list of RAML files -->
                <sourceDirectory>api/internal</sourceDirectory>
                <!-- Optionally configure outputDirectory if you don't like the default 
                    value: ${project.build.directory}/generated-sources/raml-JAX-RS -->
                <basePackageName>com.sap.mcp.collaboration.gen</basePackageName>
                <jaxrsVersion>2.0</jaxrsVersion>
                <useJsr303Annotations>true</useJsr303Annotations>
                <jsonMapper>jackson2</jsonMapper>
                <jsonMapperConfiguration>
                    <includeHashcodeAndEquals>true</includeHashcodeAndEquals>
                </jsonMapperConfiguration>
                <removeOldOutput>true</removeOldOutput>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
        </plugin>

Is that right? I have tried many times, the @valid annotation can't be generated, following is the generated code

@POST @Consumes("application/json") @Produces({ "application/json" }) CollaborationRoomsResource.PostCollaborationRoomsResponse postCollaborationRooms(CollaborationRoomCreateRequest entity) throws Exception ;

What I expected is to add @valid annotation for the parameter "CollaborationRoomCreateRequest entity", how to do that? Thank you!