OpenAPITools / OpenAPITools/openapi-generator

[Java][jaxrs-jersey] unnecessary multipart imports in generated code

Open
#1,421 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

if the java jaxrs-jersey server code is generated from a model which doesn't need the jersey multipart feature, the multipart packages are imported anyway.

openapi-generator version

openapi-generator 3.3.2

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: foo
  description: >-
    bar
  version: 1.1.0
paths:
  /foo/v1/bar:
    get:
      summary: read foo bar
      operationId: getFooBar
      responses:
        200:
          content:
            application/json:
              schema:
                default:
          description: all went ok
Command line used for generation

Java -jar openapi-generator-cli-3.3.2.jar generate -i /foobar.yaml -g jaxrs-jersey -o /foobar

java output
package fooBar.impl;

import fooBar.*;
import fooBar.model.*;


import java.util.List;
import fooBar.NotFoundException;

import java.io.InputStream;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.validation.constraints.*;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", date = "2018-11-12T10:51:46.203+01:00[Europe/Berlin]")
public class FooApiServiceImpl extends FooApiService {
    @Override
    public Response getFooBar(SecurityContext securityContext) throws NotFoundException {
        // do some magic!
        return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
    }
}
Suggest a fix/enhancement

in the templates should be a check around the multipart imports:

{{#useMultipartFeature}}
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
{{/useMultipartFeature}}

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 jaxrs-jersey templates and reproduce the supplied Java generation command using the minimal OpenAPI YAML. Check how multipart imports are emitted when the model has no multipart feature, then verify generation still includes them for multipart endpoints. Done means unused multipart imports are absent without breaking cases that need them.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.