Skip to content

Commit

Permalink
Merge pull request #144 from yetanotherjsontodatabaseexporter/tags
Browse files Browse the repository at this point in the history
now it's possible to use tags in templates
  • Loading branch information
koxudaxi authored Apr 29, 2021
2 parents 7c6ca7a + db4d810 commit 4b08eff
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions fastapi_code_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Operation(CachedPropertyModel):
imports: List[Import] = []
security: Optional[List[Dict[str, List[str]]]] = None
components: Dict[str, Any] = {}
tags: Optional[List[str]]
openapi_model_parser: OpenAPIModelParser

@cached_property
Expand Down
4 changes: 2 additions & 2 deletions tests/data/custom_template/security/main.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def valid_current_user(token: str = Depends(valid_token)) -> User:


{% for operation in operations %}
@app.{{operation.type}}('{{operation.snake_case_path}}', response_model={{operation.response}})
@app.{{operation.type}}('{{operation.snake_case_path}}', response_model={{operation.response}}{% if operation.tags -%}, tags={{operation.tags}}{%- endif -%})
def {{operation.function_name}}({{operation.snake_case_arguments}}{%- if operation.security -%}{%- if operation.snake_case_arguments -%}, {%- endif -%}user: User = Depends(valid_current_user){%- endif -%}) -> {{operation.response}}:
pass
{% endfor %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def valid_current_user(token: str = Depends(valid_token)) -> User:
return get_dummy_user(token)


@app.get('/food/{food_id}', response_model=None)
@app.get('/food/{food_id}', response_model=None, tags=['foods'])
def show_food_by_id(food_id: str, user: User = Depends(valid_current_user)) -> None:
pass

Expand All @@ -59,19 +59,19 @@ def list_pets(
pass


@app.post('/pets', response_model=None)
@app.post('/pets', response_model=None, tags=['pets'])
def post_pets(body: PetForm, user: User = Depends(valid_current_user)) -> None:
pass


@app.get('/pets/{pet_id}', response_model=Pet)
@app.get('/pets/{pet_id}', response_model=Pet, tags=['pets'])
def show_pet_by_id(
pet_id: str = Query(..., alias='petId'), user: User = Depends(valid_current_user)
) -> Pet:
pass


@app.put('/pets/{pet_id}', response_model=None)
@app.put('/pets/{pet_id}', response_model=None, tags=['pets'])
def put_pets_pet_id(
pet_id: str = Query(..., alias='petId'),
body: PetForm = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ paths:
get:
summary: List all pets
operationId: listPets
tags:
- pets
security: []
parameters:
- name: limit
Expand Down

0 comments on commit 4b08eff

Please sign in to comment.