0

I'm using 'jaxrs-spec' in order to generate server stubs that are deployed in a JEE server (JBoss Wildfy).

As I need my generated model pojos to be annotated with JAXB annotations (like @XmlRootElement), I have enabled the 'withXml" option. This is working very fine with "Java" language, but does not seem possible with "jaxrs-spec". Right ??

As a result, because of the missing JAXB annotations, jaxrs responses of my web services are producing incorrect xml (ie without namespace declaration) although xml namespace is defined in the yaml file.

Did someone already manage to generate jaxb annotations in combination with 'jaxrs-spec' language ? Any workaround ?

Bernard.

<plugin>    
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.4.0</version>
    ... 
    <configuration>                 
        ...                 
        <language>jaxrs-spec</language>                                                                 
        <generateModels>true</generateModels>
        <withXml>true</withXml> 
        ...
    </configuration>

Example of generated model:

@ApiModel
public class ReadingRequest {..}

Expected:

@ApiModel
@XmlRootElement(namespace="...") // <= missing !
public class ReadingRequest {..}
TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17

1 Answers1

0

Temporarily (?) solved using the following workaround.

  • Override original mustache template for Jaxrs-spec > Pojo, inspiring from the pure Java template.
  • Put the modified mustache template (with addition of JAXB stuff) under my projet (eg src/main/resources/templates/pojo.mustache)
  • Update Maven config of CodeGen plugin in order to use this extra template:
    <configuration>                   
      <templateDirectory>src/main/resources/templates</templateDirectory>
    </configuration>
TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17