swagger-api / swagger-api/swagger-codegen

[lang php] object in query param sent as json string instead associative array

Open
#10,548 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Via https://editor.swagger.io/ generated correct request with multidemensional array settings:

image

settings[app_info][app_id]=123&settings[app_info][app_hash]=321

But via PHP generated client generated request:

/system/addSession?session=sxfgd&settings=%7B%0A%20%20%20%20%22settings%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22app_info%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22app_id%22%3A%20123%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22app_hash%22%3A%20%22321%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D
/system/addSession?session=sxfgd&settings={
    "settings": {
        "app_info": {
            "app_id": 123,
            "app_hash": "321"
        }
    }
}
            $ai = new AppInfo();
            $ai->setAppId($event->getApplication()->api_id);
            $ai->setAppHash($event->getApplication()->api_hash);

            $ss = new SessionSettings();
            $ss->setAppInfo($ai);

            $settings = new Settings();
            $settings->setSettings($ss);

            $getSessionListResponse = $apiInstance->addSession($event->getSession(), $settings);

session param is string contains json object. This is not correct request.

Swagger-codegen version

swagger-codegen-cli-3.0.22.jar

Swagger declaration file content or url
openapi: 3.0.1
info:
  title:

  version:

servers:
- url:

paths:
  /system/addSession:
    get:
      parameters:
      - name: session
        in: query
        description: Session name
        required: true
        schema:
          type: string
      - name: settings
        in: query
        description: Settings
        required: false
        schema:
          $ref: '#/components/schemas/settings'
      responses:
        "200":
          description: successful operation

components:
  schemas:
    AppInfo:
      type: object
      properties:
        app_id:
          type: integer
          description: App api_id
        app_hash:
          type: string
          description: App api_hash
    settings:
      type: object
      properties:
        settings:
          $ref: '#/components/schemas/SessionSettings'
    SessionSettings:
      type: object
      properties:
        app_info:
          $ref: '#/components/schemas/AppInfo'
Command line used for generation
docker run --rm -v ${PWD}:/local -w /local openjdk java -jar swagger-codegen-cli.jar generate --input-spec /local/openapi.yaml --lang php --output /local/out/ -c /local/openapi-codegen-php.json
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

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 by reproducing the generated PHP client request from the supplied openapi.yaml with swagger-codegen-cli-3.0.22.jar, then inspect the generated addSession call and its query serialization. Compare the object-valued settings parameter with the Swagger Editor request; done means nested settings are sent as associative query parameters rather than a JSON string.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php
Domain
api, backend
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.