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
  • #9462
Closed
Open
Issue created May 12, 2021 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[BUG][Java][Spring] Different in-parameter types generated for api and delegate for binary (application/octet-stream) #9331 breaks outparameter

Created by: beckerjohannes

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

The breaking change introduced in #9331 (in a fix version!) applies not only to in-Parameters but also to out-Parameters. The result is that 5.1.1 cannot be applied for projects having application/octet-stream as response parameters. It is not only a breaking change (requiring source code change) the results in compile errors, these errors cannot be fixed, as MultipartFile is not a valid return value.

After the Change the generated API is this:

    /**
     * GET /downloadFile/{fileId} : File for an ID
     * Retrieves file.
     *
     * @param fileId Numeric ID of the file. (required)
     * @return OK (status code 200)
     */
    @ApiOperation(value = "File for an ID", nickname = "getFile", notes = "Retrieves file.", response = org.springframework.web.multipart.MultipartFile.class, tags={ "files", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK", response = org.springframework.web.multipart.MultipartFile.class) })
    @GetMapping(
        value = "/downloadFile/{fileId}",
        produces = { "application/octet-stream" }
    )
    default ResponseEntity<org.springframework.web.multipart.MultipartFile> getFile(@ApiParam(value = "Numeric ID of the file.",required=true) @PathVariable("fileId") Long fileId) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }

Before Version 5.1.1 it was:

default ResponseEntity<org.springframework.core.io.Resource> getFile(@ApiParam(value = "Numeric ID of the file.",required=true) @PathVariable("fileId") Long fileId) 

However, the newly generated interface contract cannot be satisfied in a clean way, as MultipartFile is not supposed to be a return value. See Spring documentation of MultipartFile

A representation of an uploaded file received in a multipart request.

The file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired. The temporary storage will be cleared at the end of request processing.

openapi-generator version

5.1.1

OpenAPI declaration file content or url
get:
  tags:
    - files
  summary: File for an ID
  description: Retrieves file.
  operationId: getFile
  parameters:
    - in: path
      name: fileId
      schema:
        type: integer
        format: int64
      required: true
      description: Numeric ID of the file.
  responses:
    200:
      description: OK
      content:
        application/octet-stream:
          schema:
            type: string
            format: binary
Generation Details

Generation with openapi-generator-maven-plugin

                            <!-- specify the OpenAPI spec -->
                            <inputSpec>dipa-hub.yaml</inputSpec>
                            <enablePostProcessFile>false</enablePostProcessFile>

                            <generatorName>spring</generatorName>
                            <additionalProperties>removeEnumValuePrefix=false</additionalProperties>

                            <configOptions>
                                <apiPackage>online.dipa.hub.api.rest</apiPackage>
                                <modelPackage>online.dipa.hub.api.model</modelPackage>
                                <interfaceOnly>true</interfaceOnly>
                                <generateSupportingFiles>false</generateSupportingFiles>
                                <generateModelTests>false</generateModelTests>
                                <generateModelDocumentation>false</generateModelDocumentation>
                                <generateApiDocumentation>false</generateApiDocumentation>
                                <generateApiTests>false</generateApiTests>
                                <serializableModel>true</serializableModel>
                                <snapshotVersion>true</snapshotVersion>
                                <useTags>true</useTags>
                            </configOptions>
Steps to reproduce

See compile errors in the following PR https://github.com/DiPA-Projekt/dipa-hub/pull/300

Related issues/PRs

Introduced in #9331

Suggest a fix

Ensure that #9331 is only applied to in parameters and not to response parameters.

Assignee
Assign to
Time tracking