Skip to content

Commit 2dc21a0

Browse files
🔥 Remove support for generating exception models
1 parent 6dcea49 commit 2dc21a0

File tree

9 files changed

+40
-62
lines changed

9 files changed

+40
-62
lines changed

‎ChangeLog.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
9+
## [Unreleased]
10+
11+
### Removed
12+
13+
- Removed support for generating exceptions.
14+
15+
816
## [0.11.0] - 2024-08-14
917

1018
### Added
@@ -183,7 +191,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
183191
- Generate classes for schemas under components/schemas
184192
- Generate partial client class with methods based on /paths/*/*
185193

186-
[unreleased]: https://github.com/python-lapidary/lapidary-render/compare/v0.11.0...HEAD
194+
[Unreleased]: https://github.com/python-lapidary/lapidary-render/compare/v0.11.0...HEAD
187195
[0.10.1]: https://github.com/python-lapidary/lapidary-render/compare/v0.10.1...v0.11.0
188196
[0.10.1]: https://github.com/python-lapidary/lapidary-render/compare/v0.10.0...v0.10.1
189197
[0.10.0]: https://github.com/python-lapidary/lapidary-render/compare/v0.9.0...v0.10.0
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# ignore: F401
22

3-
from .ext import *
43
from .model import *
54

65
type SchemaOrRef = Schema | Reference

‎src/lapidary/render/model/openapi/ext.py‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎src/lapidary/render/model/openapi/model.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
PropertyPattern,
1818
validate_example_xor_examples,
1919
)
20-
from .ext import LapidaryModelType
2120

2221

2322
class Reference[Target](BaseModel):
@@ -237,7 +236,6 @@ class Schema(ExtendableModel):
237236
),
238237
]
239238
lapidary_name: typing.Annotated[str | None, pydantic.Field(alias='x-lapidary-type-name')] = None
240-
lapidary_model_type: typing.Annotated[LapidaryModelType | None, pydantic.Field(alias='x-lapidary-modelType')] = None
241239

242240

243241
class Tag(ExtendableModel):

‎src/lapidary/render/model/python/model.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class SchemaClass:
200200
allow_extra: bool = False
201201
docstr: str | None = None
202202
fields: list[Field] = dc.field(default_factory=list)
203-
model_type: ModelType = ModelType.model
204203

205204
def dependencies(self) -> Iterable[TypeHint]:
206205
yield self.base_type

‎src/lapidary/render/model/schema.py‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,19 @@ def _process_schema_object(self, value: openapi.Schema, stack: Stack) -> python.
3030
return self.schema_types[stack][1]
3131

3232
name = value.lapidary_name or names.maybe_mangle_name(stack.top())
33-
base_type = (
34-
python.TypeHint.from_type(Exception)
35-
if value.lapidary_model_type is openapi.LapidaryModelType.exception
36-
else python.TypeHint.from_str('lapidary.runtime:ModelBase')
37-
)
38-
3933
stack_props = stack.push('properties')
4034
fields = [
4135
self.process_property(prop_schema, stack_props.push(prop_name), prop_name, prop_name in value.required)
4236
for prop_name, prop_schema in value.properties.items()
4337
]
4438

45-
model_type = (
46-
python.ModelType[value.lapidary_model_type.name] if value.lapidary_model_type else python.ModelType.model
47-
)
48-
4939
type_hint = resolve_type_hint(str(self.root_package), stack.push('schema', name))
5040
schema_class = python.SchemaClass(
5141
class_name=name,
52-
base_type=base_type,
42+
base_type=python.TypeHint.from_str('lapidary.runtime:ModelBase'),
5343
allow_extra=value.additional_properties is not False,
5444
fields=fields,
5545
docstr=value.description or None,
56-
model_type=model_type,
5746
)
5847
self.schema_types[stack] = schema_class, type_hint
5948
return type_hint

‎src/lapidary/render/templates/render/includes/module/schema.py.jinja‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
{%- from 'includes/type_hint.py.jinja' import type_hint %}
2+
{%- macro render_field(field) %}
3+
{%- if field.annotation.field_props %}
4+
{{ field.name }}: typing.Annotated[
5+
{{ type_hint(field.annotation.type, path) }},
6+
pydantic.Field(
7+
{%- for key, value in field.annotation.field_props.items() | sort %}
8+
{{ key }}={{ value }},
9+
{%- endfor %}
10+
)
11+
]
12+
{%- else %}
13+
{{ field.name }}: {{ type_hint(field.annotation.type, path) }}
14+
{%- endif -%}
15+
{%- if field.required is false %} = None{% endif %}
16+
{%- endmacro -%}
117
from __future__ import annotations
218

319
import lapidary.runtime
@@ -9,5 +25,18 @@ import {{ imp }}
925
{%- endfor %}
1026
{% set path = item.path %}
1127
{%- for model in item.body %}
12-
{% include 'includes/schema/schema_class_' + model.model_type.name + '.py.jinja' %}
28+
29+
class {{ model.class_name }}({{ type_hint(model.base_type, path) }}):
30+
{%- for field in model.fields if field.required %}
31+
{{- render_field(field) }}
32+
{% endfor %}
33+
{%- for field in model.fields if not field.required %}
34+
{{- render_field(field) }}
35+
{% endfor %}
36+
37+
{%- if model.allow_extra %}
38+
model_config = pydantic.ConfigDict(
39+
extra='allow'
40+
)
41+
{% endif -%}
1342
{%- endfor -%}

‎src/lapidary/render/templates/render/includes/schema/schema_class_exception.py.jinja‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎src/lapidary/render/templates/render/includes/schema/schema_class_model.py.jinja‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)