@team-supercharge/oasg 13.2.0-feature-python-fastapi-455451cf.0 → 13.2.0-feature-python-fastapi-0a55030b.0
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.
- package/README.md +1 -0
- package/package.json +1 -1
- package/targets/python-fastapi/templates/README.mustache +43 -0
- package/targets/python-fastapi/templates/api.mustache +62 -0
- package/targets/python-fastapi/templates/base_api.mustache +32 -0
- package/targets/python-fastapi/templates/endpoint_argument_definition.mustache +1 -0
- package/targets/python-fastapi/templates/pyproject_toml.mustache +1 -1
- package/targets/python-fastapi/templates/requirements.mustache +2 -0
package/README.md
CHANGED
@@ -674,6 +674,7 @@ Publishing the PyPI packages is done with Twine. For authentication againts the
|
|
674
674
|
| packageName | Package nem for the project (convention: snake_case) | Y | - |
|
675
675
|
| repositoryUrl | URL of the PyPI repository | Y | - |
|
676
676
|
|
677
|
+
Building the distribution package requires Flit.
|
677
678
|
Publishing the PyPI packages is done with Twine. For authentication againts the PiPI repository you need to set the `TWINE_USERNAME` and `TWINE_PASSWORD` environment variables.
|
678
679
|
|
679
680
|
#### `contract-testing`
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@team-supercharge/oasg",
|
3
|
-
"version": "13.2.0-feature-python-fastapi-
|
3
|
+
"version": "13.2.0-feature-python-fastapi-0a55030b.0",
|
4
4
|
"description": "Node-based tool to lint OpenAPI documents and generate clients, servers and documentation from them",
|
5
5
|
"author": "Supercharge",
|
6
6
|
"license": "MIT",
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# OpenAPI generated FastAPI server
|
2
|
+
|
3
|
+
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
4
|
+
|
5
|
+
- API version: {{appVersion}}
|
6
|
+
{{^hideGenerationTimestamp}}
|
7
|
+
- Build date: {{generatedDate}}
|
8
|
+
{{/hideGenerationTimestamp}}
|
9
|
+
- Build package: {{generatorClass}}
|
10
|
+
|
11
|
+
## Requirements.
|
12
|
+
|
13
|
+
Python >= {{{generatorLanguageVersion}}}
|
14
|
+
|
15
|
+
## Installation & Usage
|
16
|
+
|
17
|
+
To run the server, please execute the following from the root directory:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
pip3 install -r requirements.txt
|
21
|
+
pip3 install uvicorn
|
22
|
+
uvicorn --app-dir src {{packageName}}.main:app --host 0.0.0.0 --port {{serverPort}}
|
23
|
+
```
|
24
|
+
|
25
|
+
and open your browser at `http://localhost:{{serverPort}}/docs/` to see the docs.
|
26
|
+
|
27
|
+
## Running with Docker
|
28
|
+
|
29
|
+
To run the server on a Docker container, please execute the following from the root directory:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
docker-compose up --build
|
33
|
+
```
|
34
|
+
|
35
|
+
## Tests
|
36
|
+
|
37
|
+
To run the tests:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
pip3 install pytest
|
41
|
+
pip3 install httpx
|
42
|
+
PYTHONPATH=src pytest tests
|
43
|
+
```
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
from typing import Dict, List # noqa: F401
|
4
|
+
import importlib
|
5
|
+
import pkgutil
|
6
|
+
|
7
|
+
from {{apiPackage}}.{{classFilename}}_{{baseSuffix}} import Base{{classname}}
|
8
|
+
|
9
|
+
from fastapi import ( # noqa: F401
|
10
|
+
APIRouter,
|
11
|
+
Body,
|
12
|
+
Cookie,
|
13
|
+
Depends,
|
14
|
+
Form,
|
15
|
+
Header,
|
16
|
+
Path,
|
17
|
+
Query,
|
18
|
+
Request,
|
19
|
+
Response,
|
20
|
+
Security,
|
21
|
+
status,
|
22
|
+
)
|
23
|
+
|
24
|
+
from {{modelPackage}}.extra_models import TokenModel # noqa: F401
|
25
|
+
{{#imports}}
|
26
|
+
{{import}}
|
27
|
+
{{/imports}}
|
28
|
+
|
29
|
+
router = APIRouter()
|
30
|
+
|
31
|
+
{{#operations}}
|
32
|
+
{{#operation}}
|
33
|
+
@router.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(
|
34
|
+
"{{path}}",
|
35
|
+
responses={
|
36
|
+
{{#responses}}
|
37
|
+
{{code}}: {{=<% %>=}}{<%#dataType%>"model": <%dataType%>, "description": "<%message%>"<%/dataType%><%^dataType%>"description": "<%message%>"<%/dataType%>}<%={{ }}=%>,
|
38
|
+
{{/responses}}
|
39
|
+
},
|
40
|
+
tags=[{{#tags}}"{{name}}"{{^-last}},{{/-last}}{{/tags}}],
|
41
|
+
{{#summary}}
|
42
|
+
summary="{{.}}",
|
43
|
+
{{/summary}}
|
44
|
+
{{#description}}
|
45
|
+
description = "{{.}}",
|
46
|
+
{{/description}}
|
47
|
+
response_model_by_alias=True,
|
48
|
+
)
|
49
|
+
async def {{operationId}}(
|
50
|
+
request: Request,
|
51
|
+
{{#allParams}}
|
52
|
+
{{>endpoint_argument_definition}},
|
53
|
+
{{/allParams}}
|
54
|
+
) -> Response: # -> {{returnType}}{{^returnType}}None{{/returnType}}
|
55
|
+
{{#notes}}"""{{.}}"""
|
56
|
+
return await Base{{classname}}.subclasses[0]().{{operationId}}(request{{#allParams}}, {{>impl_argument}}{{/allParams}}){{/notes}}{{^notes}}...{{/notes}}
|
57
|
+
{{^-last}}
|
58
|
+
|
59
|
+
|
60
|
+
{{/-last}}
|
61
|
+
{{/operation}}
|
62
|
+
{{/operations}}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
from typing import ClassVar, Dict, List, Tuple # noqa: F401
|
4
|
+
from fastapi import Request, Response
|
5
|
+
|
6
|
+
{{#imports}}
|
7
|
+
{{import}}
|
8
|
+
{{/imports}}
|
9
|
+
|
10
|
+
class Base{{classname}}:
|
11
|
+
subclasses: ClassVar[Tuple] = ()
|
12
|
+
|
13
|
+
def __init_subclass__(cls, **kwargs):
|
14
|
+
super().__init_subclass__(**kwargs)
|
15
|
+
Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,)
|
16
|
+
|
17
|
+
{{#operations}}
|
18
|
+
{{#operation}}
|
19
|
+
async def {{operationId}}(
|
20
|
+
self,
|
21
|
+
request: Request,
|
22
|
+
{{#allParams}}
|
23
|
+
{{>impl_argument_definition}},
|
24
|
+
{{/allParams}}
|
25
|
+
) -> Response: # -> {{returnType}}{{^returnType}}None{{/returnType}}
|
26
|
+
{{#notes}}"""{{.}}"""
|
27
|
+
...{{/notes}}{{^notes}}...{{/notes}}
|
28
|
+
{{^-last}}
|
29
|
+
|
30
|
+
{{/-last}}
|
31
|
+
{{/operation}}
|
32
|
+
{{/operations}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{{#isPathParam}}{{baseName}}{{/isPathParam}}{{^isPathParam}}{{paramName}}{{/isPathParam}}: {{>param_type}} = {{#isPathParam}}Path{{/isPathParam}}{{#isHeaderParam}}Header{{/isHeaderParam}}{{#isFormParam}}Form{{/isFormParam}}{{#isQueryParam}}Query{{/isQueryParam}}{{#isCookieParam}}Cookie{{/isCookieParam}}{{#isBodyParam}}Body{{/isBodyParam}}({{&defaultValue}}{{^defaultValue}}{{#isPathParam}}...{{/isPathParam}}{{^isPathParam}}None{{/isPathParam}}{{/defaultValue}}, description="{{description}}"{{#isQueryParam}}, alias="{{baseName}}"{{/isQueryParam}}{{#isLong}}{{#minimum}}, ge={{.}}{{/minimum}}{{#maximum}}, le={{.}}{{/maximum}}{{/isLong}}{{#isInteger}}{{#minimum}}, ge={{.}}{{/minimum}}{{#maximum}}, le={{.}}{{/maximum}}{{/isInteger}}{{#pattern}}, regex=r"{{.}}"{{/pattern}}{{#minLength}}, min_length={{.}}{{/minLength}}{{#maxLength}}, max_length={{.}}{{/maxLength}})
|