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
  • #8659
Closed
Open
Issue created Feb 09, 2021 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG][SPRING] Different in-parameter types generated for api and delegate

Created by: easymindster

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?
Description

When using the maven plugin to generate java code for spring using the delegate pattern, the API differs between the API and the delegate. The generated API gets a body of type Resource, but the delegate is generated with the type MultipartFile, see below. The expected in-parameter type would be a Resource.

    @ApiOperation(value = "Upload content", nickname = "apiUpload", notes = "", response = Resource.class, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK", response = Resource.class) })
    @RequestMapping(value = "/upload",
        produces = { "application/octet-stream" }, 
        consumes = { "application/octet-stream" },
        method = RequestMethod.PUT)
    default ResponseEntity<Resource> apiUpload(@ApiParam(value = "" ,required=true )  @Valid @RequestBody Resource body) {
        return getDelegate().apiUpload(body);
    }

Generated code for the delegate:

    default ResponseEntity<Resource> apiUpload(MultipartFile body) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }
openapi-generator version

openapi-generator-maven-plugin, v.4.3.1

OpenAPI declaration file content or url
openapi: '3.0.2'
info:
  title: Test API
  version: "0.0.1"
servers:
  - url: http://localhost:8080/test  
paths:
  /upload:
    put:
      summary: "Upload content"
      operationId: apiUpload
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        '200':
          description: OK
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary   
Generation Details

Extract from pom.xml:

         <plugin>
           <groupId>org.openapitools</groupId>
           <artifactId>openapi-generator-maven-plugin</artifactId>
           <version>4.3.1</version>
           <executions>
             <execution>
               <id>generate-rest-api</id>
               <phase>generate-sources</phase>
               <goals>
                 <goal>generate</goal>
               </goals>
               <configuration>
                 <inputSpec>${project.basedir}/src/main/resources/openapi/testapi.yml</inputSpec>
                 <generatorName>spring</generatorName>
                  <modelPackage>${default.package}.openapi.test.model</modelPackage>
                  <apiPackage>${default.package}.openapi.test.api</apiPackage>
                  <invokerPackage>${default.package}.openapi.invoker</invokerPackage>
                 <configOptions>
                   <sourceFolder>src/gen3/java/main</sourceFolder>
                   <validateSpec>true</validateSpec>
                   <java8>true</java8>
                   <dateLibrary>java8</dateLibrary>
                   <interfaceOnly>false</interfaceOnly>
                   <delegatePattern>true</delegatePattern>
                 </configOptions>
               </configuration>
             </execution>
           </executions>
         </plugin>         
Steps to reproduce

Use maven to generate the sources, i.e. mvn clean generate-sources

Related issues/PRs

None found.

Assignee
Assign to
Time tracking