swagger-api / swagger-api/swagger-codegen

jaxrs-jersey jersey2 server stub generated with errors

Open
#11,734 1 comment 0 reactions 1 assignee View on GitHub

@HugoMario is already working on this.

Since Mar 2, 2022.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The server code generated by both swagger-codegen-maven-plugin and swagger hub contains compilation and logic errors with target jaxrs-jersey, library jersey2. The errors are specific to file uploads within a multipart/form-data post.

The generate MediaApi.java source file containts compilation error for mismatched parameters as well as wrong annotations. @FormParam annotations should be @FormDataParam instead AFAIK.

Swagger-codegen version

3.0.33

Swagger declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: BackOffice DAM API
  description: ''

paths:

  '/media':
    post:
      operationId: uploadMedia
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                fileName:
                  type: string
                fileContent:
                  type: string
                  format: binary
      responses:
        '200':
          description: successful operation

servers:
  # Added by API Auto Mocking Plugin
  # Added by API Auto Mocking Plugin
  - description: SwaggerHub API Auto Mocking
    url: https://virtserver.swaggerhub.com/FocalizeCloud/BackOffice_DAM_API/1.0.0
  - description: SwaggerHub API Auto Mocking
    url: https://virtserver.swaggerhub.com/FocalizeCloud/BackOffice_lookbook/1.0.0
Command line used for generation

I heven't used the command line. I've used the swaggerhub and swagger-codegen-maven-plugin.

Steps to reproduce

Either create a new maven project with the following configuration and above api declaration, or configure in swaggerhub the codegen target to jaxrs-jersey and library to jersey2.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>focalize-collection</groupId>
  <artifactId>test-swagger-codegen</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>test-swagger-codegen Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>test-swagger-codegen</finalName>
    <plugins>
	    <plugin>
		    <groupId>io.swagger.codegen.v3</groupId>
		    <artifactId>swagger-codegen-maven-plugin</artifactId>
		    <version>3.0.33</version>
		    <executions>
		        <execution>
		            <goals>
		                <goal>generate</goal>
		            </goals>
		            <configuration>
		                <inputSpec>src/main/resources/api.yaml</inputSpec>
		                <language>jaxrs-jersey</language>
		                <configOptions>
		                   <sourceFolder>src/gen/java/main</sourceFolder>
		                   <library>jersey2</library>
		                   <java8>true</java8>
                           <dateLibrary>java8</dateLibrary>
		                </configOptions>
		            </configuration>
		        </execution>
		    </executions>
		</plugin>
    </plugins>
  </build>
</project>
Related issues/PRs
Suggest a fix/enhancement

The generated code:

@POST
    
    @Consumes({ "multipart/form-data" })
    
    @Operation(summary = "", description = "", tags={  })
    @ApiResponses(value = { 
        @ApiResponse(responseCode = "200", description = "successful operation") })
    public Response uploadMedia(@Parameter(description = "")  @FormParam("fileName")  String fileName
,@FormDataParam("fileContent") InputStream fileContentInputStream,
            @FormDataParam("fileContent") FormDataContentDisposition fileContentDetail
,@Context SecurityContext securityContext)
    throws NotFoundException {
        return delegate.uploadMedia(fileName,fileContent,securityContext);
    }

Should instead be:

    @POST
    
    @Consumes({ "multipart/form-data" })
    
    @Operation(summary = "", description = "", tags={  })
    @ApiResponses(value = { 
        @ApiResponse(responseCode = "200", description = "successful operation") })
    public Response uploadMedia(@Parameter(description = "")  @FormDataParam("fileName")  String fileName
,@FormDataParam("fileContent") InputStream fileContentInputStream,
            @FormDataParam("fileContent") FormDataContentDisposition fileContentDetail
,@Context SecurityContext securityContext)
    throws NotFoundException {
        return delegate.uploadMedia(fileName,fileContentInputStream,fileContentDetail,securityContext);
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.