Skip to content

Commit 1664a17

Browse files
authored
Merge pull request #567 from koxudaxi/issue-467-query-array-params
Preserve query array parameter types
2 parents c2fa6a1 + a54fd92 commit 1664a17

6 files changed

Lines changed: 139 additions & 6 deletions

File tree

docs/llms-full.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,15 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends.
553553

554554
| Format | Status | Evidence | Notes |
555555
|--------|--------|----------|-------|
556-
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (27 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
556+
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (28 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
557557
| OpenAPI JSON | tested | `tests/main/test_main.py::test_generate_from_json_input` | Covered by the JSON conversion CLI test in `tests/main/test_main.py`. |
558558
| Remote HTTP `$ref` targets | tested | `tests/main/test_main.py::test_generate_remote_ref` | Covered by the remote `$ref` generation test against a live HTTP server. |
559559

560560
## Fixture Suites
561561

562562
| Suite | Fixtures | Example files | Notes |
563563
|-------|----------|---------------|-------|
564-
| Default template | 19 | `body_and_parameters.yaml`, `content_in_parameters.yaml`, `content_in_parameters_inline.yaml` | Core single-file generation scenarios exercised by the main CLI tests. |
564+
| Default template | 20 | `body_and_parameters.yaml`, `content_in_parameters.yaml`, `content_in_parameters_inline.yaml` | Core single-file generation scenarios exercised by the main CLI tests. |
565565
| Coverage fixtures | 4 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. |
566566
| Custom template overrides | 1 | `custom_security.yaml` | Template override coverage for `--template-dir`. |
567567
| Timestamp suppression | 1 | `simple.yaml` | Fixtures that exercise `--disable-timestamp`. |

docs/supported_formats.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends.
77

88
| Format | Status | Evidence | Notes |
99
|--------|--------|----------|-------|
10-
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (27 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
10+
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (28 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
1111
| OpenAPI JSON | tested | `tests/main/test_main.py::test_generate_from_json_input` | Covered by the JSON conversion CLI test in `tests/main/test_main.py`. |
1212
| Remote HTTP `$ref` targets | tested | `tests/main/test_main.py::test_generate_remote_ref` | Covered by the remote `$ref` generation test against a live HTTP server. |
1313

1414
## Fixture Suites
1515

1616
| Suite | Fixtures | Example files | Notes |
1717
|-------|----------|---------------|-------|
18-
| Default template | 19 | `body_and_parameters.yaml`, `content_in_parameters.yaml`, `content_in_parameters_inline.yaml` | Core single-file generation scenarios exercised by the main CLI tests. |
18+
| Default template | 20 | `body_and_parameters.yaml`, `content_in_parameters.yaml`, `content_in_parameters_inline.yaml` | Core single-file generation scenarios exercised by the main CLI tests. |
1919
| Coverage fixtures | 4 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. |
2020
| Custom template overrides | 1 | `custom_security.yaml` | Template override coverage for `--template-dir`. |
2121
| Timestamp suppression | 1 | `simple.yaml` | Fixtures that exercise `--disable-timestamp`. |

fastapi_code_generator/prompt_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
'\n'
533533
'| Format | Status | Evidence | Notes |\n'
534534
'|--------|--------|----------|-------|\n'
535-
'| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (27 '
535+
'| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (28 '
536536
'fixtures) | Primary fixture format exercised under '
537537
'`tests/data/openapi/**/*.yaml`. |\n'
538538
'| OpenAPI JSON | tested | '
@@ -548,7 +548,7 @@
548548
'\n'
549549
'| Suite | Fixtures | Example files | Notes |\n'
550550
'|-------|----------|---------------|-------|\n'
551-
'| Default template | 19 | `body_and_parameters.yaml`, '
551+
'| Default template | 20 | `body_and_parameters.yaml`, '
552552
'`content_in_parameters.yaml`, '
553553
'`content_in_parameters_inline.yaml` | Core single-file '
554554
'generation scenarios exercised by the main CLI tests. |\n'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# generated by fastapi-codegen:
2+
# filename: query_array_parameter.yaml
3+
# timestamp: 2020-06-19T00:00:00+00:00
4+
5+
from __future__ import annotations
6+
7+
from typing import List, Optional, Union
8+
9+
from fastapi import FastAPI, Query
10+
11+
from .models import Error, Pet
12+
13+
app = FastAPI(
14+
version='1.0.0',
15+
title='Swagger Petstore',
16+
license={'name': 'MIT'},
17+
servers=[{'url': 'http://petstore.swagger.io/v1'}],
18+
)
19+
20+
21+
@app.get(
22+
'/pets',
23+
response_model=List[Pet],
24+
responses={'default': {'model': Error}},
25+
tags=['pets'],
26+
)
27+
def list_pets(
28+
limit: Optional[int] = None,
29+
pet_ids: Optional[List[int]] = Query(None, alias='petIds'),
30+
) -> Union[List[Pet], Error]:
31+
"""
32+
List all pets
33+
"""
34+
pass
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# generated by fastapi-codegen:
2+
# filename: query_array_parameter.yaml
3+
# timestamp: 2020-06-19T00:00:00+00:00
4+
5+
from __future__ import annotations
6+
7+
from typing import Optional
8+
9+
from pydantic import BaseModel
10+
11+
12+
class Pet(BaseModel):
13+
id: int
14+
name: str
15+
tag: Optional[str] = None
16+
17+
18+
class Error(BaseModel):
19+
code: int
20+
message: str
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
tags:
15+
- pets
16+
parameters:
17+
- name: limit
18+
in: query
19+
description: How many items to return at one time (max 100)
20+
required: false
21+
schema:
22+
type: integer
23+
format: int32
24+
- name: petIds
25+
in: query
26+
description: Filter pets by these pet IDs
27+
required: false
28+
schema:
29+
type: array
30+
items:
31+
type: integer
32+
format: int64
33+
responses:
34+
'200':
35+
description: A paged array of pets
36+
headers:
37+
x-next:
38+
description: A link to the next page of responses
39+
schema:
40+
type: string
41+
content:
42+
application/json:
43+
schema:
44+
$ref: "#/components/schemas/Pets"
45+
default:
46+
description: unexpected error
47+
content:
48+
application/json:
49+
schema:
50+
$ref: "#/components/schemas/Error"
51+
components:
52+
schemas:
53+
Pet:
54+
required:
55+
- id
56+
- name
57+
properties:
58+
id:
59+
type: integer
60+
format: int64
61+
name:
62+
type: string
63+
tag:
64+
type: string
65+
Pets:
66+
type: array
67+
description: list of pet
68+
items:
69+
$ref: "#/components/schemas/Pet"
70+
Error:
71+
required:
72+
- code
73+
- message
74+
properties:
75+
code:
76+
type: integer
77+
format: int32
78+
message:
79+
type: string

0 commit comments

Comments
 (0)