swagger-api / swagger-api/swagger-codegen

[FINCH] Parameters in query are generated as path parameters

Open
#4,885 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

The Finch code generator does not support query parameters correctly. They get generated as if they were path parameters.

Swagger-codegen version

2.2.2-SNAPSHOT

Swagger declaration file content or url
  /delivery/lookup/{clientId}/{appId}:
    get:
      tags:
        - Delivery
      operationId: lookup
      summary: Lookup
      description: Lookup
      parameters:
        - name: clientId
          type: string
          in: path
          required: true
          description: Client ID
        - name: appId
          type: string
          in: path
          required: true
          description: app id
        - name: url
          type: string
          in: query
          required: true
          description: page url to lookup
      responses:
        200:
          description: Response delivery object
          schema:
            $ref: '#/definitions/ResponseLookup'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

which generates

  private def lookup(da: DataAccessor): Endpoint[ResponseLookup] =
    get("delivery" :: "lookup" :: string :: string :: string) { (clientId: String, appId: String, url: String) =>
      Ok(da.Delivery_lookup(clientId, appId, url))
    } handle {
      case e: Exception => BadRequest(e)
    }
Suggest a Fix

The generator should instead generate

private def lookup(da: DataAccessor): Endpoint[ResponseLookup] =
    get("delivery" :: "lookup" :: string :: string :: param("url").as[String]) { (clientId: String, appId: String, url: String) =>
      Ok(da.Delivery_lookup(clientId, appId, url))
    } handle {
      case e: Exception => BadRequest(e)
    }

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 inspecting the Finch generator's parameter mapping and the generated Scala endpoint shown in the issue. Compare path and query parameter handling, then verify that the url query parameter is generated as param("url").as[String] rather than as another path segment.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.