MCPcopy Index your code
hub / github.com/glideapps/quicktype / makeClass

Function makeClass

src/JSONSchemaInput.ts:268–298  ·  view source on GitHub ↗
(
        schema: StringMap,
        path: Ref,
        name: string,
        isInferred: boolean,
        properties: StringMap,
        requiredArray: string[]
    )

Source from the content-addressed store, hash-verified

266 }
267
268 function makeClass(
269 schema: StringMap,
270 path: Ref,
271 name: string,
272 isInferred: boolean,
273 properties: StringMap,
274 requiredArray: string[]
275 ): TypeRef {
276 const required = Set(requiredArray);
277 [name, isInferred] = getName(schema, name, isInferred);
278 const result = typeBuilder.getUniqueClassType(name, isInferred);
279 const c = assertIsClass(getHopefullyFinishedType(typeBuilder, result));
280 setTypeForPath(path, result);
281 // FIXME: We're using a Map instead of an OrderedMap here because we represent
282 // the JSON Schema as a JavaScript object, which has no map ordering. Ideally
283 // we would use a JSON parser that preserves order.
284 const props = Map(properties).map((propSchema, propName) => {
285 let t = toType(
286 checkStringMap(propSchema),
287 path.push({ kind: PathElementKind.Property, name: propName }),
288 pluralize.singular(propName),
289 true
290 );
291 if (!required.has(propName)) {
292 return typeBuilder.makeNullable(t, propName, true);
293 }
294 return t;
295 });
296 c.setProperties(props.toOrderedMap());
297 return result;
298 }
299
300 function makeMap(path: Ref, name: string, additional: StringMap): TypeRef {
301 let valuesType: TypeRef | undefined = undefined;

Callers 1

fromTypeNameFunction · 0.85

Calls 8

checkStringMapFunction · 0.90
getNameFunction · 0.85
assertIsClassFunction · 0.85
getHopefullyFinishedTypeFunction · 0.85
setTypeForPathFunction · 0.85
toTypeFunction · 0.85
setPropertiesMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…