fastapi-code-generator icon indicating copy to clipboard operation
fastapi-code-generator copied to clipboard

Generation break if parameter name contains illegal character like :

Open slamer59 opened this issue 4 years ago • 2 comments

The following schema will break creating this function def list_pets(rs:query: Optional[int] = None) -> Pets:

schema.yml


openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: "rs:query"
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
                x-amazon-apigateway-integration:
                  uri:
                    Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PythonVersionFunction.Arn}/invocations
                  passthroughBehavior: when_no_templates
                  httpMethod: POST
                  type: aws_proxy
components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string

Solution is to replace : but another legal character like _

slamer59 avatar Sep 03 '21 14:09 slamer59

This can be change with a specific template jinja and replace function for exemple

slamer59 avatar Sep 03 '21 14:09 slamer59

@slamer59 Thank you for creating this issue. The code-generator must changes it to a valid name. I will fix it. thank you.

koxudaxi avatar Sep 08 '21 06:09 koxudaxi