OpenAPITools / OpenAPITools/openapi-generator

Using "content" instead of "schema" in query param does not work

Open
#14,424 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

for example, We want our query argument to end up with color=[" blue","black","brown"] instead of color=blue,black,brown or color=blue; color=black; Color = brown, So we use content.

openapi-generator version

6.2.1

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: test_title
  description: test_description
  version: '2022-12-13'
servers:
  - url: https://openapi.alipay.com
    description: Production server
  - url: http://openapi.stable.dl.alipaydev.com
    description: Development server
paths:
  /v3/alipay/trade/query:
    get:
      tags:
        - alipay.trade
      summary: alipay.trade.query
      description: "qqq"
      operationId: alipay.trade.query
      responses:
        '200':
          description: common response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AlipayTradeQueryResponseModel'
        default:
          description: failed
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/CommonErrorType'
                  - $ref: '#/components/schemas/AlipayTradeQueryErrorResponseModel'
      parameters:
        - name: out_trade_no
          in: query
          description: "out_trade_no"
          required: false
          schema:
            type: string
            example: '20150320010101001'
        - name: query_options
          in: query
          description: xxx
          required: false
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
Command line used for generation
java -jar bin/openapi-generator-cli-6.2.1.jar generate \
    -g java\
    -i src/main/resources/test_enum.yaml\
    -o gen \
    -c src/main/resources/java-sdk.json \
    -t src/main/resources/Java \
    --global-property skipFormModel=false,modelTests=false,apiTests=false,modelDocs=false
Steps to reproduce

The resulting code is:

if (queryOptions != null) {
    localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("csv", "query_options", queryOptions));
}

The resulting url is:
xxx?color=blue,black,brown

Is there something wrong with my usage or is content not supported?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Java client code and the parameterToPairs("csv", "query_options", queryOptions) call shown in the report. Trace how query parameters declared with content and an application/json schema are represented and serialized, then compare the generated URL with the requested JSON-array form. Done means the content declaration produces the intended query encoding and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.