oapi-gen 0.1.2__tar.gz → 0.1.3__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.
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/PKG-INFO +25 -5
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/README.md +24 -4
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/operations.py +9 -1
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/responses.py +9 -3
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/contracts.py +15 -3
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/router.py +14 -1
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen.egg-info/PKG-INFO +25 -5
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/pyproject.toml +1 -1
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/contracts.py.txt +84 -84
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/router.py.txt +128 -12
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/contracts.py.txt +6 -6
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/router.py.txt +14 -2
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_multipart.py +12 -1
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_parser.py +12 -1
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_responses.py +106 -12
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_router.py +1 -1
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/MANIFEST.in +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/__init__.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/__main__.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/_version.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/errors.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/formatter.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/generator.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/ir.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/main.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/models.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/naming.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/__init__.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/bodies.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/document.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/parameters.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/references.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/schemas.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/security.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/serialization.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/parser/values.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/__init__.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/inspection.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/package.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/runtime.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/security.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen/render/writer.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen.egg-info/SOURCES.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen.egg-info/dependency_links.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen.egg-info/entry_points.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen.egg-info/requires.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/packages/oapi_gen.egg-info/top_level.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/setup.cfg +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/__init__.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/conftest.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/fixtures/advanced.openapi.yaml +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/fixtures/cats.openapi.yaml +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/fixtures/security.openapi.yaml +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/README.md +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/.oapi-gen-manifest.json.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/__init__.py.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/_runtime.py.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/models.py.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/advanced/openapi.json.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/.oapi-gen-manifest.json.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/__init__.py.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/_runtime.py.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/models.py.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/snapshots/cats/openapi.json.txt +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/support.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_generator.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_imports.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_parameters.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_schemas.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_security.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_snapshots.py +0 -0
- {oapi_gen-0.1.2 → oapi_gen-0.1.3}/tests/test_starlette.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: oapi-gen
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Strict OpenAPI-first server contract generator for Starlette and msgspec
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -125,12 +125,27 @@ adds `@inject` and `FromDishka[T]` injection to handler methods using the native
|
|
|
125
125
|
Starlette request scope.
|
|
126
126
|
|
|
127
127
|
Each operation has a namespace in `contracts`: `Login.Request` is its request
|
|
128
|
-
envelope, `Login.Ok` and `Login.Unauthorized`
|
|
129
|
-
|
|
128
|
+
envelope, `Login.Ok` is a response variant, and `Login.Unauthorized` is an exception.
|
|
129
|
+
Return responses below 400 and raise declared 4xx/5xx errors:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
async def login(self, request: contracts.Login.Request) -> contracts.Login.Response:
|
|
133
|
+
if not accepted:
|
|
134
|
+
raise contracts.Login.Unauthorized(body="Invalid credentials")
|
|
135
|
+
return contracts.Login.Ok(body=session)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`Login.Response` includes only the returnable variants (`Ok` in this example).
|
|
139
|
+
For an operation with only error statuses, `Response` is `typing.Never`.
|
|
140
|
+
Status names follow HTTP names such as
|
|
130
141
|
`Ok` (200), `Created` (201), `NoContent` (204), `NotFound` (404), and
|
|
131
142
|
`UnprocessableEntity` (422). Custom statuses use names such as `Status499`.
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
The router catches only error variants declared for that operation, including when
|
|
144
|
+
raised by a nested service call. Other exceptions propagate normally. Error bodies
|
|
145
|
+
and headers use the same serialization and validation as returned responses.
|
|
146
|
+
Returning an error instead of raising it, or returning an undeclared variant such
|
|
147
|
+
as another operation's `Ok`, raises `TypeError`. Declared response headers remain
|
|
148
|
+
typed fields on each variant:
|
|
134
149
|
|
|
135
150
|
```python
|
|
136
151
|
return contracts.CreateUpload.Created(
|
|
@@ -139,8 +154,13 @@ return contracts.CreateUpload.Created(
|
|
|
139
154
|
)
|
|
140
155
|
```
|
|
141
156
|
|
|
157
|
+
Header fields that collide with `body` or exception attributes receive a `_header`
|
|
158
|
+
suffix, for example the `Args` header on an error becomes `args_header`.
|
|
159
|
+
|
|
142
160
|
When migrating generated handlers, replace `LoginRequest` with `Login.Request`,
|
|
143
161
|
`LoginResponse` with `Login.Response`, and `LoginResponse200` with `Login.Ok`.
|
|
162
|
+
Replace `return Login.Unauthorized(...)` (and other 4xx/5xx variants) with
|
|
163
|
+
`raise Login.Unauthorized(...)`.
|
|
144
164
|
Regenerate the package and update all callers together.
|
|
145
165
|
Operation names that collide with contract infrastructure receive an `Operation`
|
|
146
166
|
suffix, for example `handlers` becomes `HandlersOperation` because `Handlers`
|
|
@@ -112,12 +112,27 @@ adds `@inject` and `FromDishka[T]` injection to handler methods using the native
|
|
|
112
112
|
Starlette request scope.
|
|
113
113
|
|
|
114
114
|
Each operation has a namespace in `contracts`: `Login.Request` is its request
|
|
115
|
-
envelope, `Login.Ok` and `Login.Unauthorized`
|
|
116
|
-
|
|
115
|
+
envelope, `Login.Ok` is a response variant, and `Login.Unauthorized` is an exception.
|
|
116
|
+
Return responses below 400 and raise declared 4xx/5xx errors:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
async def login(self, request: contracts.Login.Request) -> contracts.Login.Response:
|
|
120
|
+
if not accepted:
|
|
121
|
+
raise contracts.Login.Unauthorized(body="Invalid credentials")
|
|
122
|
+
return contracts.Login.Ok(body=session)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`Login.Response` includes only the returnable variants (`Ok` in this example).
|
|
126
|
+
For an operation with only error statuses, `Response` is `typing.Never`.
|
|
127
|
+
Status names follow HTTP names such as
|
|
117
128
|
`Ok` (200), `Created` (201), `NoContent` (204), `NotFound` (404), and
|
|
118
129
|
`UnprocessableEntity` (422). Custom statuses use names such as `Status499`.
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
The router catches only error variants declared for that operation, including when
|
|
131
|
+
raised by a nested service call. Other exceptions propagate normally. Error bodies
|
|
132
|
+
and headers use the same serialization and validation as returned responses.
|
|
133
|
+
Returning an error instead of raising it, or returning an undeclared variant such
|
|
134
|
+
as another operation's `Ok`, raises `TypeError`. Declared response headers remain
|
|
135
|
+
typed fields on each variant:
|
|
121
136
|
|
|
122
137
|
```python
|
|
123
138
|
return contracts.CreateUpload.Created(
|
|
@@ -126,8 +141,13 @@ return contracts.CreateUpload.Created(
|
|
|
126
141
|
)
|
|
127
142
|
```
|
|
128
143
|
|
|
144
|
+
Header fields that collide with `body` or exception attributes receive a `_header`
|
|
145
|
+
suffix, for example the `Args` header on an error becomes `args_header`.
|
|
146
|
+
|
|
129
147
|
When migrating generated handlers, replace `LoginRequest` with `Login.Request`,
|
|
130
148
|
`LoginResponse` with `Login.Response`, and `LoginResponse200` with `Login.Ok`.
|
|
149
|
+
Replace `return Login.Unauthorized(...)` (and other 4xx/5xx variants) with
|
|
150
|
+
`raise Login.Unauthorized(...)`.
|
|
131
151
|
Regenerate the package and update all callers together.
|
|
132
152
|
Operation names that collide with contract infrastructure receive an `Operation`
|
|
133
153
|
suffix, for example `handlers` becomes `HandlersOperation` because `Handlers`
|
|
@@ -124,7 +124,15 @@ def validate_operation_names(operations: list[Operation]) -> None:
|
|
|
124
124
|
def assign_operation_names(
|
|
125
125
|
operations: list[Operation], security_schemes: tuple[SecurityScheme, ...]
|
|
126
126
|
) -> list[Operation]:
|
|
127
|
-
reserved = {
|
|
127
|
+
reserved = {
|
|
128
|
+
"Exception",
|
|
129
|
+
"Handlers",
|
|
130
|
+
"MultipartFile",
|
|
131
|
+
"Never",
|
|
132
|
+
"SecurityHandler",
|
|
133
|
+
"SecurityRejected",
|
|
134
|
+
"Protocol",
|
|
135
|
+
}
|
|
128
136
|
reserved.update(operation.group_class_name for operation in operations)
|
|
129
137
|
reserved.update(scheme.class_name for scheme in security_schemes)
|
|
130
138
|
reserved.update(
|
|
@@ -38,7 +38,11 @@ def parse_responses(
|
|
|
38
38
|
status_code = int(status_text)
|
|
39
39
|
raw = resolver.resolve_object(value, f"{context}.responses.{status_text}")
|
|
40
40
|
headers = _parse_response_headers(
|
|
41
|
-
resolver,
|
|
41
|
+
resolver,
|
|
42
|
+
schemas,
|
|
43
|
+
raw.get("headers", {}),
|
|
44
|
+
f"{context}.responses.{status_text}.headers",
|
|
45
|
+
is_error=status_code >= 400,
|
|
42
46
|
)
|
|
43
47
|
description = required_string(raw, "description", f"{context}.responses.{status_text}")
|
|
44
48
|
content = object_value(raw.get("content", {}), f"{context}.responses.{status_text}.content")
|
|
@@ -95,6 +99,8 @@ def _parse_response_headers(
|
|
|
95
99
|
schemas: SchemaParser,
|
|
96
100
|
value: object,
|
|
97
101
|
context: str,
|
|
102
|
+
*,
|
|
103
|
+
is_error: bool,
|
|
98
104
|
) -> tuple[ResponseHeader, ...]:
|
|
99
105
|
raw_headers = object_value(value, context)
|
|
100
106
|
normalized_names: set[str] = set()
|
|
@@ -123,8 +129,8 @@ def _parse_response_headers(
|
|
|
123
129
|
python_name = snake_case(wire_name)
|
|
124
130
|
except ValueError as error:
|
|
125
131
|
raise GenerationError(f"{header_context}: invalid header name") from error
|
|
126
|
-
if python_name == "body":
|
|
127
|
-
python_name
|
|
132
|
+
if python_name == "body" or (is_error and hasattr(Exception, python_name)):
|
|
133
|
+
python_name += "_header"
|
|
128
134
|
headers.append(
|
|
129
135
|
ResponseHeader(
|
|
130
136
|
wire_name=wire_name,
|
|
@@ -123,8 +123,13 @@ def render_contracts(spec: ApiSpec) -> str:
|
|
|
123
123
|
for response in operation.responses:
|
|
124
124
|
writer.line()
|
|
125
125
|
writer.line()
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
if response.status_code >= 400:
|
|
127
|
+
# Exceptions need writable traceback attributes for context managers.
|
|
128
|
+
writer.line("@dataclass(slots=True)")
|
|
129
|
+
writer.line(f"class {response.class_name}(Exception):")
|
|
130
|
+
else:
|
|
131
|
+
writer.line("@dataclass(frozen=True, slots=True)")
|
|
132
|
+
writer.line(f"class {response.class_name}:")
|
|
128
133
|
render_docstring(writer, response.description, response.headers)
|
|
129
134
|
if response.type_ref is None and not response.headers:
|
|
130
135
|
writer.line("pass", indent=1)
|
|
@@ -144,7 +149,14 @@ def render_contracts(spec: ApiSpec) -> str:
|
|
|
144
149
|
indent=1,
|
|
145
150
|
)
|
|
146
151
|
|
|
147
|
-
union = " | ".join(
|
|
152
|
+
union = " | ".join(
|
|
153
|
+
response.class_name
|
|
154
|
+
for response in operation.responses
|
|
155
|
+
if response.status_code < 400
|
|
156
|
+
)
|
|
157
|
+
if not union:
|
|
158
|
+
writer.require("typing", "Never")
|
|
159
|
+
union = "Never"
|
|
148
160
|
writer.line()
|
|
149
161
|
writer.line(f"type Response = {union}")
|
|
150
162
|
|
|
@@ -197,11 +197,24 @@ def render_endpoint(w: Writer, op: Operation, checked: bool) -> None:
|
|
|
197
197
|
fields.append(("security_context", "__oapi_security_context"))
|
|
198
198
|
arguments = ", ".join(f"{name}={value}" for name, value in fields)
|
|
199
199
|
w.line(f"__oapi_request = _contracts.{op.class_name}.Request({arguments})", 2)
|
|
200
|
+
errors = ", ".join(
|
|
201
|
+
f"_contracts.{op.class_name}.{response.class_name}"
|
|
202
|
+
for response in op.responses
|
|
203
|
+
if response.status_code >= 400
|
|
204
|
+
)
|
|
205
|
+
if errors:
|
|
206
|
+
w.line("try:", 2)
|
|
200
207
|
w.line(
|
|
201
208
|
f"__oapi_result = await __oapi_handlers.{op.group_field_name}."
|
|
202
209
|
f"{op.python_name}(__oapi_request)",
|
|
203
|
-
2,
|
|
210
|
+
3 if errors else 2,
|
|
204
211
|
)
|
|
212
|
+
if errors:
|
|
213
|
+
w.line(f"except ({errors}) as __oapi_error:", 2)
|
|
214
|
+
w.line("__oapi_result = __oapi_error", 3)
|
|
215
|
+
w.line("else:", 2)
|
|
216
|
+
w.line("if isinstance(__oapi_result, Exception):", 3)
|
|
217
|
+
w.line(f"raise TypeError({op.operation_id + ' error responses must be raised'!r})", 4)
|
|
205
218
|
for response in op.responses:
|
|
206
219
|
w.line(
|
|
207
220
|
f"if isinstance(__oapi_result, _contracts.{op.class_name}.{response.class_name}):", 2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: oapi-gen
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Strict OpenAPI-first server contract generator for Starlette and msgspec
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -125,12 +125,27 @@ adds `@inject` and `FromDishka[T]` injection to handler methods using the native
|
|
|
125
125
|
Starlette request scope.
|
|
126
126
|
|
|
127
127
|
Each operation has a namespace in `contracts`: `Login.Request` is its request
|
|
128
|
-
envelope, `Login.Ok` and `Login.Unauthorized`
|
|
129
|
-
|
|
128
|
+
envelope, `Login.Ok` is a response variant, and `Login.Unauthorized` is an exception.
|
|
129
|
+
Return responses below 400 and raise declared 4xx/5xx errors:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
async def login(self, request: contracts.Login.Request) -> contracts.Login.Response:
|
|
133
|
+
if not accepted:
|
|
134
|
+
raise contracts.Login.Unauthorized(body="Invalid credentials")
|
|
135
|
+
return contracts.Login.Ok(body=session)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`Login.Response` includes only the returnable variants (`Ok` in this example).
|
|
139
|
+
For an operation with only error statuses, `Response` is `typing.Never`.
|
|
140
|
+
Status names follow HTTP names such as
|
|
130
141
|
`Ok` (200), `Created` (201), `NoContent` (204), `NotFound` (404), and
|
|
131
142
|
`UnprocessableEntity` (422). Custom statuses use names such as `Status499`.
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
The router catches only error variants declared for that operation, including when
|
|
144
|
+
raised by a nested service call. Other exceptions propagate normally. Error bodies
|
|
145
|
+
and headers use the same serialization and validation as returned responses.
|
|
146
|
+
Returning an error instead of raising it, or returning an undeclared variant such
|
|
147
|
+
as another operation's `Ok`, raises `TypeError`. Declared response headers remain
|
|
148
|
+
typed fields on each variant:
|
|
134
149
|
|
|
135
150
|
```python
|
|
136
151
|
return contracts.CreateUpload.Created(
|
|
@@ -139,8 +154,13 @@ return contracts.CreateUpload.Created(
|
|
|
139
154
|
)
|
|
140
155
|
```
|
|
141
156
|
|
|
157
|
+
Header fields that collide with `body` or exception attributes receive a `_header`
|
|
158
|
+
suffix, for example the `Args` header on an error becomes `args_header`.
|
|
159
|
+
|
|
142
160
|
When migrating generated handlers, replace `LoginRequest` with `Login.Request`,
|
|
143
161
|
`LoginResponse` with `Login.Response`, and `LoginResponse200` with `Login.Ok`.
|
|
162
|
+
Replace `return Login.Unauthorized(...)` (and other 4xx/5xx variants) with
|
|
163
|
+
`raise Login.Unauthorized(...)`.
|
|
144
164
|
Regenerate the package and update all callers together.
|
|
145
165
|
Operation names that collide with contract infrastructure receive an `Operation`
|
|
146
166
|
suffix, for example `handlers` becomes `HandlersOperation` because `Handlers`
|
|
@@ -41,31 +41,31 @@ class Login:
|
|
|
41
41
|
body: _models.AuthSuccessResponse
|
|
42
42
|
set_cookie: str | None = None
|
|
43
43
|
|
|
44
|
-
@dataclass(
|
|
45
|
-
class BadRequest:
|
|
44
|
+
@dataclass(slots=True)
|
|
45
|
+
class BadRequest(Exception):
|
|
46
46
|
"Некорректный запрос"
|
|
47
47
|
|
|
48
48
|
pass
|
|
49
49
|
|
|
50
|
-
@dataclass(
|
|
51
|
-
class Unauthorized:
|
|
50
|
+
@dataclass(slots=True)
|
|
51
|
+
class Unauthorized(Exception):
|
|
52
52
|
"Неверный email или пароль"
|
|
53
53
|
|
|
54
54
|
pass
|
|
55
55
|
|
|
56
|
-
@dataclass(
|
|
57
|
-
class Forbidden:
|
|
56
|
+
@dataclass(slots=True)
|
|
57
|
+
class Forbidden(Exception):
|
|
58
58
|
"Пользователь заблокирован"
|
|
59
59
|
|
|
60
60
|
pass
|
|
61
61
|
|
|
62
|
-
@dataclass(
|
|
63
|
-
class UnprocessableEntity:
|
|
62
|
+
@dataclass(slots=True)
|
|
63
|
+
class UnprocessableEntity(Exception):
|
|
64
64
|
"Validation Error"
|
|
65
65
|
|
|
66
66
|
body: _models.HttpValidationError
|
|
67
67
|
|
|
68
|
-
type Response = Ok
|
|
68
|
+
type Response = Ok
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
class Logout:
|
|
@@ -82,13 +82,13 @@ class Logout:
|
|
|
82
82
|
body: _models.MessageResponse
|
|
83
83
|
set_cookie: str | None = None
|
|
84
84
|
|
|
85
|
-
@dataclass(
|
|
86
|
-
class UnprocessableEntity:
|
|
85
|
+
@dataclass(slots=True)
|
|
86
|
+
class UnprocessableEntity(Exception):
|
|
87
87
|
"Validation Error"
|
|
88
88
|
|
|
89
89
|
body: _models.HttpValidationError
|
|
90
90
|
|
|
91
|
-
type Response = Ok
|
|
91
|
+
type Response = Ok
|
|
92
92
|
|
|
93
93
|
|
|
94
94
|
class GetCurrentUser:
|
|
@@ -104,19 +104,19 @@ class GetCurrentUser:
|
|
|
104
104
|
|
|
105
105
|
body: _models.UserItem
|
|
106
106
|
|
|
107
|
-
@dataclass(
|
|
108
|
-
class Unauthorized:
|
|
107
|
+
@dataclass(slots=True)
|
|
108
|
+
class Unauthorized(Exception):
|
|
109
109
|
"Не авторизован"
|
|
110
110
|
|
|
111
111
|
pass
|
|
112
112
|
|
|
113
|
-
@dataclass(
|
|
114
|
-
class UnprocessableEntity:
|
|
113
|
+
@dataclass(slots=True)
|
|
114
|
+
class UnprocessableEntity(Exception):
|
|
115
115
|
"Validation Error"
|
|
116
116
|
|
|
117
117
|
body: _models.HttpValidationError
|
|
118
118
|
|
|
119
|
-
type Response = Ok
|
|
119
|
+
type Response = Ok
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
class UpdatePassword:
|
|
@@ -134,25 +134,25 @@ class UpdatePassword:
|
|
|
134
134
|
body: _models.AuthSuccessResponse
|
|
135
135
|
set_cookie: str | None = None
|
|
136
136
|
|
|
137
|
-
@dataclass(
|
|
138
|
-
class BadRequest:
|
|
137
|
+
@dataclass(slots=True)
|
|
138
|
+
class BadRequest(Exception):
|
|
139
139
|
"Некорректный запрос"
|
|
140
140
|
|
|
141
141
|
pass
|
|
142
142
|
|
|
143
|
-
@dataclass(
|
|
144
|
-
class Unauthorized:
|
|
143
|
+
@dataclass(slots=True)
|
|
144
|
+
class Unauthorized(Exception):
|
|
145
145
|
"JWT отсутствует или невалиден"
|
|
146
146
|
|
|
147
147
|
pass
|
|
148
148
|
|
|
149
|
-
@dataclass(
|
|
150
|
-
class UnprocessableEntity:
|
|
149
|
+
@dataclass(slots=True)
|
|
150
|
+
class UnprocessableEntity(Exception):
|
|
151
151
|
"Validation Error"
|
|
152
152
|
|
|
153
153
|
body: _models.HttpValidationError
|
|
154
154
|
|
|
155
|
-
type Response = Ok
|
|
155
|
+
type Response = Ok
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
class RequestPasswordReset:
|
|
@@ -168,13 +168,13 @@ class RequestPasswordReset:
|
|
|
168
168
|
|
|
169
169
|
body: _models.MessageResponse
|
|
170
170
|
|
|
171
|
-
@dataclass(
|
|
172
|
-
class UnprocessableEntity:
|
|
171
|
+
@dataclass(slots=True)
|
|
172
|
+
class UnprocessableEntity(Exception):
|
|
173
173
|
"Validation Error"
|
|
174
174
|
|
|
175
175
|
body: _models.HttpValidationError
|
|
176
176
|
|
|
177
|
-
type Response = Ok
|
|
177
|
+
type Response = Ok
|
|
178
178
|
|
|
179
179
|
|
|
180
180
|
class ResetPassword:
|
|
@@ -190,25 +190,25 @@ class ResetPassword:
|
|
|
190
190
|
|
|
191
191
|
body: _models.MessageResponse
|
|
192
192
|
|
|
193
|
-
@dataclass(
|
|
194
|
-
class BadRequest:
|
|
193
|
+
@dataclass(slots=True)
|
|
194
|
+
class BadRequest(Exception):
|
|
195
195
|
"Невалидный запрос"
|
|
196
196
|
|
|
197
197
|
pass
|
|
198
198
|
|
|
199
|
-
@dataclass(
|
|
200
|
-
class Unauthorized:
|
|
199
|
+
@dataclass(slots=True)
|
|
200
|
+
class Unauthorized(Exception):
|
|
201
201
|
"Невалидный или истекший token"
|
|
202
202
|
|
|
203
203
|
pass
|
|
204
204
|
|
|
205
|
-
@dataclass(
|
|
206
|
-
class UnprocessableEntity:
|
|
205
|
+
@dataclass(slots=True)
|
|
206
|
+
class UnprocessableEntity(Exception):
|
|
207
207
|
"Validation Error"
|
|
208
208
|
|
|
209
209
|
body: _models.HttpValidationError
|
|
210
210
|
|
|
211
|
-
type Response = Ok
|
|
211
|
+
type Response = Ok
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
class RefreshToken:
|
|
@@ -225,19 +225,19 @@ class RefreshToken:
|
|
|
225
225
|
body: _models.AuthSuccessResponse
|
|
226
226
|
set_cookie: str | None = None
|
|
227
227
|
|
|
228
|
-
@dataclass(
|
|
229
|
-
class Unauthorized:
|
|
228
|
+
@dataclass(slots=True)
|
|
229
|
+
class Unauthorized(Exception):
|
|
230
230
|
"Невалидный или истекший refresh token"
|
|
231
231
|
|
|
232
232
|
pass
|
|
233
233
|
|
|
234
|
-
@dataclass(
|
|
235
|
-
class UnprocessableEntity:
|
|
234
|
+
@dataclass(slots=True)
|
|
235
|
+
class UnprocessableEntity(Exception):
|
|
236
236
|
"Validation Error"
|
|
237
237
|
|
|
238
238
|
body: _models.HttpValidationError
|
|
239
239
|
|
|
240
|
-
type Response = Ok
|
|
240
|
+
type Response = Ok
|
|
241
241
|
|
|
242
242
|
|
|
243
243
|
class ListUsers:
|
|
@@ -255,25 +255,25 @@ class ListUsers:
|
|
|
255
255
|
|
|
256
256
|
body: _models.UserListResponse
|
|
257
257
|
|
|
258
|
-
@dataclass(
|
|
259
|
-
class Unauthorized:
|
|
258
|
+
@dataclass(slots=True)
|
|
259
|
+
class Unauthorized(Exception):
|
|
260
260
|
"Не авторизован"
|
|
261
261
|
|
|
262
262
|
pass
|
|
263
263
|
|
|
264
|
-
@dataclass(
|
|
265
|
-
class Forbidden:
|
|
264
|
+
@dataclass(slots=True)
|
|
265
|
+
class Forbidden(Exception):
|
|
266
266
|
"Недостаточно прав"
|
|
267
267
|
|
|
268
268
|
pass
|
|
269
269
|
|
|
270
|
-
@dataclass(
|
|
271
|
-
class UnprocessableEntity:
|
|
270
|
+
@dataclass(slots=True)
|
|
271
|
+
class UnprocessableEntity(Exception):
|
|
272
272
|
"Validation Error"
|
|
273
273
|
|
|
274
274
|
body: _models.HttpValidationError
|
|
275
275
|
|
|
276
|
-
type Response = Ok
|
|
276
|
+
type Response = Ok
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
class CreateUser:
|
|
@@ -290,37 +290,37 @@ class CreateUser:
|
|
|
290
290
|
|
|
291
291
|
body: _models.CreateUserResponse
|
|
292
292
|
|
|
293
|
-
@dataclass(
|
|
294
|
-
class BadRequest:
|
|
293
|
+
@dataclass(slots=True)
|
|
294
|
+
class BadRequest(Exception):
|
|
295
295
|
"Некорректный запрос"
|
|
296
296
|
|
|
297
297
|
pass
|
|
298
298
|
|
|
299
|
-
@dataclass(
|
|
300
|
-
class Unauthorized:
|
|
299
|
+
@dataclass(slots=True)
|
|
300
|
+
class Unauthorized(Exception):
|
|
301
301
|
"Не авторизован"
|
|
302
302
|
|
|
303
303
|
pass
|
|
304
304
|
|
|
305
|
-
@dataclass(
|
|
306
|
-
class Forbidden:
|
|
305
|
+
@dataclass(slots=True)
|
|
306
|
+
class Forbidden(Exception):
|
|
307
307
|
"Недостаточно прав"
|
|
308
308
|
|
|
309
309
|
pass
|
|
310
310
|
|
|
311
|
-
@dataclass(
|
|
312
|
-
class Conflict:
|
|
311
|
+
@dataclass(slots=True)
|
|
312
|
+
class Conflict(Exception):
|
|
313
313
|
"Пользователь с таким email уже существует"
|
|
314
314
|
|
|
315
315
|
pass
|
|
316
316
|
|
|
317
|
-
@dataclass(
|
|
318
|
-
class UnprocessableEntity:
|
|
317
|
+
@dataclass(slots=True)
|
|
318
|
+
class UnprocessableEntity(Exception):
|
|
319
319
|
"Validation Error"
|
|
320
320
|
|
|
321
321
|
body: _models.HttpValidationError
|
|
322
322
|
|
|
323
|
-
type Response = Created
|
|
323
|
+
type Response = Created
|
|
324
324
|
|
|
325
325
|
|
|
326
326
|
class DeleteUser:
|
|
@@ -337,31 +337,31 @@ class DeleteUser:
|
|
|
337
337
|
|
|
338
338
|
pass
|
|
339
339
|
|
|
340
|
-
@dataclass(
|
|
341
|
-
class Unauthorized:
|
|
340
|
+
@dataclass(slots=True)
|
|
341
|
+
class Unauthorized(Exception):
|
|
342
342
|
"Не авторизован"
|
|
343
343
|
|
|
344
344
|
pass
|
|
345
345
|
|
|
346
|
-
@dataclass(
|
|
347
|
-
class Forbidden:
|
|
346
|
+
@dataclass(slots=True)
|
|
347
|
+
class Forbidden(Exception):
|
|
348
348
|
"Недостаточно прав"
|
|
349
349
|
|
|
350
350
|
pass
|
|
351
351
|
|
|
352
|
-
@dataclass(
|
|
353
|
-
class NotFound:
|
|
352
|
+
@dataclass(slots=True)
|
|
353
|
+
class NotFound(Exception):
|
|
354
354
|
"Пользователь не найден"
|
|
355
355
|
|
|
356
356
|
pass
|
|
357
357
|
|
|
358
|
-
@dataclass(
|
|
359
|
-
class UnprocessableEntity:
|
|
358
|
+
@dataclass(slots=True)
|
|
359
|
+
class UnprocessableEntity(Exception):
|
|
360
360
|
"Validation Error"
|
|
361
361
|
|
|
362
362
|
body: _models.HttpValidationError
|
|
363
363
|
|
|
364
|
-
type Response = NoContent
|
|
364
|
+
type Response = NoContent
|
|
365
365
|
|
|
366
366
|
|
|
367
367
|
class GetUser:
|
|
@@ -378,31 +378,31 @@ class GetUser:
|
|
|
378
378
|
|
|
379
379
|
body: _models.UserItem
|
|
380
380
|
|
|
381
|
-
@dataclass(
|
|
382
|
-
class Unauthorized:
|
|
381
|
+
@dataclass(slots=True)
|
|
382
|
+
class Unauthorized(Exception):
|
|
383
383
|
"Не авторизован"
|
|
384
384
|
|
|
385
385
|
pass
|
|
386
386
|
|
|
387
|
-
@dataclass(
|
|
388
|
-
class Forbidden:
|
|
387
|
+
@dataclass(slots=True)
|
|
388
|
+
class Forbidden(Exception):
|
|
389
389
|
"Недостаточно прав"
|
|
390
390
|
|
|
391
391
|
pass
|
|
392
392
|
|
|
393
|
-
@dataclass(
|
|
394
|
-
class NotFound:
|
|
393
|
+
@dataclass(slots=True)
|
|
394
|
+
class NotFound(Exception):
|
|
395
395
|
"Пользователь не найден"
|
|
396
396
|
|
|
397
397
|
pass
|
|
398
398
|
|
|
399
|
-
@dataclass(
|
|
400
|
-
class UnprocessableEntity:
|
|
399
|
+
@dataclass(slots=True)
|
|
400
|
+
class UnprocessableEntity(Exception):
|
|
401
401
|
"Validation Error"
|
|
402
402
|
|
|
403
403
|
body: _models.HttpValidationError
|
|
404
404
|
|
|
405
|
-
type Response = Ok
|
|
405
|
+
type Response = Ok
|
|
406
406
|
|
|
407
407
|
|
|
408
408
|
class UpdateUser:
|
|
@@ -420,31 +420,31 @@ class UpdateUser:
|
|
|
420
420
|
|
|
421
421
|
body: _models.UserItem
|
|
422
422
|
|
|
423
|
-
@dataclass(
|
|
424
|
-
class Unauthorized:
|
|
423
|
+
@dataclass(slots=True)
|
|
424
|
+
class Unauthorized(Exception):
|
|
425
425
|
"Не авторизован"
|
|
426
426
|
|
|
427
427
|
pass
|
|
428
428
|
|
|
429
|
-
@dataclass(
|
|
430
|
-
class Forbidden:
|
|
429
|
+
@dataclass(slots=True)
|
|
430
|
+
class Forbidden(Exception):
|
|
431
431
|
"Недостаточно прав"
|
|
432
432
|
|
|
433
433
|
pass
|
|
434
434
|
|
|
435
|
-
@dataclass(
|
|
436
|
-
class NotFound:
|
|
435
|
+
@dataclass(slots=True)
|
|
436
|
+
class NotFound(Exception):
|
|
437
437
|
"Пользователь не найден"
|
|
438
438
|
|
|
439
439
|
pass
|
|
440
440
|
|
|
441
|
-
@dataclass(
|
|
442
|
-
class UnprocessableEntity:
|
|
441
|
+
@dataclass(slots=True)
|
|
442
|
+
class UnprocessableEntity(Exception):
|
|
443
443
|
"Validation Error"
|
|
444
444
|
|
|
445
445
|
body: _models.HttpValidationError
|
|
446
446
|
|
|
447
|
-
type Response = Ok
|
|
447
|
+
type Response = Ok
|
|
448
448
|
|
|
449
449
|
|
|
450
450
|
class AdminApi(Protocol):
|