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

Class SimpleTypesRenderer

src/Language/SimpleTypes.ts:71–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71class SimpleTypesRenderer extends ConvenienceRenderer {
72 constructor(graph: TypeGraph, private readonly inlineUnions: boolean) {
73 super(graph);
74 }
75
76 protected topLevelNameStyle(rawName: string): string {
77 return simpleNameStyle(rawName, true);
78 }
79
80 protected get namedTypeNamer(): Namer {
81 return new Namer(n => simpleNameStyle(n, true), []);
82 }
83
84 protected get classPropertyNamer(): Namer {
85 return new Namer(n => simpleNameStyle(n, false), []);
86 }
87
88 protected get unionMemberNamer(): null {
89 return null;
90 }
91
92 protected get enumCaseNamer(): Namer {
93 return new Namer(n => simpleNameStyle(n, true), []);
94 }
95
96 protected namedTypeToNameForTopLevel(type: Type): NamedType | null {
97 if (type.isNamedType()) {
98 return type;
99 }
100 return null;
101 }
102
103 sourceFor = (t: Type): Sourcelike => {
104 return matchTypeExhaustive<Sourcelike>(
105 t,
106 _anyType => "Any",
107 _nullType => "Null",
108 _boolType => "Bool",
109 _integerType => "Int",
110 _doubleType => "Double",
111 _stringType => "String",
112 arrayType => ["List<", this.sourceFor(arrayType.items), ">"],
113 classType => this.nameForNamedType(classType),
114 mapType => ["Map<String, ", this.sourceFor(mapType.values), ">"],
115 enumType => this.nameForNamedType(enumType),
116 unionType => {
117 const nullable = nullableFromUnion(unionType);
118 if (nullable) return ["Maybe<", this.sourceFor(nullable), ">"];
119
120 if (this.inlineUnions) {
121 const children = unionType.children.map((c: Type) => this.sourceFor(c));
122 return intercalate(" | ", children).toArray();
123 } else {
124 return this.nameForNamedType(unionType);
125 }
126 },
127 _dateType => "Date",
128 _timeType => "Time",

Callers

nothing calls this directly

Calls 4

matchTypeExhaustiveFunction · 0.90
nullableFromUnionFunction · 0.90
intercalateFunction · 0.90
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…