stoicflame / enunciate

Build-time enhancement tool for Java-based Web services projects
http://enunciate.webcohesion.com/
Other
480 stars 200 forks source link

Problem to use swagger annotation with enunciate #1162

Closed luigcapo closed 1 year ago

luigcapo commented 1 year ago

Hello

I have a rest API that I deploy to swagger Ui using enunciate. But I have some problems using swagger annotations to add comments on swagger Ui. There are some annotations that don't work on the Ui (@ApiModelProperty) and some that work just fine (@ApiOperation).

Here is an example from my source code

pom.xml

<plugin>
        <groupId>com.webcohesion.enunciate</groupId>
        <artifactId>enunciate-maven-plugin</artifactId>
        <version>2.14.0</version>
         <executions>
          <execution>
            <goals>
              <goal>assemble</goal>
            </goals>
          </execution>
        </executions> 
      </plugin>
.....
<dependency>
        <groupId>com.webcohesion.enunciate</groupId>
        <artifactId>enunciate-core-annotations</artifactId>
        <version>2.14.0</version>
      </dependency>
      <dependency>
          <groupId>com.webcohesion.enunciate</groupId>
          <artifactId>enunciate-rt-util</artifactId>
          <version>2.14.0</version>
      </dependency>
       <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>2.3.7.Final</version>
    </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.6.9</version>
        </dependency>

User class (where i use @ApiModelProperty and @ApiModel which don't work)

ApiModel(description = "User Model")
public class User {
    @ApiModelProperty(value = "user's age", required = true) 
    private String age;
    @ApiModelProperty(value = "user numero", example = "0000", required = true) 
    private String numero;

UserRessource.class my web service . ApiOperation works but ApiParam doesn't work

@ApiOperation(value = "Gets users by Numero", notes = "user must exist")
    @GET
    @Path("/agences/{numero}")
    public Response getUserByNumero(@ApiParam(value = "User numero", example = "5152", required = true) @PathParam("usernUMERO")  String numero) throws Throwable {
            if (StringUtils.isBlank(numero)) {
                return toResponse(ErrorMessages.ERROR_MISS_AGENCE_NUM);
            }
            return getUserByNumero(numero);
    }

Is it possible that some swagger annotations don't work with enunciate 2.14 and other annotation work?

stoicflame commented 1 year ago

I just never got around to implementing support for those annotations. Enunciate has it's own mechanisms (JavaDoc, annotations, etc.) for providing the same information, so it hasn't been a high priority.

luigcapo commented 1 year ago

Hello,

Thank you for your answer. Do you have an equivalent for the annotation @ApiParam(value = "User number", required = true) in order to add description to a GET REQUEST. i haven't find a note about that in Annotation enunciate

stoicflame commented 1 year ago
/**
 * @param userNumber User number
 * @return The user.
 */
@GetMapping
public User getUser(@RequestParam(required=true) String userNumber) {
  ...
}