Skip to content

Commit e35b31a

Browse files
committedNov 5, 2024·
Merge branch 'main' of github.com:openapi-generators/openapi-python-client into issue1123-merge-model
2 parents 5cd16ac + 40d63f9 commit e35b31a

File tree

129 files changed

+3933
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3933
-455
lines changed
 

Diff for: ‎.changeset/fix-model-override.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,50 @@ default: patch
44

55
# Fix overriding of object property class
66

7-
Fixed issue #1123, in which a property could end up with the wrong type when combining two object schemas with `allOf`, if the type of the property was itself an object but had a different schema in each. Previously, if the property's type was A in the first schema and B in the second, the resulting schema would use type A for the property.
7+
Fixed issue #1123, in which a property could end up with the wrong type when combining two object schemas with `allOf`, if the type of the property was itself an object but had a different schema in each. Example:
88

9-
The new behavior is, that the generator will test whether one of the types A/B is derived from the other. "Derived" here means that the result of `allOf[A, B]` would be exactly identical to B. If so, it will use the class name of B. If not, it will attempt to merge A and B with the usual `allOf` logic to create a new inline schema.
9+
```yaml
10+
ModelA:
11+
properties:
12+
status:
13+
type: string
14+
result:
15+
- $ref: "#/components/schemas/BaseResult"
16+
17+
ModelB:
18+
allOf:
19+
- $ref: "#/components/schemas/ModelA"
20+
- properties:
21+
result:
22+
- $ref: "#/components/schemas/ExtendedResult"
23+
24+
ModelC:
25+
allOf:
26+
- $ref: "#/components/schemas/ModelA"
27+
- properties:
28+
result:
29+
- $ref: "#/components/schemas/UnrelatedResult"
30+
31+
BaseResult:
32+
properties:
33+
prop1:
34+
type: string
35+
36+
ExtendedResult:
37+
allOf:
38+
- $ref: "#/components/schemas/BaseResult"
39+
- properties:
40+
prop2:
41+
type: string
42+
43+
UnrelatedResult:
44+
properties:
45+
prop3:
46+
type: string
47+
```
48+
49+
Previously, in the generated classes for both `ModelB` and `ModelC`, the type of `result` was being incorrectly set to `BaseResult`.
50+
51+
The new behavior is, when computing `allOf: [A, B]` where `A` and `B` are both objects, any property `P` whose name exists in both schemas will have a schema equivalent to `allOf: [A.P, B.P]`. This is consistent with the basic definition of `allOf`.
52+
53+
When translating this into Python code, the generator will use a type that correctly describes the combined schema for the property. If the combined schema is exactly equal in shape to either `A.P` or `B.P` (implying that one was already derived from the other using `allOf`) then it will reuse the corresponding Python class. Otherwise it will create a new class, just as it would for an inline schema that used `allOf`. Therefore in the example above, the type of `ModelB.result` is `ExtendedResult`, but the type of `ModelC.result` is a new class called `ModelCResult` that includes all the properties from `BaseResult` and `UnrelatedResult`.

Diff for: ‎.github/workflows/checks.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ jobs:
1111
test:
1212
strategy:
1313
matrix:
14-
python: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
14+
python: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
1515
os: [ ubuntu-latest, macos-latest, windows-latest ]
1616
runs-on: ${{ matrix.os }}
1717
steps:
18-
- uses: actions/checkout@v4.1.7
18+
- uses: actions/checkout@v4.2.2
1919
- name: Set up Python
20-
uses: actions/setup-python@v5.2.0
20+
uses: actions/setup-python@v5.3.0
2121
with:
2222
python-version: ${{ matrix.python }}
2323

@@ -64,7 +64,7 @@ jobs:
6464
if: matrix.os == 'ubuntu-latest'
6565

6666
- name: Store coverage report
67-
uses: actions/upload-artifact@v4.4.0
67+
uses: actions/upload-artifact@v4.4.3
6868
if: matrix.os == 'ubuntu-latest'
6969
with:
7070
name: coverage-${{ matrix.python }}
@@ -77,7 +77,7 @@ jobs:
7777
needs: test
7878
runs-on: ubuntu-latest
7979
steps:
80-
- uses: actions/checkout@v4.1.7
80+
- uses: actions/checkout@v4.2.2
8181
- uses: actions/setup-python@v5
8282
with:
8383
python-version: "3.12"
@@ -107,7 +107,7 @@ jobs:
107107
.venv/bin/python -m coverage report --fail-under=100
108108
109109
- name: Upload HTML report if check failed.
110-
uses: actions/upload-artifact@v4.4.0
110+
uses: actions/upload-artifact@v4.4.3
111111
with:
112112
name: html-report
113113
path: htmlcov
@@ -127,9 +127,9 @@ jobs:
127127
ports:
128128
- "3000:3000"
129129
steps:
130-
- uses: actions/checkout@v4.1.7
130+
- uses: actions/checkout@v4.2.2
131131
- name: Set up Python
132-
uses: actions/setup-python@v5.2.0
132+
uses: actions/setup-python@v5.3.0
133133
with:
134134
python-version: "3.8"
135135
- name: Get Python Version

0 commit comments

Comments
 (0)