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

codegen, oas-3-compat: Treatment of parameter style "deepObject" is shady

Created by: lorenzleutgeb

Description

It seems to me that your codegen layer does not treat the deepObject style for parameters. For example it is missing in the method DefaultCodegen#getCollectionFormat where it should probably be treated in one way or another.

The result for the YAML below is that I get a client implementation that does not seem to handle the deepObject case in ApiClient:

    public List<Pair> parameterToPair(String name, Object value) {
        List<Pair> params = new ArrayList<Pair>();

        // preconditions
        if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params;

        params.add(new Pair(name, parameterToString(value)));
        return params;
    }

    public String parameterToString(Object param) {
        if (param == null) {
            return "";
        } else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
            //Serialize to json string and remove the " enclosing characters
            String jsonStr = json.serialize(param);
            return jsonStr.substring(1, jsonStr.length() - 1);
        } else if (param instanceof Collection) {
            StringBuilder b = new StringBuilder();
            for (Object o : (Collection)param) {
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append(String.valueOf(o));
            }
            return b.toString();
        } else {
            return String.valueOf(param);
        }
    }

The resulting query parameter looks like:

filter=class%20Filter%20%7B%0A%20%20%20%20id%3A%20null%0A%20%20%20%20updatedAtGt%3A%20null%0A%7D

where I would expect no parameters to be present (all values inside the filter object are null). Generally I expect it to look like:

filter[id]=x&filter[updated_at|gt]=y
openapi-generator version

020883fd (master from 2018-07-04)

OpenAPI declaration file content or url
paths:
  '/foo':
    get:
      parameters:
        - name: filter
          in: query
          required: false
          style: deepObject
          schema:
            properties:
              "updated_at|gt":
                type: string
                format: date-time
Command line used for generation

java -jar openapi-generator-cli.jar generate -l java -i api.yml -o jclient

Steps to reproduce

Generate client.

Suggest a fix/enhancement

You should treat deepObject style parameters as specified in OAS 3.0.1, there even is an example: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-examples

Assignee
Assign to
Time tracking