From adcc152058daa11408aede97c17b32589f8dc845 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Mon, 29 Apr 2024 08:37:44 +0200 Subject: [PATCH] update snaps --- src/generators/kotlin/KotlinGenerator.ts | 4 +- src/helpers/MetaModelIterator.ts | 153 ------------------ .../KotlinGenerator.spec.ts.snap | 8 +- .../ConstraintsPreset.spec.ts.snap | 4 +- .../DescriptionPreset.spec.ts.snap | 2 +- .../PythonGenerator.spec.ts.snap | 55 ++----- .../__snapshots__/Pydantic.spec.ts.snap | 4 +- 7 files changed, 20 insertions(+), 210 deletions(-) delete mode 100644 src/helpers/MetaModelIterator.ts diff --git a/src/generators/kotlin/KotlinGenerator.ts b/src/generators/kotlin/KotlinGenerator.ts index 43665a28be..a3c23565af 100644 --- a/src/generators/kotlin/KotlinGenerator.ts +++ b/src/generators/kotlin/KotlinGenerator.ts @@ -75,10 +75,8 @@ const SAFE_MODEL_TYPES: any[] = [ ConstrainedStringModel, ConstrainedBooleanModel, ConstrainedTupleModel, - ConstrainedArrayModel, ConstrainedEnumModel, - ConstrainedUnionModel, - ConstrainedDictionaryModel + ConstrainedUnionModel ]; export class KotlinGenerator extends AbstractGenerator< diff --git a/src/helpers/MetaModelIterator.ts b/src/helpers/MetaModelIterator.ts deleted file mode 100644 index df0417db04..0000000000 --- a/src/helpers/MetaModelIterator.ts +++ /dev/null @@ -1,153 +0,0 @@ -// import { -// ConstrainedArrayModel, -// ConstrainedDictionaryModel, -// ConstrainedMetaModel, -// ConstrainedObjectModel, -// ConstrainedObjectPropertyModel, -// ConstrainedReferenceModel, -// ConstrainedTupleModel, -// ConstrainedUnionModel -// } from '../models'; - -// export type callbackType = (argument: { -// partOfProperty: ConstrainedObjectPropertyModel; -// constrainedModel: ConstrainedMetaModel; -// parentConstrainedModel: ConstrainedMetaModel; -// context: any; -// }) => { continue: boolean }; - -// function iterateMetaModel({ -// callback, -// constrainedModel, -// context -// }: { -// constrainedModel: ConstrainedMetaModel; -// callback: callbackType; -// context: any; -// }) { -// if (constrainedModel instanceof ConstrainedObjectModel) { -// for (const propertyModel of Object.values({ -// ...constrainedModel.properties -// })) { -// const returnType = callback({ -// constrainedModel: propertyModel.property, -// parentConstrainedModel: constrainedModel, -// partOfProperty: propertyModel, -// context -// }); -// if (returnType.continue) { -// iterateMetaModel({ -// callback, -// constrainedModel: propertyModel.property, -// context -// }); -// } -// } -// } else if (constrainedModel instanceof ConstrainedDictionaryModel) { -// } else if (constrainedModel instanceof ConstrainedTupleModel) { -// walkTupleNode(context); -// } else if (constrainedModel instanceof ConstrainedArrayModel) { -// walkArrayNode(context); -// } else if (constrainedModel instanceof ConstrainedUnionModel) { -// walkUnionNode(context); -// } else if (constrainedModel instanceof ConstrainedReferenceModel) { -// walkReferenceNode(context); -// } -// } - -// function walkDictionaryNode< -// GeneratorOptions, -// DependencyManager extends AbstractDependencyManager -// >(context: ApplyingTypesOptions) { -// const dictionaryModel = -// context.constrainedModel as ConstrainedDictionaryModel; - -// const overwriteKeyModel = applyTypes({ -// ...context, -// constrainedModel: dictionaryModel.key, -// partOfProperty: undefined -// }); -// if (overwriteKeyModel) { -// dictionaryModel.key = overwriteKeyModel; -// } -// const overWriteValueModel = applyTypes({ -// ...context, -// constrainedModel: dictionaryModel.value, -// partOfProperty: undefined -// }); -// if (overWriteValueModel) { -// dictionaryModel.value = overWriteValueModel; -// } -// } -// function walkTupleNode< -// GeneratorOptions, -// DependencyManager extends AbstractDependencyManager -// >(context: ApplyingTypesOptions) { -// const tupleModel = context.constrainedModel as ConstrainedTupleModel; - -// for (const [index, tupleMetaModel] of [...tupleModel.tuple].entries()) { -// const overwriteTupleModel = applyTypes({ -// ...context, -// constrainedModel: tupleMetaModel.value, -// partOfProperty: undefined -// }); -// if (overwriteTupleModel) { -// // eslint-disable-next-line security/detect-object-injection -// tupleModel.tuple[index].value = overwriteTupleModel; -// } -// } -// } - -// function walkArrayNode< -// GeneratorOptions, -// DependencyManager extends AbstractDependencyManager -// >(context: ApplyingTypesOptions) { -// const arrayModel = context.constrainedModel as ConstrainedArrayModel; -// const overWriteArrayModel = applyTypes({ -// ...context, -// constrainedModel: arrayModel.valueModel, -// partOfProperty: undefined, -// shouldWalkNode: true -// }); - -// if (overWriteArrayModel) { -// arrayModel.valueModel = overWriteArrayModel; -// } -// } - -// function walkUnionNode< -// GeneratorOptions, -// DependencyManager extends AbstractDependencyManager -// >(context: ApplyingTypesOptions) { -// const unionModel = context.constrainedModel as ConstrainedUnionModel; -// //If all union value models have type, we can go ahead and get the type for the union as well. -// for (const [index, unionValueModel] of [...unionModel.union].entries()) { -// const overwriteUnionModel = applyTypes({ -// ...context, -// constrainedModel: unionValueModel, -// partOfProperty: undefined, -// shouldWalkNode: true -// }); - -// if (overwriteUnionModel) { -// // eslint-disable-next-line security/detect-object-injection -// unionModel.union[index] = overwriteUnionModel; -// } -// } -// } - -// function walkReferenceNode< -// GeneratorOptions, -// DependencyManager extends AbstractDependencyManager -// >(context: ApplyingTypesOptions) { -// const referenceModel = context.constrainedModel as ConstrainedReferenceModel; -// const overwriteReference = applyTypes({ -// ...context, -// constrainedModel: referenceModel.ref, -// partOfProperty: undefined -// }); - -// if (overwriteReference) { -// referenceModel.ref = overwriteReference; -// } -// } diff --git a/test/generators/kotlin/__snapshots__/KotlinGenerator.spec.ts.snap b/test/generators/kotlin/__snapshots__/KotlinGenerator.spec.ts.snap index d0e6a16b7d..73030d4757 100644 --- a/test/generators/kotlin/__snapshots__/KotlinGenerator.spec.ts.snap +++ b/test/generators/kotlin/__snapshots__/KotlinGenerator.spec.ts.snap @@ -19,7 +19,7 @@ exports[`KotlinGenerator should render \`data class\` type 1`] = ` val time: java.time.OffsetTime? = null, val dateTime: java.time.OffsetDateTime? = null, val binary: ByteArray? = null, - val additionalProperties: Map<, >? = null, + val additionalProperties: Map? = null, )" `; @@ -55,7 +55,7 @@ exports[`KotlinGenerator should render \`enum\` type (union type) 1`] = ` exports[`KotlinGenerator should render List type for collections 1`] = ` "data class CustomClass( - val arrayType: List<>? = null, + val arrayType: List? = null, )" `; @@ -82,7 +82,7 @@ data class Address( val members: Any? = null, val arrayType: List, val otherModel: OtherModel? = null, - val additionalProperties: Map<, >? = null, + val additionalProperties: Map? = null, )" `; @@ -92,6 +92,6 @@ exports[`KotlinGenerator should render models and their dependencies 2`] = ` data class OtherModel( val streetName: String? = null, - val additionalProperties: Map<, >? = null, + val additionalProperties: Map? = null, )" `; diff --git a/test/generators/kotlin/presets/__snapshots__/ConstraintsPreset.spec.ts.snap b/test/generators/kotlin/presets/__snapshots__/ConstraintsPreset.spec.ts.snap index 955bd36288..e47ccb4e5d 100644 --- a/test/generators/kotlin/presets/__snapshots__/ConstraintsPreset.spec.ts.snap +++ b/test/generators/kotlin/presets/__snapshots__/ConstraintsPreset.spec.ts.snap @@ -9,10 +9,10 @@ exports[`KOTLIN_CONSTRAINTS_PRESET should render constraints annotations 1`] = ` @get:Max(99) val maxNumberProp: Double, @get:Size(min=2, max=3) - val arrayProp: List<>? = null, + val arrayProp: List? = null, @get:Pattern(regexp=\\"^I_\\") @get:Size(min=3) val stringProp: String? = null, - val additionalProperties: Map<, >? = null, + val additionalProperties: Map? = null, )" `; diff --git a/test/generators/kotlin/presets/__snapshots__/DescriptionPreset.spec.ts.snap b/test/generators/kotlin/presets/__snapshots__/DescriptionPreset.spec.ts.snap index aeeb5b3bb9..22bbeb3e4c 100644 --- a/test/generators/kotlin/presets/__snapshots__/DescriptionPreset.spec.ts.snap +++ b/test/generators/kotlin/presets/__snapshots__/DescriptionPreset.spec.ts.snap @@ -12,7 +12,7 @@ exports[`KOTLIN_DESCRIPTION_PRESET should render description and examples for cl */ data class Clazz( val prop: String? = null, - val additionalProperties: Map<, >? = null, + val additionalProperties: Map? = null, )" `; diff --git a/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap b/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap index 422db1f7ec..1d71794237 100644 --- a/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap +++ b/test/generators/python/__snapshots__/PythonGenerator.spec.ts.snap @@ -4,49 +4,14 @@ exports[`PythonGenerator Class should handle self reference models 1`] = ` "class Address: def __init__(self, input: Dict): if 'self_model' in input: - self._self_model: Address.Address = Address.Address(input['self_model']) + self._self_model: Address = Address(input['self_model']) if 'array_model' in input: - self._array_model: List[Address.Address] = input['array_model'] + self._array_model: List[Address] = input['array_model'] if 'tuple_model' in input: - self._tuple_model: tuple[Address.Address] = input['tuple_mode + self._tuple_model: tuple[Address, str] = input['tuple_model'] if 'map_model' in input: - self._map_model: dict[str, Address.Address] = input['map_model'] + self._map_model: dict[str, Address] = input['map_model'] if 'union_model' in input: - self._union_model: Address.Address = input['union_model'] - - @property - def self_model(self) -> 'Address'.Address: - return self._self_model - @self_model.setter - def self_model(self, self_model: 'Address'.Address): - self._self_model = self_model - - @property - def array_model(self) -> List['Address'.Address]: - return self._array_model - @array_model.setter - def array_model(self, array_model: List['Address'.Address]): - self._array_model = array_model - - @property - def tuple_model(self) -> tuple['Address'.Address]: - return self._tuple_model - @tuple_model.setter - def tuple_model(self, tuple_model: tuple['Address'.Address]): - self._tuple_model = tuple_model - - @property - def map_model(self) -> dict[str, 'Address'.Address]: - return self._map_model - @map_model.setter - def map_model(self, map_model: dict[str, 'Address'.Address]): - self._map_model = map_model - - @property - def union_model(self) -> 'Address'.Address: - return self._union_model - @union_model.setter - def union_model(self, union_model: 'Address'.Address): self._union_model: Address | str = input['union_model'] @property @@ -122,24 +87,24 @@ Array [ "class CoreSchemaMetaMinusSchemaObject: def __init__(self, input: Dict): if 'additional_items' in input: - self._additional_items: CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool = input['additional_items'] + self._additional_items: CoreSchemaMetaMinusSchemaObject | bool = input['additional_items'] if 'items' in input: - self._items: CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool | List[CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool] = input['items'] + self._items: CoreSchemaMetaMinusSchemaObject | bool | List[CoreSchemaMetaMinusSchemaObject | bool] = input['items'] if 'additional_properties' in input: self._additional_properties: dict[str, Any] = input['additional_properties'] @property - def additional_items(self) -> CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool: + def additional_items(self) -> CoreSchemaMetaMinusSchemaObject | bool: return self._additional_items @additional_items.setter - def additional_items(self, additional_items: CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool): + def additional_items(self, additional_items: CoreSchemaMetaMinusSchemaObject | bool): self._additional_items = additional_items @property - def items(self) -> CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool | List[CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool]: + def items(self) -> CoreSchemaMetaMinusSchemaObject | bool | List[CoreSchemaMetaMinusSchemaObject | bool]: return self._items @items.setter - def items(self, items: CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool | List[CoreSchemaMetaMinusSchemaObject.CoreSchemaMetaMinusSchemaObject | bool]): + def items(self, items: CoreSchemaMetaMinusSchemaObject | bool | List[CoreSchemaMetaMinusSchemaObject | bool]): self._items = items @property diff --git a/test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap b/test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap index b0624581b7..ece4fb83fc 100644 --- a/test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap +++ b/test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap @@ -13,8 +13,8 @@ exports[`PYTHON_PYDANTIC_PRESET should render pydantic for class 1`] = ` exports[`PYTHON_PYDANTIC_PRESET should render union to support Python < 3.10 1`] = ` Array [ "class UnionTest(BaseModel): - union_test: Optional[Union[Union1.Union1, Union2.Union2]] = Field(default=None, serialization_alias='unionTest') - additional_properties: Optional[dict[str, Any]] = Field(default=None, serialization_alias='additionalProperties', exclude=True) + union_test: Optional[Union[Union1.Union1, Union2.Union2]] = Field(default=None, alias='''unionTest''') + additional_properties: Optional[dict[str, Any]] = Field(exclude=True, default=None, alias='''additionalProperties''') ", "class Union1(BaseModel): test_prop1: Optional[str] = Field(default=None, alias='''testProp1''')