OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.56k stars 6.52k forks source link

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

Open Beaueve opened 1 year ago

Beaueve commented 1 year ago

Bug Report Checklist

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}}.

lvijnck commented 1 year ago

Adding in here, defaults in for the body in the spec are also not adhered.

Can we broaden the issue?