MCPcopy Create free account
hub / github.com/glideapps/quicktype / makeClass

Method makeClass

src/JSONSchemaInput.ts:158–189  ·  view source on GitHub ↗
(classes: TypeRef[], maps: TypeRef[])

Source from the content-addressed store, hash-verified

156 }
157
158 protected makeClass(classes: TypeRef[], maps: TypeRef[]): TypeRef {
159 if (classes.length > 0 && maps.length > 0) {
160 return panic("Cannot handle a class type that's also a map");
161 }
162 if (maps.length > 0) {
163 return this.typeBuilder.getMapType(this._unifyTypes(maps, this.typeName, this.isInferred));
164 }
165 if (classes.length === 1) {
166 return classes[0];
167 }
168 let properties = OrderedMap<string, TypeRef[]>();
169 const actualClasses: ClassType[] = [];
170 for (const c of classes) {
171 const t = assertIsClass(getHopefullyFinishedType(this.typeBuilder, c));
172 actualClasses.push(t);
173 }
174 for (const c of actualClasses) {
175 c.properties.forEach((t, name) => {
176 const types = properties.get(name);
177 if (types === undefined) {
178 properties = properties.set(name, [t.typeRef]);
179 } else {
180 types.push(t.typeRef);
181 }
182 });
183 }
184 return this.typeBuilder.getUniqueClassType(
185 this.typeName,
186 this.isInferred,
187 properties.map((ts, name) => this._unifyTypes(ts, name, true)).sortBy((_, n) => n)
188 );
189 }
190
191 protected makeArray(arrays: TypeRef[]): TypeRef {
192 return this.typeBuilder.getArrayType(this._unifyTypes(arrays, pluralize.singular(this.typeName), true));

Callers

nothing calls this directly

Calls 4

panicFunction · 0.90
assertIsClassFunction · 0.85
getHopefullyFinishedTypeFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected