quicktype-core 23.0.170 → 23.0.171

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -99,7 +99,9 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
99
99
  const memberTypes = Array.from(nonNulls).map(m => this.pythonType(m));
100
100
  if (hasNull !== null) {
101
101
  let rest = [];
102
- if (!this.getAlphabetizeProperties() && this.pyOptions.features.dataClasses && _isRootTypeDef) {
102
+ if (!this.getAlphabetizeProperties() &&
103
+ (this.pyOptions.features.dataClasses || this.pyOptions.pydanticBaseModel) &&
104
+ _isRootTypeDef) {
103
105
  // Only push "= None" if this is a root level type def
104
106
  // otherwise we may get type defs like List[Optional[int] = None]
105
107
  // which are invalid
@@ -134,6 +136,9 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
134
136
  }
135
137
  declarationLine(t) {
136
138
  if (t instanceof Type_1.ClassType) {
139
+ if (this.pyOptions.pydanticBaseModel) {
140
+ return ["class ", this.nameForNamedType(t), "(", this.withImport("pydantic", "BaseModel"), "):"];
141
+ }
137
142
  return ["class ", this.nameForNamedType(t), ":"];
138
143
  }
139
144
  if (t instanceof Type_1.EnumType) {
@@ -149,7 +154,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
149
154
  this.declaredTypes.add(t);
150
155
  }
151
156
  emitClassMembers(t) {
152
- if (this.pyOptions.features.dataClasses)
157
+ if (this.pyOptions.features.dataClasses || this.pyOptions.pydanticBaseModel)
153
158
  return;
154
159
  const args = [];
155
160
  this.forEachClassProperty(t, "none", (name, _, cp) => {
@@ -179,7 +184,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
179
184
  return this.typeHint(" -> ", this.withTyping(type));
180
185
  }
181
186
  sortClassProperties(properties, propertyNames) {
182
- if (this.pyOptions.features.dataClasses) {
187
+ if (this.pyOptions.features.dataClasses || this.pyOptions.pydanticBaseModel) {
183
188
  return (0, collection_utils_1.mapSortBy)(properties, (p) => {
184
189
  return (p.type instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(p.type) != null) || p.isOptional ? 1 : 0;
185
190
  });
@@ -189,7 +194,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
189
194
  }
190
195
  }
191
196
  emitClass(t) {
192
- if (this.pyOptions.features.dataClasses) {
197
+ if (this.pyOptions.features.dataClasses && !this.pyOptions.pydanticBaseModel) {
193
198
  this.emitLine("@", this.withImport("dataclasses", "dataclass"));
194
199
  }
195
200
  this.declareType(t, () => {
@@ -13,6 +13,7 @@ export declare const pythonOptions: {
13
13
  features: EnumOption<PythonFeatures>;
14
14
  justTypes: BooleanOption;
15
15
  nicePropertyNames: BooleanOption;
16
+ pydanticBaseModel: BooleanOption;
16
17
  };
17
18
  export declare class PythonTargetLanguage extends TargetLanguage {
18
19
  protected getOptions(): Array<Option<FixMeOptionsAnyType>>;
@@ -14,11 +14,17 @@ exports.pythonOptions = {
14
14
  ["3.7", { typeHints: true, dataClasses: true }]
15
15
  ], "3.6"),
16
16
  justTypes: new RendererOptions_1.BooleanOption("just-types", "Classes only", false),
17
- nicePropertyNames: new RendererOptions_1.BooleanOption("nice-property-names", "Transform property names to be Pythonic", true)
17
+ nicePropertyNames: new RendererOptions_1.BooleanOption("nice-property-names", "Transform property names to be Pythonic", true),
18
+ pydanticBaseModel: new RendererOptions_1.BooleanOption("pydantic-base-model", "Uses pydantic BaseModel", false)
18
19
  };
19
20
  class PythonTargetLanguage extends TargetLanguage_1.TargetLanguage {
20
21
  getOptions() {
21
- return [exports.pythonOptions.features, exports.pythonOptions.justTypes, exports.pythonOptions.nicePropertyNames];
22
+ return [
23
+ exports.pythonOptions.features,
24
+ exports.pythonOptions.justTypes,
25
+ exports.pythonOptions.nicePropertyNames,
26
+ exports.pythonOptions.pydanticBaseModel
27
+ ];
22
28
  }
23
29
  get stringTypeMapping() {
24
30
  const mapping = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.170",
3
+ "version": "23.0.171",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",