Skip to content

Commit

Permalink
Merge branch 'master' into issue-334
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Sep 7, 2023
2 parents c21aba9 + 71723ee commit 3ad6e66
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 14 deletions.
6 changes: 5 additions & 1 deletion fastapi_code_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ 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 or argument.default is not None
positional_argument = (
argument.required
or (argument.default is not None)
or argument.type_hint.startswith('Optional[')
)

return arguments

Expand Down
2 changes: 1 addition & 1 deletion fastapi_code_generator/template/main.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app = FastAPI(


{% for operation in operations %}
@app.{{operation.type}}('{{operation.snake_case_path}}', response_model={{operation.response}}
@app.{{operation.type}}('{{operation.path}}', response_model={{operation.response}}
{% if operation.additional_responses %}
, responses={
{% for status_code, models in operation.additional_responses.items() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def post_bar(request: Request) -> None:


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


@app.put('/convert', response_model=bytes)
def convert2(format: Optional[str] = None, request: Request = ...) -> bytes:
pass


Expand Down Expand Up @@ -94,7 +99,7 @@ def post_pets(body: PetForm) -> Union[None, Error]:


@app.get(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=Pet,
responses={'default': {'model': Error}},
tags=['pets'],
Expand All @@ -107,7 +112,7 @@ def show_pet_by_id(pet_id: str = Path(..., alias='petId')) -> Union[Pet, Error]:


@app.put(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=None,
responses={'default': {'model': Error}},
tags=['pets'],
Expand Down Expand Up @@ -142,7 +147,7 @@ def post_users(body: List[UsersPostRequest]) -> None:


@app.post(
'/{ue_id}/sdm-subscriptions', response_model=None, tags=['Subscription Creation']
'/{ueId}/sdm-subscriptions', response_model=None, tags=['Subscription Creation']
)
def subscribe(ue_id: str = Path(..., alias='ueId'), body: Pet = ...) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


@app.get(
'/{supi_or_suci}/security-information-rg',
'/{supiOrSuci}/security-information-rg',
response_model=None,
tags=['Get Auth Data for FN-RG'],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_pets() -> Union[None, Error]:


@app.get(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=Pets,
responses={'404': {'model': Error}, 'default': {'model': Error}},
tags=['pets'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_pets() -> Union[None, Error]:


@app.get(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=Pets,
responses={'default': {'model': Error}},
tags=['pets'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_pets() -> Union[None, Error]:


@app.get(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=Pets,
responses={'default': {'model': Error}},
tags=['pets'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def post_pets(body: PetForm) -> Union[None, Error]:


@app.get(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=Pet,
responses={'default': {'model': Error}},
tags=['pets'],
Expand All @@ -85,7 +85,7 @@ def show_pet_by_id(pet_id: str = Path(..., alias='petId')) -> Union[Pet, Error]:


@app.put(
'/pets/{pet_id}',
'/pets/{petId}',
response_model=None,
responses={'default': {'model': Error}},
tags=['pets'],
Expand All @@ -100,7 +100,7 @@ def put_pets_pet_id(


@app.post(
'/pets/{pet_id}/image',
'/pets/{petId}/image',
response_model=None,
responses={'default': {'model': str}},
tags=['pets'],
Expand Down
25 changes: 24 additions & 1 deletion tests/data/openapi/default_template/body_and_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ paths:
required: true
/convert:
post:
operationId: convert
description: https://github.com/koxudaxi/fastapi-code-generator/issues/376
operationId: convert1
parameters:
- in: query
name: format
Expand All @@ -360,6 +361,28 @@ paths:
schema:
type: string
format: binary
put:
description: https://github.com/koxudaxi/fastapi-code-generator/issues/322
operationId: convert2
parameters:
- in: query
name: format
schema:
type: string
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

0 comments on commit 3ad6e66

Please sign in to comment.