Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate valid python code if query param has default value and requeststBody is required #377

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastapi_code_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def get_argument_list(self, snake_case: bool, path: List[str]) -> List[Argument]
for argument in arguments:
if positional_argument and argument.required and argument.default is None:
argument.default = UsefulStr('...')
positional_argument = argument.required
positional_argument = argument.required or argument.default is not None

return arguments

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing import List, Optional, Union

from fastapi import FastAPI, Path, Query
from fastapi import FastAPI, Path, Query, UploadFile
from starlette.requests import Request

from .models import (
Expand Down Expand Up @@ -36,6 +36,11 @@ def post_bar(request: Request) -> None:
pass


@app.post('/convert', response_model=bytes)
def convert(format: Optional[str] = 'pdf', file: UploadFile = ...) -> bytes:
pass


@app.get('/foo', response_model=str, tags=['foo'])
def get_foo(foo: Optional[str] = None) -> str:
pass
Expand Down
23 changes: 23 additions & 0 deletions tests/data/openapi/default_template/body_and_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,29 @@ paths:
schema:
$ref: '#/components/schemas/Pet'
required: true
/convert:
post:
operationId: convert
parameters:
- in: query
name: format
schema:
type: string
default: pdf
requestBody:
required: true
content:
application/octet-stream:
schema:
type: string
format: binary
responses:
"200":
content:
application/octet-stream:
schema:
type: string
format: binary
components:
parameters:
MyParam:
Expand Down
Loading