swagger-api / swagger-api/swagger-codegen

[typescript-angular] Square brackets in form names result in invalid syntax

Open
#7,604 1 comment 1 reaction 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

Trying to describe an existing (Symfony) environment in swagger to build a Angular 4 client against it.

Forms in the Symfony environment contain fields like:

<input type="text" id="username" name="registration[username]" required="required">

I modelled that in an OpenAPI 2.0 definition (See yaml below).

Which validates against the Swagger editor.
But the generated the Typescript API results in invalid code because the square brackets are not escaped in variable names:

public registerUserWithHttpInfo(language: string, country: string, registration[username]: string)
Swagger-codegen version

3.0.0-SNAPSHOT (Don't know if it is regression, when starting the project I could only use 3.0 to get valid Angular 4 code to begin with)

Swagger declaration file content or url
swagger: '2.0'
info:
  title: 'App'
  version: 0.1.0
paths:
  /{language}/{country}/registration:
    post:
      summary: Registers the user
      operationId: registerUser
      parameters:
        - name: language
          in: path
          type: string
          description: The language of the user
          required: true
        - name: country
          in: path
          type: string
          description: The country of the user
          required: true
        - name: registration[username]
          in: formData
          type: string
          description: The username of the user
          required: true
      consumes:
        - application/x-www-form-urlencoded
      produces:
        - application/json
      responses:
        '200':
          description: The user is registered
Command line used for generation

java -jar swagger-codegen-cli-3.0.0-20170904.171256-3.jar generate -i openapi.yml -l typescript-angular

Related issues/PRs

Similar to https://github.com/swagger-api/swagger-codegen/issues/4290

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

Reproduce the issue with the supplied OpenAPI YAML and the typescript-angular generation command. Start in the typescript-angular generator and its templates, then verify that the form parameter registration[username] produces valid TypeScript while preserving the intended request field name; regenerate the client to confirm the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.