OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][CXF-CLIENT] Multipart argument not generated

Open
#17,718 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating a CXF webservice client according to the OpenAPI 3.0.1 specification, the interface code generated does not allow multipart attachment to be defined, even though the package containing the classes representing the multipart has been imported from the CXF framework.

openapi-generator version

6.6.0 (does not appear to be a regression, and reproduces 5.4.0 to 7.2.0).

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: sample
  version: 1.0.0
security:
- authenticated: []
paths:
  /file:
    post:
      tags:
      - Foo
      summary: Test
      operationId: bar
      parameters:
      - name: X-Meta-Eol
        in: header
        description: end of life
        schema:
          type: string
          format: date-time
          nullable: true
      requestBody:
        description: File
        content:
          multipart/form-data:
            schema:
              type: string
              format: binary
      responses:
        "201":
          description: okay
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileId'
        "401":
          description: Not ok
components:
  schemas:
    FileId:
      type: object
      properties:
        id:
          type: string
          description: ident
        md5:
          type: string
          description: md5
Generation Details

Maven plugin configuration:

<plugin>
	<groupId>org.openapitools</groupId>
	<artifactId>openapi-generator-maven-plugin</artifactId>
	<version>6.6.0</version>
	<executions>
		<execution>
			<id>execution-sample</id>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<inputSpec>${project.basedir}/src/main/resources/sample.yml</inputSpec>
				<apiPackage>foo.webservice.api</apiPackage>
				<modelPackage>foo.webservice.model</modelPackage>
			</configuration>
		</execution>
    </executions>
    <configuration>
		<generatorName>jaxrs-cxf-client</generatorName>
        <generateApiTests>false</generateApiTests>
        <generateModelTests>false</generateModelTests>
        <configOptions>
			<java8>true</java8>
			<dateLibrary>java8</dateLibrary>
            <openApiNullable>false</openApiNullable>
            <sourceFolder>generated</sourceFolder>
        </configOptions>
    </configuration>
</plugin>

Maven dependencies:

    <dependencies>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
            <version>1.6.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>3.1.4</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
Steps to reproduce

Simply generate the client code using the maven configuration and the YAML file defined in this ticket.

Currently

package foo.webservice.api;

import foo.webservice.model.FileId;
import java.time.OffsetDateTime;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
import org.apache.cxf.jaxrs.ext.multipart.*; // <---- Already imported

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH;

/**
 * sample
 *
 * <p>No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 */
@Path("/file")
@Api(value = "/", description = "")
public interface FooApi  {

    /**
     * Test
     *
     */
    @POST
    
    @Consumes({ "multipart/form-data" })
    @Produces({ "application/json" })
    @ApiOperation(value = "Test", tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 201, message = "okay", response = FileId.class),
        @ApiResponse(code = 401, message = "Not ok") })
    public FileId bar(@HeaderParam("X-Meta-Eol")  OffsetDateTime xMetaEol);
}

Expected

package foo.webservice.api;

import foo.webservice.model.FileId;
import java.time.OffsetDateTime;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
import org.apache.cxf.jaxrs.ext.multipart.*; // <---- Already imported

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH;

/**
 * sample
 *
 * <p>No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 */
@Path("/file")
@Api(value = "/", description = "")
public interface FooApi  {

    /**
     * Test
     *
     */
    @POST
    @Consumes({ "multipart/form-data" })
    @Produces({ "application/json" })
    @ApiOperation(value = "Test", tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 201, message = "okay", response = FileId.class),
        @ApiResponse(code = 401, message = "Not ok") })
    public FileId bar(MultipartBody body, @HeaderParam("X-Meta-Eol")  OffsetDateTime xMetaEol);
}
Related issues/PRs

Not ATM

Suggest a fix

Research in progress

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.

Research direction

Start with the Maven plugin configuration and OpenAPI YAML in the issue, then reproduce generation with the jaxrs-cxf-client generator and inspect the generated FooApi interface. Done means the generated bar method includes the expected MultipartBody parameter while retaining the header parameter and response annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.