Skip to content

[BUG][python-fastapi] &#39 in generated api when adding a default to optional query string parameter #15685

Open
@Beaueve

Description

@Beaueve

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Adding a default to an optional query parameter of type int leads to invalid arguments for Query call.

Generated code:

# coding: utf-8

from typing import Dict, List  # noqa: F401

from fastapi import (  # noqa: F401
    APIRouter,
    Body,
    Cookie,
    Depends,
    Form,
    Header,
    Path,
    Query,
    Response,
    Security,
    status,
)

from openapi_server.models.extra_models import TokenModel  # noqa: F401


router = APIRouter()


@router.get(
    "/pet/findByStatus",
    responses={
        200: {"description": "successful operation"},
    },
    tags=["default"],
    response_model_by_alias=True,
)
async def pet_find_by_status_get(
    status: str = Query('default_string', description="Status values that need to be considered for filter"),
) -> None:
    """Multiple status values can be provided with comma separated strings"""
    ...
openapi-generator version

Version 6.6.0

OpenAPI declaration file content or url
openapi: 3.0.2
servers:
  - url: /v3
info:
  description: ""
  version: 1.0.17
  title: Swagger Petstore - OpenAPI 3.0
paths:
  /pet/findByStatus:
    get:
      description: Multiple status values can be provided with comma separated strings
      parameters:
        - in: query
          name: status
          description: Status values that need to be considered for filter
          schema:
            type: string
            default: "default_string"
      responses:
        '200':
          description: successful operation
Steps to reproduce
java -jar generators/openapi-generator-cli-.jar generate -i min_spec.yaml -g python-fastapi -o pet_store 

Look in default_api.py line 33:

Related issues/PRs

None found

Suggest a fix

Change {{default}} in endpoint_arguments_definition.mustache, to {{&default}}.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions