Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit effb5f6

Browse files
committed
Quotes ref classes
1 parent a4aaf4b commit effb5f6

159 files changed

Lines changed: 1620 additions & 5208 deletions

File tree

Some content is hidden

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

modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenSchema.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public CodegenSchema getSelfOrDeepestRef() {
132132
* @param schemas the input list that stores this and all required schemas
133133
* @return the list that stores this and all required schemas
134134
*/
135-
private ArrayList<CodegenSchema> getAllSchemas(ArrayList<CodegenSchema> schemas) {
135+
private ArrayList<CodegenSchema> getAllSchemas(ArrayList<CodegenSchema> schemas, int level) {
136136
/*
137137
post order traversal using alphabetic json schema keywords as the order
138138
keywords with schemas:
@@ -148,41 +148,45 @@ private ArrayList<CodegenSchema> getAllSchemas(ArrayList<CodegenSchema> schemas)
148148
$ref (because it is an import)
149149
*/
150150
if (additionalProperties != null) {
151-
additionalProperties.getAllSchemas(schemas);
151+
additionalProperties.getAllSchemas(schemas, level + 1);
152152
}
153153
if (allOf != null) {
154154
for (CodegenSchema someSchema: allOf) {
155-
someSchema.getAllSchemas(schemas);
155+
someSchema.getAllSchemas(schemas, level + 1);
156156
}
157157
}
158158
if (anyOf != null) {
159159
for (CodegenSchema someSchema: anyOf) {
160-
someSchema.getAllSchemas(schemas);
160+
someSchema.getAllSchemas(schemas, level + 1);
161161
}
162162
}
163163
if (items != null) {
164-
items.getAllSchemas(schemas);
164+
items.getAllSchemas(schemas, level + 1);
165165
}
166166
if (not != null) {
167-
not.getAllSchemas(schemas);
167+
not.getAllSchemas(schemas, level + 1);
168168
}
169169
if (oneOf != null) {
170170
for (CodegenSchema someSchema: oneOf) {
171-
someSchema.getAllSchemas(schemas);
171+
someSchema.getAllSchemas(schemas, level + 1);
172172
}
173173
}
174174
if (properties != null) {
175175
for (CodegenSchema someSchema: properties.values()) {
176-
someSchema.getAllSchemas(schemas);
176+
someSchema.getAllSchemas(schemas, level + 1);
177177
}
178178
}
179+
if (refInfo != null && level > 0) {
180+
// do not add ref to schemas
181+
return schemas;
182+
}
179183
schemas.add(this);
180184
return schemas;
181185
}
182186

183187
public ArrayList<CodegenSchema> getSchemas() {
184188
ArrayList<CodegenSchema> schemas = new ArrayList<>();
185-
return getAllSchemas(schemas);
189+
return getAllSchemas(schemas, 0);
186190
}
187191

188192
public boolean isComplicated() {
Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
{{#if allOf}}
22

3-
class AllOf:
4-
classes = [
5-
{{#each allOf}}
6-
{{#if refInfo.refClass}}
3+
@staticmethod
4+
def all_of():
5+
return (
6+
{{#each allOf}}
7+
{{#if refInfo.refClass}}
78
{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}},
8-
{{else}}
9+
{{else}}
910
{{jsonPathPiece.camelCase}},
10-
{{/if}}
11-
{{/each}}
12-
]
11+
{{/if}}
12+
{{/each}}
13+
)
1314
{{/if}}
1415
{{#if oneOf}}
1516

16-
class OneOf:
17-
classes = [
18-
{{#each oneOf}}
19-
{{#if refInfo.refClass}}
17+
@staticmethod
18+
def one_of():
19+
return (
20+
{{#each oneOf}}
21+
{{#if refInfo.refClass}}
2022
{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}},
21-
{{else}}
23+
{{else}}
2224
{{jsonPathPiece.camelCase}},
23-
{{/if}}
24-
{{/each}}
25-
]
25+
{{/if}}
26+
{{/each}}
27+
)
2628
{{/if}}
2729
{{#if anyOf}}
2830

29-
class AnyOf:
30-
classes = [
31-
{{#each anyOf}}
32-
{{#if refInfo.refClass}}
31+
@staticmethod
32+
def any_of():
33+
return (
34+
{{#each anyOf}}
35+
{{#if refInfo.refClass}}
3336
{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}},
34-
{{else}}
37+
{{else}}
3538
{{jsonPathPiece.camelCase}},
36-
{{/if}}
37-
{{/each}}
38-
]
39+
{{/if}}
40+
{{/each}}
41+
)
3942
{{/if}}
4043
{{#if not}}
4144
{{#with not}}
42-
{{#if refInfo.refClass}}
4345

44-
{{> components/schemas/_helper_refclass_staticmethod }}
45-
{{else}}
46-
_Not: typing_extensions.TypeAlias = {{jsonPathPiece.camelCase}}[U]
47-
{{/if}}
46+
@staticmethod
47+
def not_():
48+
{{#if refInfo.refClass}}
49+
return {{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}
50+
{{else}}
51+
return {{jsonPathPiece.camelCase}}
52+
{{/if}}
4853
{{/with}}
4954
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_dict_partial.hbs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,25 @@ def discriminator():
2525
{{/if}}
2626
{{#if properties}}
2727

28-
class Properties:
29-
{{#each properties}}
30-
{{#if refInfo.refClass}}
31-
32-
{{> components/schemas/_helper_refclass_staticmethod }}
33-
{{else}}
34-
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "Properties" jsonPathPiece.camelCase) }}
35-
{{/if}}
36-
{{/each}}
37-
__annotations__ = {
38-
{{#each properties}}
39-
{{#if refInfo.refClass}}
40-
"{{{@key.original}}}": {{jsonPathPiece.snakeCase}},
41-
{{else}}
28+
@staticmethod
29+
def properties():
30+
return {
31+
{{#each properties}}
32+
{{#if refInfo.refClass}}
33+
"{{{@key.original}}}": {{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}},
34+
{{else}}
4235
"{{{@key.original}}}": {{jsonPathPiece.camelCase}},
43-
{{/if}}
44-
{{/each}}
36+
{{/if}}
37+
{{/each}}
4538
}
4639
{{/if}}
4740
{{#with additionalProperties}}
48-
{{#if refInfo.refClass}}
4941

50-
{{> components/schemas/_helper_refclass_staticmethod }}
51-
{{else}}
52-
AdditionalProperties: typing_extensions.TypeAlias = {{jsonPathPiece.camelCase}}[U]
53-
{{/if}}
42+
@staticmethod
43+
def additional_properties():
44+
{{#if refInfo.refClass}}
45+
return {{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}
46+
{{else}}
47+
return {{jsonPathPiece.camelCase}}
48+
{{/if}}
5449
{{/with}}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{#if types}}
22
{{#eq types.size 1}}
3-
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:{{#if overload}} ...{{/if}}
3+
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:{{#if overload}} ...{{/if}}
44
{{else}}
5-
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[typing.Union[
5+
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{jsonPathPiece.camelCase}}[typing.Union[
66
{{> components/schemas/_helper_schema_python_base_types_newline }}
77
]]:{{#if overload}} ...{{/if}}
88
{{/eq}}
99
{{else}}
10-
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[typing.Union[
10+
def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{jsonPathPiece.camelCase}}[typing.Union[
1111
{{> components/schemas/_helper_schema_python_base_types_newline }}
1212
]]:{{#if overload}} ...{{/if}}
1313
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitems.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
{{else}}
99
{{#if jsonPathPiece}}
1010
{{#if schemaIsFromAdditionalProperties}}
11-
{{> components/schemas/_helper_getitem_property propertyClass="" literal=true key=@key.original overload=true }}
11+
{{> components/schemas/_helper_getitem_property literal=true key=@key.original overload=true }}
1212
{{else}}
13-
{{> components/schemas/_helper_getitem_property propertyClass=".Properties" literal=true key=@key.original overload=true }}
13+
{{> components/schemas/_helper_getitem_property literal=true key=@key.original overload=true }}
1414
{{/if}}
1515
{{else}}
1616
{{! for when additionalProperties is unset, use schemas.AnyTypeSchema because val is not always schemas.UnsetAnyTypeSchema }}
@@ -29,7 +29,7 @@ def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) ->
2929
{{#if refInfo.refClass}}
3030
{{> components/schemas/_helper_getitem_refclass literal=true key=@key.original overload=true }}
3131
{{else}}
32-
{{> components/schemas/_helper_getitem_property propertyClass=".Properties" literal=true key=@key.original overload=true }}
32+
{{> components/schemas/_helper_getitem_property literal=true key=@key.original overload=true }}
3333
{{/if}}
3434
{{/each}}
3535
{{/if}}
@@ -41,7 +41,7 @@ def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) ->
4141
{{#if refInfo.refClass}}
4242
{{> components/schemas/_helper_getitem_refclass literal=false key="str" overload=true }}
4343
{{else}}
44-
{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="str" overload=true }}
44+
{{> components/schemas/_helper_getitem_property literal=false key="str" overload=true }}
4545
{{/if}}
4646
{{/unless}}
4747
{{else}}
@@ -90,7 +90,7 @@ def __getitem__(
9090
{{#if refInfo.refClass}}
9191
{{> components/schemas/_helper_getitem_refclass literal=false key="str" overload=false }}
9292
{{else}}
93-
{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="str" overload=false }}
93+
{{> components/schemas/_helper_getitem_property literal=false key="str" overload=false }}
9494
{{/if}}
9595
# dict_instance[name] accessor
9696
return super().__getitem__(name)
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{{#with items}}
2-
{{#if refInfo.refClass}}
32

4-
{{> components/schemas/_helper_refclass_staticmethod }}
5-
{{else}}
6-
Items: typing_extensions.TypeAlias = {{jsonPathPiece.camelCase}}[U]
7-
{{/if}}
3+
@staticmethod
4+
def items():
5+
{{#if refInfo.refClass}}
6+
return {{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}
7+
{{else}}
8+
return {{jsonPathPiece.camelCase}}
9+
{{/if}}
810
{{/with}}

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __new__(
1111
]
1212
{{else}}
1313
typing.Union[
14-
{{> components/schemas/_helper_new_property_value_type propertyClass=null optional=false }}
14+
{{> components/schemas/_helper_new_property_value_type optional=false }}
1515
]
1616
{{/if}}
1717
{{/with}}
@@ -65,11 +65,11 @@ def __new__(
6565
{{#if jsonPathPiece}}
6666
{{#if schemaIsFromAdditionalProperties}}
6767
{{@key.original}}: typing.Union[
68-
{{> components/schemas/_helper_new_property_value_type propertyClass=null optional=false }}
68+
{{> components/schemas/_helper_new_property_value_type optional=false }}
6969
],
7070
{{else}}
7171
{{@key.original}}: typing.Union[
72-
{{> components/schemas/_helper_new_property_value_type propertyClass="Properties" optional=false }}
72+
{{> components/schemas/_helper_new_property_value_type optional=false }}
7373
],
7474
{{/if}}
7575
{{else}}
@@ -95,7 +95,7 @@ def __new__(
9595
] = schemas.unset,
9696
{{else}}
9797
{{@key.original}}: typing.Union[
98-
{{> components/schemas/_helper_new_property_value_type propertyClass="Properties" optional=true }}
98+
{{> components/schemas/_helper_new_property_value_type optional=true }}
9999
] = schemas.unset,
100100
{{/if}}
101101
{{/if}}
@@ -109,7 +109,7 @@ def __new__(
109109
],
110110
{{else}}
111111
**kwargs: typing.Union[
112-
{{> components/schemas/_helper_new_property_value_type propertyClass=null optional=false }}
112+
{{> components/schemas/_helper_new_property_value_type optional=false }}
113113
],
114114
{{/if}}
115115
{{/unless}}

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_property_value_type.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{#if types}}
22
{{#eq types.size 1}}
3-
Schema_.{{#if propertyClass}}{{propertyClass}}.{{/if}}{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}],
3+
{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}],
44
{{else}}
5-
Schema_.{{#if propertyClass}}{{propertyClass}}.{{/if}}{{jsonPathPiece.camelCase}}[typing.Union[
5+
{{jsonPathPiece.camelCase}}[typing.Union[
66
{{> components/schemas/_helper_schema_python_base_types_newline }}
77
]],
88
{{/eq}}
99
{{else}}
10-
Schema_.{{#if propertyClass}}{{propertyClass}}.{{/if}}{{jsonPathPiece.camelCase}}[typing.Union[
10+
{{jsonPathPiece.camelCase}}[typing.Union[
1111
{{> components/schemas/_helper_schema_python_base_types_newline }}
1212
]],
1313
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_property_type_hints.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ def {{@key.original}}(self) -> {{#if ../refInfo.refModule}}{{../refInfo.refModul
3434
{{#eq types.size 1}}
3535

3636
@property
37-
def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:
37+
def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:
3838
return self.__getitem__("{{{@key.original}}}")
3939
{{else}}
4040

4141
@property
42-
def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[
42+
def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[
4343
{{> components/schemas/_helper_schema_python_base_types_newline }}
4444
]]:
4545
return self.__getitem__("{{{@key.original}}}")
4646
{{/eq}}
4747
{{else}}
4848

4949
@property
50-
def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[
50+
def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[
5151
{{> components/schemas/_helper_schema_python_base_types_newline }}
5252
]]:
5353
return self.__getitem__("{{{@key.original}}}")
@@ -57,20 +57,20 @@ def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[
5757
{{#eq types.size 1}}
5858

5959
@property
60-
def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:
60+
def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:
6161
return self.__getitem__("{{{@key.original}}}")
6262
{{else}}
6363

6464
@property
65-
def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[typing.Union[
65+
def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[
6666
{{> components/schemas/_helper_schema_python_base_types_newline }}
6767
]]:
6868
return self.__getitem__("{{{@key.original}}}")
6969
{{/eq}}
7070
{{else}}
7171

7272
@property
73-
def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[typing.Union[
73+
def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[
7474
{{> components/schemas/_helper_schema_python_base_types_newline }}
7575
]]:
7676
return self.__getitem__("{{{@key.original}}}")

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_list.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class {{jsonPathPiece.camelCase}}(
3131
{{#if refInfo.refClass}}
3232
{{> components/schemas/_helper_getitem_refclass literal=false key="int" overload=false }}
3333
{{else}}
34-
{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="int" overload=false }}
34+
{{> components/schemas/_helper_getitem_property literal=false key="int" overload=false }}
3535
{{/if}}
3636
return super().__getitem__(name)
3737
{{/with}}

0 commit comments

Comments
 (0)