restful-react icon indicating copy to clipboard operation
restful-react copied to clipboard

Object key invalid after code gen

Open DavidSun0403 opened this issue 5 years ago • 3 comments

Describe the bug I got a invalid key name after I use code gen function if some symbols exits in the swagger.

To Reproduce Steps to reproduce the behavior:

  1. add a line of "- name: X-USERNAME" to the swagger file
  2. restful-react import

DavidSun0403 avatar Dec 11 '19 10:12 DavidSun0403

@DavidSun0403 thanks for the issue! Would you mind providing a swagger document we can test against?

TejasQ avatar Jan 11 '20 16:01 TejasQ

/model:
    get:
      tags:
        - model
      summary: get all model
      operationId: getAllModel
      description: |
        It is avaible for listing choosen model by giving query parameters.
      parameters:
        - name: page
          in: query
          description: page number
          required: false
          schema:
            type: integer
        - name: size
          in: query
          description: size number of per page
          required: false
          schema:
            type: integer
        - name: sort
          in: query
          description: sort and order field
          required: false
          schema:
            type: string
            example: id,asc
        - name: state
          in: query
          description: filter field
          required: false
          schema:
            type: string
            enum: [training, setup, setting, abort]
            example: setup
        - name: name
          in: query
          description: filter field
          required: false
          schema:
            type: string
          example: vs_ad
        - name: version
          in: query
          description: |
            filter field \
            if value of `current`, it indicates the `isCurrent` is true and return the current models.
          required: false
          example: current
          schema:
            type: string
        - name: title[regex]
          in: query
          description: search field
          required: false
          schema:
            type: string
      responses:
        "200":
          description: get all results
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ArrayofModel"
        "400":
          description: bad request

Here is one of our api, the problem is when the parameter name contains some symbol(as this case, title[regex]), the code gen function will just set title[regex] as a json key which is invalid. I have to add quotation mark manually.

DavidSun0403 avatar Jan 13 '20 02:01 DavidSun0403

@DavidSun0403 Interesting, I never saw API with brakets the query params as title[regex], how do you use this in real life?

curl http://myapi.com/model?title[regex]=test  or are you actually expect a real regex? 🤔

We can probably just use escape the key to avoid this kind of strange API 😬

fabien0102 avatar Jan 22 '20 12:01 fabien0102