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
  • #546
Closed
Open
Issue created Jul 12, 2018 by Administrator@rootContributor

[Java][Spring] Server codegen gradle task fails when operation only has header parameters, and generator has implicitHeaders=true

Created by: jcohen-stingray

Description

Gradle codegen task fails with IndexOutOfBoundException. This is caused when the generator task has the additional parameter of implicitHeaders = true and the operation in the api yaml specification file only has header parameters.

openapi-generator version

3.0.3

OpenAPI gradle task specification (partial)
swagger: '2.0'
paths:
  /account-info:
    get:
      tags:
      - Account
      summary: Get the account information
      operationId: getAccountInfo
      parameters:
      # HEADERS
      - $ref: '#/parameters/userIdTokenHeaderParam'
      - $ref: '#/parameters/clientIdHeaderParam'
      - $ref: '#/parameters/languageHeaderParam'
      responses:
        200:
          description: Account Info
          schema:
            $ref: '#/definitions/Account'
          headers:
            cache-control:
              type: string
              description: Caching rules
        400:
          $ref: '#/responses/BadRequest'
        401:
          $ref: '#/responses/Unauthorized'
        403:
          $ref: '#/responses/Forbidden'
        500:
          $ref: '#/responses/UnexpectedError'
Gradle task specification for generation
openApiGenerate {
    ...
    generatorName = 'spring'
    additionalProperties = [
        ...
        'interfaceOnly'     : 'true',
        'java8'             : 'true',
        'delegatePattern'   : 'true',
        'implicitHeaders'   : 'true',
        'useTags'           : 'true',
//        'useOptional'       : 'true', // bug in codegen prevents using this with delegatePattern=true
//        'async'             : 'true', // Only use if necessary (defaults to CompletableFuture for java8, Future for java<8)
//        'responseWrapper'   : 'CompletableFuture',
    ]
}
Suggest a fix/enhancement

Add check for list size before setting last element value

Class: org.openapitools.codegen.languages.SpringCodegen Original method:

private void removeHeadersFromAllParams(List<CodegenParameter> allParams) {
        if(allParams.isEmpty()){
            return;
        }
        final ArrayList<CodegenParameter> copy = new ArrayList<>(allParams);
        allParams.clear();

        for(CodegenParameter p : copy){
            if(!p.isHeaderParam){
                allParams.add(p);
            }
        }
        allParams.get(allParams.size()-1).hasMore =false;
    }

Suggested fix:

private void removeHeadersFromAllParams(List<CodegenParameter> allParams) {
        if(allParams.isEmpty()){
            return;
        }
        final ArrayList<CodegenParameter> copy = new ArrayList<>(allParams);
        allParams.clear();

        for(CodegenParameter p : copy){
            if(!p.isHeaderParam){
                allParams.add(p);
            }
        }
        if (!allParams.isEmpty()) {
            allParams.get(allParams.size()-1).hasMore =false;
        }
    }
Assignee
Assign to
Time tracking