fastapi_swagger2 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/PKG-INFO +22 -3
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/README.md +20 -1
- fastapi_swagger2-0.2.4/setup.cfg +3 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/src/fastapi_swagger2/__init__.py +2 -2
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/src/fastapi_swagger2/utils.py +15 -16
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/.gitignore +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/LICENSE +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/pyproject.toml +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/requirements-dev.txt +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/requirements.txt +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/scripts/build.sh +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/scripts/clean.sh +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/scripts/format.sh +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/scripts/lint.sh +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/scripts/publish.sh +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/scripts/test.sh +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/src/fastapi_swagger2/constants.py +0 -0
- {fastapi_swagger2-0.2.3 → fastapi_swagger2-0.2.4}/src/fastapi_swagger2/models.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: fastapi_swagger2
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Swagger2 support for FastAPI framework
|
|
5
5
|
Project-URL: Homepage, https://github.com/virajkanwade/fastapi_swagger2
|
|
6
6
|
Project-URL: Documentation, https://github.com/virajkanwade/fastapi_swagger2
|
|
@@ -94,7 +94,7 @@ Python 3.8+
|
|
|
94
94
|
|
|
95
95
|
* 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
|
|
96
96
|
* 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
|
|
97
|
-
* 0.2.
|
|
97
|
+
* 0.2.4 - FastAPI >= 0.100.0
|
|
98
98
|
|
|
99
99
|
## Installation
|
|
100
100
|
|
|
@@ -133,6 +133,25 @@ This adds following endpoints:
|
|
|
133
133
|
* http://localhost:8000/swagger2/docs
|
|
134
134
|
* http://localhost:8000/swagger2/redoc
|
|
135
135
|
|
|
136
|
+
## Generate spec for CI/CD
|
|
137
|
+
|
|
138
|
+
```Python
|
|
139
|
+
import os
|
|
140
|
+
|
|
141
|
+
import yaml
|
|
142
|
+
|
|
143
|
+
from app.main import app
|
|
144
|
+
|
|
145
|
+
URL = os.environ["CLOUD_RUN_URL"]
|
|
146
|
+
|
|
147
|
+
app.servers.append(URL)
|
|
148
|
+
|
|
149
|
+
spec = app.swagger2()
|
|
150
|
+
spec['x-google-backend'] = {'address': URL}
|
|
151
|
+
|
|
152
|
+
print(yaml.dump(spec))
|
|
153
|
+
```
|
|
154
|
+
|
|
136
155
|
## Development
|
|
137
156
|
|
|
138
157
|
```console
|
|
@@ -25,7 +25,7 @@ Python 3.8+
|
|
|
25
25
|
|
|
26
26
|
* 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
|
|
27
27
|
* 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
|
|
28
|
-
* 0.2.
|
|
28
|
+
* 0.2.4 - FastAPI >= 0.100.0
|
|
29
29
|
|
|
30
30
|
## Installation
|
|
31
31
|
|
|
@@ -64,6 +64,25 @@ This adds following endpoints:
|
|
|
64
64
|
* http://localhost:8000/swagger2/docs
|
|
65
65
|
* http://localhost:8000/swagger2/redoc
|
|
66
66
|
|
|
67
|
+
## Generate spec for CI/CD
|
|
68
|
+
|
|
69
|
+
```Python
|
|
70
|
+
import os
|
|
71
|
+
|
|
72
|
+
import yaml
|
|
73
|
+
|
|
74
|
+
from app.main import app
|
|
75
|
+
|
|
76
|
+
URL = os.environ["CLOUD_RUN_URL"]
|
|
77
|
+
|
|
78
|
+
app.servers.append(URL)
|
|
79
|
+
|
|
80
|
+
spec = app.swagger2()
|
|
81
|
+
spec['x-google-backend'] = {'address': URL}
|
|
82
|
+
|
|
83
|
+
print(yaml.dump(spec))
|
|
84
|
+
```
|
|
85
|
+
|
|
67
86
|
## Development
|
|
68
87
|
|
|
69
88
|
```console
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = "0.2.
|
|
1
|
+
__version__ = "0.2.4"
|
|
2
2
|
|
|
3
3
|
from typing import Any, Dict, List, Optional, TypeVar
|
|
4
4
|
|
|
@@ -139,7 +139,7 @@ class FastAPISwagger2:
|
|
|
139
139
|
contact=self.app.contact,
|
|
140
140
|
license_info=self.app.license_info,
|
|
141
141
|
routes=self.app.routes,
|
|
142
|
-
tags=self.app.
|
|
142
|
+
tags=self.app.openapi_tags,
|
|
143
143
|
)
|
|
144
144
|
|
|
145
145
|
return self.app.swagger2_schema
|
|
@@ -64,15 +64,17 @@ validation_error_response_definition = {
|
|
|
64
64
|
},
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
FieldMapping = Dict[
|
|
68
|
+
Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
|
|
69
|
+
]
|
|
70
|
+
|
|
67
71
|
|
|
68
72
|
# def get_schema_from_model_field(
|
|
69
73
|
# *,
|
|
70
74
|
# field: ModelField,
|
|
71
75
|
# schema_generator: GenerateJsonSchema,
|
|
72
76
|
# model_name_map: ModelNameMap,
|
|
73
|
-
# field_mapping:
|
|
74
|
-
# Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
|
|
75
|
-
# ],
|
|
77
|
+
# field_mapping: FieldMapping,
|
|
76
78
|
# ) -> Dict[str, Any]:
|
|
77
79
|
# # This expects that GenerateJsonSchema was already used to generate the definitions
|
|
78
80
|
# json_schema = field_mapping[(field, field.mode)]
|
|
@@ -110,6 +112,7 @@ def get_swagger2_security_definitions(
|
|
|
110
112
|
security_definitions = {}
|
|
111
113
|
operation_security = []
|
|
112
114
|
for security_requirement in flat_dependant.security_requirements:
|
|
115
|
+
skip: bool = False
|
|
113
116
|
# fastapi.security.* which gets model from fastapi.openapi.models
|
|
114
117
|
security_definition = jsonable_encoder(
|
|
115
118
|
security_requirement.security_scheme.model,
|
|
@@ -120,13 +123,13 @@ def get_swagger2_security_definitions(
|
|
|
120
123
|
if security_definition.get("scheme", "basic") == "basic":
|
|
121
124
|
security_definition = {"type": "basic"}
|
|
122
125
|
else:
|
|
126
|
+
skip = True
|
|
123
127
|
logger.warning(
|
|
124
128
|
f"fastapi_swagger2: Unable to handle security_definition: {security_definition}"
|
|
125
129
|
)
|
|
126
130
|
elif security_definition["type"] == "apiKey":
|
|
127
131
|
pass
|
|
128
132
|
elif security_definition["type"] == "oauth2":
|
|
129
|
-
_security_definition = security_definition
|
|
130
133
|
flows = security_definition["flows"]
|
|
131
134
|
flows_keys = list(flows.keys())
|
|
132
135
|
if len(flows_keys) >= 1:
|
|
@@ -148,12 +151,14 @@ def get_swagger2_security_definitions(
|
|
|
148
151
|
{_security_name: security_requirement.scopes}
|
|
149
152
|
)
|
|
150
153
|
else:
|
|
154
|
+
skip = True
|
|
151
155
|
logger.warning(
|
|
152
156
|
f"fastapi_swagger2: Unable to handle security_definition: {security_definition}"
|
|
153
157
|
)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
if not skip:
|
|
159
|
+
security_name = security_requirement.security_scheme.scheme_name
|
|
160
|
+
security_definitions[security_name] = security_definition
|
|
161
|
+
operation_security.append({security_name: security_requirement.scopes})
|
|
157
162
|
return security_definitions, operation_security
|
|
158
163
|
|
|
159
164
|
|
|
@@ -162,9 +167,7 @@ def get_swagger2_operation_parameters(
|
|
|
162
167
|
all_route_params: Sequence[ModelField],
|
|
163
168
|
schema_generator: GenerateJsonSchema,
|
|
164
169
|
model_name_map: ModelNameMap,
|
|
165
|
-
field_mapping:
|
|
166
|
-
Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
|
|
167
|
-
],
|
|
170
|
+
field_mapping: FieldMapping,
|
|
168
171
|
) -> List[Dict[str, Any]]:
|
|
169
172
|
parameters = []
|
|
170
173
|
for param in all_route_params:
|
|
@@ -203,9 +206,7 @@ def get_swagger2_operation_request_body(
|
|
|
203
206
|
body_field: Optional[ModelField],
|
|
204
207
|
schema_generator: GenerateJsonSchema,
|
|
205
208
|
model_name_map: ModelNameMap,
|
|
206
|
-
field_mapping:
|
|
207
|
-
Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
|
|
208
|
-
],
|
|
209
|
+
field_mapping: FieldMapping,
|
|
209
210
|
) -> Optional[Dict[str, Any]]:
|
|
210
211
|
if not body_field:
|
|
211
212
|
return None
|
|
@@ -239,9 +240,7 @@ def get_swagger2_path(
|
|
|
239
240
|
operation_ids: Set[str],
|
|
240
241
|
schema_generator: GenerateJsonSchema,
|
|
241
242
|
model_name_map: ModelNameMap,
|
|
242
|
-
field_mapping:
|
|
243
|
-
Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
|
|
244
|
-
],
|
|
243
|
+
field_mapping: FieldMapping,
|
|
245
244
|
) -> Tuple[Dict[str, Any], Dict[str, Any], Dict[str, Any]]:
|
|
246
245
|
path: Dict[str, Any] = {}
|
|
247
246
|
security_schemes: Dict[str, Any] = {}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|