Skip to content

Commit da76b1c

Browse files
authored
Merge branch 'main' into issue-1090-merge-allof
2 parents 22361fe + ae47096 commit da76b1c

File tree

12 files changed

+202
-117
lines changed

12 files changed

+202
-117
lines changed

.changeset/correctly_resolve_references_to_a_type_that_is_itself_just_a_single_allof_reference.md

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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ dmypy.json
2424
# JetBrains
2525
.idea/
2626

27+
# Visual Studio Code
28+
.vscode/
29+
2730
test-reports/
2831

2932
/coverage.xml

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ Programmatic usage of this project (e.g., importing it as a Python module) and t
1313

1414
The 0.x prefix used in versions for this project is to indicate that breaking changes are expected frequently (several times a year). Breaking changes will increment the minor number, all other changes will increment the patch number. You can track the progress toward 1.0 [here](https://github.com/openapi-generators/openapi-python-client/projects/2).
1515

16+
## 0.21.4 (2024-08-25)
17+
18+
### Fixes
19+
20+
#### Allow OpenAPI 3.1-style `exclusiveMinimum` and `exclusiveMaximum`
21+
22+
Fixed by PR #1092. Thanks @mikkelam!
23+
24+
#### Add missing `cast` import when using `const`
25+
26+
Fixed by PR #1072. Thanks @dorcohe!
27+
28+
#### Correctly resolve references to a type that is itself just a single allOf reference
29+
30+
PR #1103 fixed issue #1091. Thanks @eli-bl!
31+
32+
#### Support `const` booleans and floats
33+
34+
Fixed in PR #1086. Thanks @flxdot!
35+
1636
## 0.21.3 (2024-08-18)
1737

1838
### Features

integration-tests/pdm.lock

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openapi_python_client/parser/properties/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ConstProperty(PropertyProtocol):
2727
def build(
2828
cls,
2929
*,
30-
const: str | int,
30+
const: str | int | float | bool,
3131
default: Any,
3232
name: str,
3333
python_name: PythonIdentifier,
@@ -115,6 +115,6 @@ def get_imports(self, *, prefix: str) -> set[str]:
115115
if self.required:
116116
return {"from typing import Literal"}
117117
return {
118-
"from typing import Literal, Union",
118+
"from typing import Literal, Union, cast",
119119
f"from {prefix}types import UNSET, Unset",
120120
}

openapi_python_client/schema/openapi_schema_pydantic/schema.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Optional, Union
22

3-
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, model_validator
3+
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr, model_validator
44

55
from ..data_type import DataType
66
from .discriminator import Discriminator
@@ -23,9 +23,9 @@ class Schema(BaseModel):
2323
title: Optional[str] = None
2424
multipleOf: Optional[float] = Field(default=None, gt=0.0)
2525
maximum: Optional[float] = None
26-
exclusiveMaximum: Optional[bool] = None
26+
exclusiveMaximum: Optional[Union[bool, float]] = None
2727
minimum: Optional[float] = None
28-
exclusiveMinimum: Optional[bool] = None
28+
exclusiveMinimum: Optional[Union[bool, float]] = None
2929
maxLength: Optional[int] = Field(default=None, ge=0)
3030
minLength: Optional[int] = Field(default=None, ge=0)
3131
pattern: Optional[str] = None
@@ -36,7 +36,7 @@ class Schema(BaseModel):
3636
minProperties: Optional[int] = Field(default=None, ge=0)
3737
required: Optional[List[str]] = Field(default=None, min_length=1)
3838
enum: Union[None, List[Any]] = Field(default=None, min_length=1)
39-
const: Union[None, StrictStr, StrictInt] = None
39+
const: Union[None, StrictStr, StrictInt, StrictFloat, StrictBool] = None
4040
type: Union[DataType, List[DataType], None] = Field(default=None)
4141
allOf: List[Union[Reference, "Schema"]] = Field(default_factory=list)
4242
oneOf: List[Union[Reference, "Schema"]] = Field(default_factory=list)
@@ -160,6 +160,33 @@ class Schema(BaseModel):
160160
},
161161
)
162162

163+
@model_validator(mode="after")
164+
def handle_exclusive_min_max(self) -> "Schema":
165+
"""
166+
Convert exclusiveMinimum/exclusiveMaximum between OpenAPI v3.0 (bool) and v3.1 (numeric).
167+
"""
168+
# Handle exclusiveMinimum
169+
if isinstance(self.exclusiveMinimum, bool) and self.minimum is not None:
170+
if self.exclusiveMinimum:
171+
self.exclusiveMinimum = self.minimum
172+
self.minimum = None
173+
else:
174+
self.exclusiveMinimum = None
175+
elif isinstance(self.exclusiveMinimum, float):
176+
self.minimum = None
177+
178+
# Handle exclusiveMaximum
179+
if isinstance(self.exclusiveMaximum, bool) and self.maximum is not None:
180+
if self.exclusiveMaximum:
181+
self.exclusiveMaximum = self.maximum
182+
self.maximum = None
183+
else:
184+
self.exclusiveMaximum = None
185+
elif isinstance(self.exclusiveMaximum, float):
186+
self.maximum = None
187+
188+
return self
189+
163190
@model_validator(mode="after")
164191
def handle_nullable(self) -> "Schema":
165192
"""Convert the old 3.0 `nullable` property into the new 3.1 style"""

0 commit comments

Comments
 (0)