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
  • #4375
Closed
Open
Issue created Nov 05, 2019 by Jorge Rodríguez Martín@jorgerodContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [Java]: Client resttemplate and webclient: array parameters of type integer in path badly generated

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Java-client resttemplate and webclient generator generates code that does not compile when yaml contains array parameters of type integer in the path.

openapi-generator version

4.1.3,4.2.0

OpenAPI declaration file content or url

.openapi-rest.yml

openapi: 3.0.2
info:
  title: My-api
  version: 0.1.0
paths:
  /articles/{ids}:
    get:
      summary: Find articles by article ids
      description: Retrieve articles from their ids.
      operationId: articles
      parameters:
        - name: ids
          description: article ids separated by commas
          in: path
          required: true
          schema:
            type: array
            items:
              type: integer
      responses:
        '200':
          description: OK
Command line used for generation

java -jar openapi-generator-cli.jar generate -g java -i openapi-rest.yml -o openapi --library resttemplate

Steps to reproduce

Run the above command.

Generated code does not compile because apiClient.collectionPathParameterToString wait Collection<? extends CharSequence> and ids is a list of integers.

Output: .DefaultApi.java

    /**
     * Find articles by article ids
     * Retrieve articles from their ids.
     * <p><b>200</b> - OK
     * @param ids article ids separated by commas
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void getArticles(List<Integer> ids) throws RestClientException {
        //...
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("ids", apiClient.collectionPathParameterToString(ApiClient.CollectionFormat.valueOf("csv".toUpperCase()), ids));
               
    //...
    }

.ApiClient.java

    /**
    * Formats the specified collection path parameter to a string value.
    *
    * @param collectionFormat The collection format of the parameter.
    * @param values The values of the parameter.
    * @return String representation of the parameter
    */
    public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
        //...
    }
Related issues/PRs

2177 2137

Assignee
Assign to
Time tracking