Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6715
Closed
Open
Issue created Jun 19, 2020 by Administrator@rootContributor

Java/RestTemplate - Allow flexible options in generated client when a file is needed

Created by: MosheElisha

Hi,

I have an API that requires a org.springframework.web.multipart.MultipartFile parameter (Swagger 2.0 API spec is below).

I am using generatorName=java and library=resttemplate to generate the client.

The generated Api client looks like:

public ResponseEntity<Template> createTemplateWithHttpInfo(File file, com.example.model.CreateTemplateRequest request) throws RestClientException {
...
    if (file != null)
            formParams.add("file", new FileSystemResource(file));
...

I would like to have the option to generate a client that takes an org.springframework.core.io.AbstractResource instead of a File. The user will be able to pass a new FileSystemResource(file) to have same behavior as now but if the user does not have the file on disk, he/she can use an InputStreamResource or a ByteArrayResource or ... For example:

    api.createTemplateWithHttpInfo(
        new ByteArrayResource(byteArray) {
          @Override
          public String getFilename() {
            return "memoryBytes";
          }
        },
        ...
    );

From the source code it seems that there is no such option: https://github.com/OpenAPITools/openapi-generator/blob/5cdc9e9e35b737b04a5a201446fb430a554ef5db/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache#L133

I'm proposing a new configOption (something like "useAbstractionForFiles") and every library can try to support as possible (My first priority is to have the resttemplate library support this).

Swagger 2.0 API spec:

      "post" : {
        "operationId" : "createTemplate",
        "consumes" : [ "multipart/form-data" ],
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "file",
          "in" : "formData",
          "required" : true,
          "type" : "ref"
        }, {
          "name" : "request",
          "in" : "formData",
          "required" : true,
          "type" : "ref"
        } ],
        "responses" : {
          "200" : {
            "description" : "successful operation",
            "schema" : {
              "$ref" : "#/definitions/Template"
            }
          },
          "201" : {
            "description" : ""
          }
        }
      }
    }
Assignee
Assign to
Time tracking