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

Commit 808d63e

Browse files
committed
Fixes python tests, adjusts server initialization
1 parent c9368e0 commit 808d63e

87 files changed

Lines changed: 1562 additions & 80 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/DefaultCodegen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4435,6 +4435,7 @@ protected LinkedHashMapWithContext<CodegenKey, CodegenSchema> getRequiredPropert
44354435
int reqPropsWithDef = 0;
44364436
LinkedHashMapWithContext<CodegenKey, CodegenSchema> requiredProperties = new LinkedHashMapWithContext<>();
44374437
boolean allAreInline = true;
4438+
boolean addPropsIsFalse = additionalProperties != null && additionalProperties.isBooleanSchemaFalse;
44384439
for (String requiredPropertyName: required) {
44394440
// required property is defined in properties, value is that CodegenSchema
44404441
if (properties != null && requiredAndOptionalProperties.containsKey(requiredPropertyName)) {
@@ -4452,7 +4453,7 @@ protected LinkedHashMapWithContext<CodegenKey, CodegenSchema> getRequiredPropert
44524453
} else {
44534454
throw new RuntimeException("Property " + requiredPropertyName + " is missing from getVars");
44544455
}
4455-
} else if (additionalProperties != null && additionalProperties.isBooleanSchemaFalse) {
4456+
} else if (addPropsIsFalse) {
44564457
// required property is not defined in properties, and additionalProperties is false, value is null
44574458
// no schema definition: error use case?
44584459
CodegenKey key = getKey(requiredPropertyName, "schemas", null);
@@ -4490,7 +4491,11 @@ protected LinkedHashMapWithContext<CodegenKey, CodegenSchema> getRequiredPropert
44904491
boolean onlyReqPropsCase2 = (requiredPropsWithDefAllFromAddProp && properties == null);
44914492
boolean onlyReqPropsCase3 = (propReqProps != 0 && addPropReqProps != 0 && propReqProps + addPropReqProps == reqPropsWithDef && schemaProperties != null && required.containsAll(schemaProperties.keySet()));
44924493
if (onlyReqPropsCase1 || onlyReqPropsCase2 || onlyReqPropsCase3) {
4493-
keyName = currentName + "DictInput";
4494+
if (addPropsIsFalse) {
4495+
keyName = currentName + "Dict";
4496+
} else {
4497+
keyName = currentName + "DictInput";
4498+
}
44944499
} else {
44954500
keyName = currentName + "RequiredDictInput";
44964501
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,22 @@ private void getAllSchemas(ArrayList<CodegenSchema> schemasBeforeImports, ArrayL
231231
extraSchema.instanceType = "requiredPropertiesInputType";
232232
extraSchema.requiredProperties = requiredProperties;
233233
extraSchema.additionalProperties = additionalProperties;
234+
235+
CodegenSchema propertiesOutputSchema = new CodegenSchema();
236+
propertiesOutputSchema.instanceType = "propertiesOutputType";
237+
propertiesOutputSchema.requiredProperties = requiredProperties;
238+
propertiesOutputSchema.additionalProperties = additionalProperties;
239+
propertiesOutputSchema.mapOutputJsonPathPiece = mapOutputJsonPathPiece;
234240
if (requiredProperties.allAreInline()) {
235241
schemasBeforeImports.add(extraSchema);
242+
if (mapOutputJsonPathPiece != mapInputJsonPathPiece) {
243+
schemasBeforeImports.add(propertiesOutputSchema);
244+
}
236245
} else {
237246
schemasAfterImports.add(extraSchema);
247+
if (mapOutputJsonPathPiece != mapInputJsonPathPiece) {
248+
schemasAfterImports.add(propertiesOutputSchema);
249+
}
238250
}
239251
}
240252
typedDictUseCase = (optionalProperties != null && additionalPropertiesIsBooleanSchemaFalse);
@@ -244,10 +256,22 @@ private void getAllSchemas(ArrayList<CodegenSchema> schemasBeforeImports, ArrayL
244256
extraSchema.instanceType = "optionalPropertiesInputType";
245257
extraSchema.optionalProperties = optionalProperties;
246258
extraSchema.additionalProperties = additionalProperties;
259+
260+
CodegenSchema propertiesOutputSchema = new CodegenSchema();
261+
propertiesOutputSchema.instanceType = "propertiesOutputType";
262+
propertiesOutputSchema.optionalProperties = optionalProperties;
263+
propertiesOutputSchema.additionalProperties = additionalProperties;
264+
propertiesOutputSchema.mapOutputJsonPathPiece = mapOutputJsonPathPiece;
247265
if (optionalProperties.allAreInline()) {
248266
schemasBeforeImports.add(extraSchema);
267+
if (mapOutputJsonPathPiece != mapInputJsonPathPiece) {
268+
schemasBeforeImports.add(propertiesOutputSchema);
269+
}
249270
} else {
250271
schemasAfterImports.add(extraSchema);
272+
if (mapOutputJsonPathPiece != mapInputJsonPathPiece) {
273+
schemasBeforeImports.add(propertiesOutputSchema);
274+
}
251275
}
252276
}
253277
boolean requiredPropsAndOptionalPropsSet = (requiredProperties != null && optionalProperties != null);

modules/openapi-json-schema-generator/src/main/resources/python/servers/server.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class {{jsonPathPiece.camelCase}}(server.Server{{#if variables}}With{{else}}With
2222
'''
2323
{{/if}}
2424
{{#if variables}}
25-
variables: Variables[frozendict.frozendict] = Variables({
25+
variables: {{variables.mapOutputJsonPathPiece.camelCase}} = {{variables.jsonPathPiece.camelCase}}.validate({
2626
{{#with variables}}
2727
{{#each properties}}
2828
"{{{@key.original}}}": {{jsonPathPiece.camelCase}}.Schema_.default,
2929
{{/each}}
3030
{{/with}}
3131
})
32-
variables_cls: typing.Type[Variables] = Variables
32+
variables_cls: typing.Type[{{variables.jsonPathPiece.camelCase}}] = {{variables.jsonPathPiece.camelCase}}
3333
_url: str = "{{url}}"
3434
{{else}}
3535
url: str = "{{url}}"

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_200_response.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
]
3737

3838

39+
class _200ResponseDict(typing.Dict[str, typing.Any]):
40+
41+
@typing.overload
42+
def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[decimal.Decimal]: ...
43+
44+
@typing.overload
45+
def __getitem__(self, name: typing_extensions.Literal["class"]) -> _Class[str]: ...
46+
47+
3948
class _200Response(
4049
schemas.AnyTypeSchema[schemas.T],
4150
):

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_return.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
]
3131

3232

33+
class ReturnDict(typing.Dict[str, typing.Any]):
34+
35+
@typing.overload
36+
def __getitem__(self, name: typing_extensions.Literal["return"]) -> Return2[decimal.Decimal]: ...
37+
38+
3339
class _Return(
3440
schemas.AnyTypeSchema[schemas.T],
3541
):

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/abstract_step_message.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,90 @@
8585
]
8686

8787

88+
class AbstractStepMessageDict(typing.Dict[str, typing.Any]):
89+
90+
@property
91+
def description(self) -> schemas.AnyTypeSchema[typing.Union[
92+
frozendict.frozendict,
93+
str,
94+
decimal.Decimal,
95+
schemas.BoolClass,
96+
schemas.NoneClass,
97+
tuple,
98+
bytes,
99+
schemas.FileIO
100+
]]:
101+
return self.__getitem__("description")
102+
103+
@property
104+
def discriminator(self) -> Discriminator[str]:
105+
return self.__getitem__("discriminator")
106+
107+
@property
108+
def sequenceNumber(self) -> schemas.AnyTypeSchema[typing.Union[
109+
frozendict.frozendict,
110+
str,
111+
decimal.Decimal,
112+
schemas.BoolClass,
113+
schemas.NoneClass,
114+
tuple,
115+
bytes,
116+
schemas.FileIO
117+
]]:
118+
return self.__getitem__("sequenceNumber")
119+
120+
@typing.overload
121+
def __getitem__(self, name: typing_extensions.Literal["description"]) -> schemas.AnyTypeSchema[typing.Union[
122+
frozendict.frozendict,
123+
str,
124+
decimal.Decimal,
125+
schemas.BoolClass,
126+
schemas.NoneClass,
127+
tuple,
128+
bytes,
129+
schemas.FileIO
130+
]]: ...
131+
132+
@typing.overload
133+
def __getitem__(self, name: typing_extensions.Literal["discriminator"]) -> Discriminator[str]: ...
134+
135+
@typing.overload
136+
def __getitem__(self, name: typing_extensions.Literal["sequenceNumber"]) -> schemas.AnyTypeSchema[typing.Union[
137+
frozendict.frozendict,
138+
str,
139+
decimal.Decimal,
140+
schemas.BoolClass,
141+
schemas.NoneClass,
142+
tuple,
143+
bytes,
144+
schemas.FileIO
145+
]]: ...
146+
147+
@typing.overload
148+
def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[
149+
frozendict.frozendict,
150+
str,
151+
decimal.Decimal,
152+
schemas.BoolClass,
153+
schemas.NoneClass,
154+
tuple,
155+
bytes,
156+
schemas.FileIO
157+
]]: ...
158+
159+
def __getitem__(
160+
self,
161+
name: typing.Union[
162+
typing_extensions.Literal["description"],
163+
typing_extensions.Literal["discriminator"],
164+
typing_extensions.Literal["sequenceNumber"],
165+
str
166+
]
167+
):
168+
# dict_instance[name] accessor
169+
return super().__getitem__(name)
170+
171+
88172
class AbstractStepMessage(
89173
schemas.DictSchema[schemas.T]
90174
):

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_class.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,42 @@ def validate(
338338
]
339339

340340

341+
class AdditionalPropertiesClassDict(typing.Dict[str, typing.Any]):
342+
343+
@typing.overload
344+
def __getitem__(self, name: typing_extensions.Literal["map_property"]) -> MapProperty[frozendict.frozendict]: ...
345+
346+
@typing.overload
347+
def __getitem__(self, name: typing_extensions.Literal["map_of_map_property"]) -> MapOfMapProperty[frozendict.frozendict]: ...
348+
349+
@typing.overload
350+
def __getitem__(self, name: typing_extensions.Literal["anytype_1"]) -> Anytype1[typing.Union[
351+
frozendict.frozendict,
352+
str,
353+
decimal.Decimal,
354+
schemas.BoolClass,
355+
schemas.NoneClass,
356+
tuple,
357+
bytes,
358+
schemas.FileIO
359+
]]: ...
360+
361+
@typing.overload
362+
def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_1"]) -> MapWithUndeclaredPropertiesAnytype1[frozendict.frozendict]: ...
363+
364+
@typing.overload
365+
def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_2"]) -> MapWithUndeclaredPropertiesAnytype2[frozendict.frozendict]: ...
366+
367+
@typing.overload
368+
def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_3"]) -> MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict]: ...
369+
370+
@typing.overload
371+
def __getitem__(self, name: typing_extensions.Literal["empty_map"]) -> EmptyMap[frozendict.frozendict]: ...
372+
373+
@typing.overload
374+
def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_string"]) -> MapWithUndeclaredPropertiesString[frozendict.frozendict]: ...
375+
376+
341377
class AdditionalPropertiesClass(
342378
schemas.DictSchema[schemas.T]
343379
):

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_and_format.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,117 @@ def validate(
10531053
]
10541054

10551055

1056+
class AnyTypeAndFormatDict(typing.Dict[str, typing.Any]):
1057+
1058+
@typing.overload
1059+
def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Uuid[typing.Union[
1060+
frozendict.frozendict,
1061+
str,
1062+
decimal.Decimal,
1063+
schemas.BoolClass,
1064+
schemas.NoneClass,
1065+
tuple,
1066+
bytes,
1067+
schemas.FileIO
1068+
]]: ...
1069+
1070+
@typing.overload
1071+
def __getitem__(self, name: typing_extensions.Literal["date"]) -> Date[typing.Union[
1072+
frozendict.frozendict,
1073+
str,
1074+
decimal.Decimal,
1075+
schemas.BoolClass,
1076+
schemas.NoneClass,
1077+
tuple,
1078+
bytes,
1079+
schemas.FileIO
1080+
]]: ...
1081+
1082+
@typing.overload
1083+
def __getitem__(self, name: typing_extensions.Literal["date-time"]) -> DateTime[typing.Union[
1084+
frozendict.frozendict,
1085+
str,
1086+
decimal.Decimal,
1087+
schemas.BoolClass,
1088+
schemas.NoneClass,
1089+
tuple,
1090+
bytes,
1091+
schemas.FileIO
1092+
]]: ...
1093+
1094+
@typing.overload
1095+
def __getitem__(self, name: typing_extensions.Literal["number"]) -> Number[typing.Union[
1096+
frozendict.frozendict,
1097+
str,
1098+
decimal.Decimal,
1099+
schemas.BoolClass,
1100+
schemas.NoneClass,
1101+
tuple,
1102+
bytes,
1103+
schemas.FileIO
1104+
]]: ...
1105+
1106+
@typing.overload
1107+
def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Binary[typing.Union[
1108+
frozendict.frozendict,
1109+
str,
1110+
decimal.Decimal,
1111+
schemas.BoolClass,
1112+
schemas.NoneClass,
1113+
tuple,
1114+
bytes,
1115+
schemas.FileIO
1116+
]]: ...
1117+
1118+
@typing.overload
1119+
def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Int32[typing.Union[
1120+
frozendict.frozendict,
1121+
str,
1122+
decimal.Decimal,
1123+
schemas.BoolClass,
1124+
schemas.NoneClass,
1125+
tuple,
1126+
bytes,
1127+
schemas.FileIO
1128+
]]: ...
1129+
1130+
@typing.overload
1131+
def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Int64[typing.Union[
1132+
frozendict.frozendict,
1133+
str,
1134+
decimal.Decimal,
1135+
schemas.BoolClass,
1136+
schemas.NoneClass,
1137+
tuple,
1138+
bytes,
1139+
schemas.FileIO
1140+
]]: ...
1141+
1142+
@typing.overload
1143+
def __getitem__(self, name: typing_extensions.Literal["double"]) -> Double[typing.Union[
1144+
frozendict.frozendict,
1145+
str,
1146+
decimal.Decimal,
1147+
schemas.BoolClass,
1148+
schemas.NoneClass,
1149+
tuple,
1150+
bytes,
1151+
schemas.FileIO
1152+
]]: ...
1153+
1154+
@typing.overload
1155+
def __getitem__(self, name: typing_extensions.Literal["float"]) -> _Float[typing.Union[
1156+
frozendict.frozendict,
1157+
str,
1158+
decimal.Decimal,
1159+
schemas.BoolClass,
1160+
schemas.NoneClass,
1161+
tuple,
1162+
bytes,
1163+
schemas.FileIO
1164+
]]: ...
1165+
1166+
10561167
class AnyTypeAndFormat(
10571168
schemas.DictSchema[schemas.T]
10581169
):

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/api_response.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@
4242
]
4343

4444

45+
class ApiResponseDict(typing.Dict[str, typing.Any]):
46+
47+
@typing.overload
48+
def __getitem__(self, name: typing_extensions.Literal["code"]) -> Code[decimal.Decimal]: ...
49+
50+
@typing.overload
51+
def __getitem__(self, name: typing_extensions.Literal["type"]) -> Type[str]: ...
52+
53+
@typing.overload
54+
def __getitem__(self, name: typing_extensions.Literal["message"]) -> Message[str]: ...
55+
56+
4557
class ApiResponse(
4658
schemas.DictSchema[schemas.T]
4759
):

0 commit comments

Comments
 (0)