quicktype 17.0.3 → 17.0.5
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.
- package/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -14,12 +14,12 @@ export declare const goOptions: {
|
|
|
14
14
|
export declare class GoTargetLanguage extends TargetLanguage {
|
|
15
15
|
constructor();
|
|
16
16
|
protected getOptions(): Option<any>[];
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
readonly supportsUnionsWithBothNumberTypes: boolean;
|
|
18
|
+
readonly supportsOptionalClassProperties: boolean;
|
|
19
19
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
20
20
|
[name: string]: any;
|
|
21
21
|
}): GoRenderer;
|
|
22
|
-
protected
|
|
22
|
+
protected readonly defaultIndentation: string;
|
|
23
23
|
}
|
|
24
24
|
export declare class GoRenderer extends ConvenienceRenderer {
|
|
25
25
|
private readonly _options;
|
|
@@ -30,7 +30,7 @@ export declare class GoRenderer extends ConvenienceRenderer {
|
|
|
30
30
|
protected namerForObjectProperty(): Namer;
|
|
31
31
|
protected makeUnionMemberNamer(): Namer;
|
|
32
32
|
protected makeEnumCaseNamer(): Namer;
|
|
33
|
-
protected
|
|
33
|
+
protected readonly enumCasesInGlobalNamespace: boolean;
|
|
34
34
|
protected makeTopLevelDependencyNames(_: Type, topLevelName: Name): DependencyName[];
|
|
35
35
|
protected startFile(basename: Sourcelike): void;
|
|
36
36
|
protected endFile(): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoRenderer = exports.GoTargetLanguage = exports.goOptions = void 0;
|
|
4
3
|
const Type_1 = require("../Type");
|
|
5
4
|
const TypeUtils_1 = require("../TypeUtils");
|
|
6
5
|
const Naming_1 = require("../Naming");
|
|
@@ -31,18 +30,18 @@ class GoTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
31
30
|
return true;
|
|
32
31
|
}
|
|
33
32
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
34
|
-
return new GoRenderer(this, renderContext,
|
|
33
|
+
return new GoRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.goOptions, untypedOptionValues));
|
|
35
34
|
}
|
|
36
35
|
get defaultIndentation() {
|
|
37
36
|
return "\t";
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
exports.GoTargetLanguage = GoTargetLanguage;
|
|
41
|
-
const namingFunction =
|
|
42
|
-
const legalizeName =
|
|
40
|
+
const namingFunction = Naming_1.funPrefixNamer("namer", goNameStyle);
|
|
41
|
+
const legalizeName = Strings_1.legalizeCharacters(Strings_1.isLetterOrUnderscoreOrDigit);
|
|
43
42
|
function goNameStyle(original) {
|
|
44
|
-
const words =
|
|
45
|
-
return
|
|
43
|
+
const words = Strings_1.splitIntoWords(original);
|
|
44
|
+
return Strings_1.combineWords(words, legalizeName, Strings_1.firstUpperWordStyle, Strings_1.firstUpperWordStyle, Strings_1.allUpperWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
|
|
46
45
|
}
|
|
47
46
|
const primitiveValueTypeKinds = ["integer", "double", "bool", "string"];
|
|
48
47
|
const compoundTypeKinds = ["array", "class", "map", "enum"];
|
|
@@ -57,12 +56,10 @@ function canOmitEmpty(cp) {
|
|
|
57
56
|
return ["union", "null", "any"].indexOf(t.kind) < 0;
|
|
58
57
|
}
|
|
59
58
|
class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
60
|
-
_options;
|
|
61
|
-
_topLevelUnmarshalNames = new Map();
|
|
62
|
-
_currentFilename;
|
|
63
59
|
constructor(targetLanguage, renderContext, _options) {
|
|
64
60
|
super(targetLanguage, renderContext);
|
|
65
61
|
this._options = _options;
|
|
62
|
+
this._topLevelUnmarshalNames = new Map();
|
|
66
63
|
}
|
|
67
64
|
makeNamedTypeNamer() {
|
|
68
65
|
return namingFunction;
|
|
@@ -89,7 +86,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
89
86
|
if (this._options.multiFileOutput === false) {
|
|
90
87
|
return;
|
|
91
88
|
}
|
|
92
|
-
|
|
89
|
+
Support_1.assert(this._currentFilename === undefined, "Previous file wasn't finished: " + this._currentFilename);
|
|
93
90
|
// FIXME: The filenames should actually be Sourcelikes, too
|
|
94
91
|
this._currentFilename = `${this.sourcelikeToString(basename)}.go`.toLowerCase();
|
|
95
92
|
this.initializeEmitContextForFilename(this._currentFilename);
|
|
@@ -99,7 +96,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
99
96
|
if (this._options.multiFileOutput === false) {
|
|
100
97
|
return;
|
|
101
98
|
}
|
|
102
|
-
this.finishFile(
|
|
99
|
+
this.finishFile(Support_1.defined(this._currentFilename));
|
|
103
100
|
this._currentFilename = undefined;
|
|
104
101
|
}
|
|
105
102
|
emitBlock(line, f) {
|
|
@@ -124,7 +121,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
124
121
|
}
|
|
125
122
|
propertyGoType(cp) {
|
|
126
123
|
const t = cp.type;
|
|
127
|
-
if (t instanceof Type_1.UnionType &&
|
|
124
|
+
if (t instanceof Type_1.UnionType && TypeUtils_1.nullableFromUnion(t) === null) {
|
|
128
125
|
return ["*", this.goType(t, true)];
|
|
129
126
|
}
|
|
130
127
|
if (cp.isOptional) {
|
|
@@ -133,10 +130,10 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
133
130
|
return this.goType(t, true);
|
|
134
131
|
}
|
|
135
132
|
goType(t, withIssues = false) {
|
|
136
|
-
return
|
|
133
|
+
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "interface{}"), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "interface{}"), _boolType => "bool", _integerType => "int64", _doubleType => "float64", _stringType => "string", arrayType => ["[]", this.goType(arrayType.items, withIssues)], classType => this.nameForNamedType(classType), mapType => {
|
|
137
134
|
let valueSource;
|
|
138
135
|
const v = mapType.values;
|
|
139
|
-
if (v instanceof Type_1.UnionType &&
|
|
136
|
+
if (v instanceof Type_1.UnionType && TypeUtils_1.nullableFromUnion(v) === null) {
|
|
140
137
|
valueSource = ["*", this.nameForNamedType(v)];
|
|
141
138
|
}
|
|
142
139
|
else {
|
|
@@ -144,7 +141,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
144
141
|
}
|
|
145
142
|
return ["map[string]", valueSource];
|
|
146
143
|
}, enumType => this.nameForNamedType(enumType), unionType => {
|
|
147
|
-
const nullable =
|
|
144
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
148
145
|
if (nullable !== null)
|
|
149
146
|
return this.nullableGoType(nullable, withIssues);
|
|
150
147
|
return this.nameForNamedType(unionType);
|
|
@@ -159,12 +156,12 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
159
156
|
this.emitLineOnce("// This file was generated from JSON Schema using quicktype, do not modify it directly.");
|
|
160
157
|
this.emitLineOnce("// To parse and unparse this JSON data, add this code to your project and do:");
|
|
161
158
|
this.emitLineOnce("//");
|
|
162
|
-
const ref =
|
|
163
|
-
this.emitLineOnce("// ", ref, ", err := ",
|
|
159
|
+
const ref = Source_1.modifySource(Strings_1.camelCase, name);
|
|
160
|
+
this.emitLineOnce("// ", ref, ", err := ", Support_1.defined(this._topLevelUnmarshalNames.get(name)), "(bytes)");
|
|
164
161
|
this.emitLineOnce("// bytes, err = ", ref, ".Marshal()");
|
|
165
162
|
}
|
|
166
163
|
this.emitPackageDefinitons(true);
|
|
167
|
-
const unmarshalName =
|
|
164
|
+
const unmarshalName = Support_1.defined(this._topLevelUnmarshalNames.get(name));
|
|
168
165
|
if (this.namedTypeToNameForTopLevel(t) === undefined) {
|
|
169
166
|
this.emitLine("type ", name, " ", this.goType(t));
|
|
170
167
|
}
|
|
@@ -195,7 +192,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
195
192
|
columns.push([
|
|
196
193
|
[name, " "],
|
|
197
194
|
[goType, " "],
|
|
198
|
-
['`json:"',
|
|
195
|
+
['`json:"', Strings_1.stringEscape(jsonName), omitEmpty, '"`']
|
|
199
196
|
]);
|
|
200
197
|
});
|
|
201
198
|
this.emitDescription(this.descriptionForType(c));
|
|
@@ -209,7 +206,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
209
206
|
this.emitLine("type ", enumName, " string");
|
|
210
207
|
this.emitLine("const (");
|
|
211
208
|
this.indent(() => this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
212
|
-
this.emitLine(name, " ", enumName, ' = "',
|
|
209
|
+
this.emitLine(name, " ", enumName, ' = "', Strings_1.stringEscape(jsonName), '"');
|
|
213
210
|
}));
|
|
214
211
|
this.emitLine(")");
|
|
215
212
|
this.endFile();
|
|
@@ -217,7 +214,7 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
217
214
|
emitUnion(u, unionName) {
|
|
218
215
|
this.startFile(unionName);
|
|
219
216
|
this.emitPackageDefinitons(false);
|
|
220
|
-
const [hasNull, nonNulls] =
|
|
217
|
+
const [hasNull, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
221
218
|
const isNullableArg = hasNull !== null ? "true" : "false";
|
|
222
219
|
const ifMember = (kind, ifNotMember, f) => {
|
|
223
220
|
const maybeType = u.findMember(kind);
|
|
@@ -289,8 +286,8 @@ class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
289
286
|
this.emitLineOnce("// To parse and unparse this JSON data, add this code to your project and do:");
|
|
290
287
|
this.forEachTopLevel("none", (_, name) => {
|
|
291
288
|
this.emitLine("//");
|
|
292
|
-
const ref =
|
|
293
|
-
this.emitLine("// ", ref, ", err := ",
|
|
289
|
+
const ref = Source_1.modifySource(Strings_1.camelCase, name);
|
|
290
|
+
this.emitLine("// ", ref, ", err := ", Support_1.defined(this._topLevelUnmarshalNames.get(name)), "(bytes)");
|
|
294
291
|
this.emitLine("// bytes, err = ", ref, ".Marshal()");
|
|
295
292
|
});
|
|
296
293
|
}
|
|
@@ -13,8 +13,8 @@ export declare const haskellOptions: {
|
|
|
13
13
|
export declare class HaskellTargetLanguage extends TargetLanguage {
|
|
14
14
|
constructor();
|
|
15
15
|
protected getOptions(): Option<any>[];
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
readonly supportsOptionalClassProperties: boolean;
|
|
17
|
+
readonly supportsUnionsWithBothNumberTypes: boolean;
|
|
18
18
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
19
19
|
[name: string]: any;
|
|
20
20
|
}): HaskellRenderer;
|
|
@@ -27,11 +27,11 @@ export declare class HaskellRenderer extends ConvenienceRenderer {
|
|
|
27
27
|
protected namerForObjectProperty(): Namer;
|
|
28
28
|
protected forbiddenForObjectProperties(_c: ClassType, _className: Name): ForbiddenWordsInfo;
|
|
29
29
|
protected makeUnionMemberNamer(): Namer;
|
|
30
|
-
protected
|
|
30
|
+
protected readonly unionMembersInGlobalNamespace: boolean;
|
|
31
31
|
protected makeEnumCaseNamer(): Namer;
|
|
32
|
-
protected
|
|
32
|
+
protected readonly enumCasesInGlobalNamespace: boolean;
|
|
33
33
|
protected proposeUnionMemberName(u: UnionType, unionName: Name, fieldType: Type, lookup: (n: Name) => string): string;
|
|
34
|
-
protected
|
|
34
|
+
protected readonly commentLineStart: string;
|
|
35
35
|
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
36
36
|
private haskellType;
|
|
37
37
|
private haskellProperty;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HaskellRenderer = exports.HaskellTargetLanguage = exports.haskellOptions = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
6
5
|
const RendererOptions_1 = require("../RendererOptions");
|
|
@@ -31,7 +30,7 @@ class HaskellTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
31
30
|
return true;
|
|
32
31
|
}
|
|
33
32
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
34
|
-
return new HaskellRenderer(this, renderContext,
|
|
33
|
+
return new HaskellRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.haskellOptions, untypedOptionValues));
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
exports.HaskellTargetLanguage = HaskellTargetLanguage;
|
|
@@ -89,15 +88,14 @@ const forbiddenNames = [
|
|
|
89
88
|
"Series",
|
|
90
89
|
"Error"
|
|
91
90
|
];
|
|
92
|
-
const legalizeName =
|
|
91
|
+
const legalizeName = Strings_1.legalizeCharacters(cp => Strings_1.isAscii(cp) && Strings_1.isLetterOrUnderscoreOrDigit(cp));
|
|
93
92
|
function haskellNameStyle(original, upper) {
|
|
94
|
-
const words =
|
|
95
|
-
return
|
|
93
|
+
const words = Strings_1.splitIntoWords(original);
|
|
94
|
+
return Strings_1.combineWords(words, legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
|
|
96
95
|
}
|
|
97
|
-
const upperNamingFunction =
|
|
98
|
-
const lowerNamingFunction =
|
|
96
|
+
const upperNamingFunction = Naming_1.funPrefixNamer("upper", n => haskellNameStyle(n, true));
|
|
97
|
+
const lowerNamingFunction = Naming_1.funPrefixNamer("lower", n => haskellNameStyle(n, false));
|
|
99
98
|
class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
100
|
-
_options;
|
|
101
99
|
constructor(targetLanguage, renderContext, _options) {
|
|
102
100
|
super(targetLanguage, renderContext);
|
|
103
101
|
this._options = _options;
|
|
@@ -142,32 +140,32 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
142
|
haskellType(t, noOptional = false) {
|
|
145
|
-
return
|
|
143
|
+
return TypeUtils_1.matchType(t, _anyType => Source_1.multiWord(" ", "Maybe", "Text"), _nullType => Source_1.multiWord(" ", "Maybe", "Text"), _boolType => Source_1.singleWord("Bool"), _integerType => Source_1.singleWord("Int"), _doubleType => Source_1.singleWord("Float"), _stringType => Source_1.singleWord("Text"), arrayType => {
|
|
146
144
|
if (this._options.useList) {
|
|
147
|
-
return
|
|
145
|
+
return Source_1.multiWord("", "[", Source_1.parenIfNeeded(this.haskellType(arrayType.items)), "]");
|
|
148
146
|
}
|
|
149
|
-
return
|
|
150
|
-
}, classType =>
|
|
151
|
-
const nullable =
|
|
147
|
+
return Source_1.multiWord(" ", "Vector", Source_1.parenIfNeeded(this.haskellType(arrayType.items)));
|
|
148
|
+
}, classType => Source_1.singleWord(this.nameForNamedType(classType)), mapType => Source_1.multiWord(" ", "HashMap Text", Source_1.parenIfNeeded(this.haskellType(mapType.values))), enumType => Source_1.singleWord(this.nameForNamedType(enumType)), unionType => {
|
|
149
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
152
150
|
if (nullable !== null) {
|
|
153
151
|
const nullableType = this.haskellType(nullable);
|
|
154
152
|
if (noOptional)
|
|
155
153
|
return nullableType;
|
|
156
|
-
return
|
|
154
|
+
return Source_1.multiWord(" ", "Maybe", Source_1.parenIfNeeded(nullableType));
|
|
157
155
|
}
|
|
158
|
-
return
|
|
156
|
+
return Source_1.singleWord(this.nameForNamedType(unionType));
|
|
159
157
|
});
|
|
160
158
|
}
|
|
161
159
|
haskellProperty(p) {
|
|
162
160
|
if (p.isOptional) {
|
|
163
|
-
return
|
|
161
|
+
return Source_1.multiWord(" ", "Maybe", Source_1.parenIfNeeded(this.haskellType(p.type, true))).source;
|
|
164
162
|
}
|
|
165
163
|
else {
|
|
166
164
|
return this.haskellType(p.type).source;
|
|
167
165
|
}
|
|
168
166
|
}
|
|
169
167
|
encoderNameForType(t) {
|
|
170
|
-
return
|
|
168
|
+
return TypeUtils_1.matchType(t, _anyType => Source_1.singleWord("String"), _nullType => Source_1.singleWord("Null"), _boolType => Source_1.singleWord("Bool"), _integerType => Source_1.singleWord("Number"), _doubleType => Source_1.singleWord("Number"), _stringType => Source_1.singleWord("String"), _arrayType => Source_1.singleWord("Array"), _classType => Source_1.singleWord("Object"), _mapType => Source_1.singleWord("Object"), _enumType => Source_1.singleWord("Object"), _unionType => Source_1.singleWord("Object"));
|
|
171
169
|
}
|
|
172
170
|
emitTopLevelDefinition(t, topLevelName) {
|
|
173
171
|
this.emitLine("type ", topLevelName, " = ", this.haskellType(t).source);
|
|
@@ -225,7 +223,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
225
223
|
this.emitLine(equalsOrPipe, " ", constructor);
|
|
226
224
|
}
|
|
227
225
|
else {
|
|
228
|
-
this.emitLine(equalsOrPipe, " ", constructor, " ",
|
|
226
|
+
this.emitLine(equalsOrPipe, " ", constructor, " ", Source_1.parenIfNeeded(this.haskellType(t)));
|
|
229
227
|
}
|
|
230
228
|
onFirst = false;
|
|
231
229
|
});
|
|
@@ -261,7 +259,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
261
259
|
this.emitLine("object");
|
|
262
260
|
let onFirst = true;
|
|
263
261
|
this.forEachClassProperty(c, "none", (name, jsonName) => {
|
|
264
|
-
this.emitLine(onFirst ? "[ " : ", ", '"',
|
|
262
|
+
this.emitLine(onFirst ? "[ " : ", ", '"', Strings_1.stringEscape(jsonName), '" .= ', name, className);
|
|
265
263
|
onFirst = false;
|
|
266
264
|
});
|
|
267
265
|
if (onFirst) {
|
|
@@ -284,7 +282,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
284
282
|
let onFirst = true;
|
|
285
283
|
this.forEachClassProperty(c, "none", (_, jsonName, p) => {
|
|
286
284
|
const operator = p.isOptional ? ".:?" : ".:";
|
|
287
|
-
this.emitLine(onFirst ? "<$> " : "<*> ", "v ", operator, ' "',
|
|
285
|
+
this.emitLine(onFirst ? "<$> " : "<*> ", "v ", operator, ' "', Strings_1.stringEscape(jsonName), '"');
|
|
288
286
|
onFirst = false;
|
|
289
287
|
});
|
|
290
288
|
});
|
|
@@ -300,7 +298,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
300
298
|
this.emitLine("instance ToJSON ", enumName, " where");
|
|
301
299
|
this.indent(() => {
|
|
302
300
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
303
|
-
this.emitLine("toJSON ", name, enumName, ' = "',
|
|
301
|
+
this.emitLine("toJSON ", name, enumName, ' = "', Strings_1.stringEscape(jsonName), '"');
|
|
304
302
|
});
|
|
305
303
|
});
|
|
306
304
|
}
|
|
@@ -312,7 +310,7 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
312
310
|
this.emitLine("where");
|
|
313
311
|
this.indent(() => {
|
|
314
312
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
315
|
-
this.emitLine('parseText "',
|
|
313
|
+
this.emitLine('parseText "', Strings_1.stringEscape(jsonName), '" = return ', name, enumName);
|
|
316
314
|
});
|
|
317
315
|
});
|
|
318
316
|
});
|
|
@@ -363,15 +361,15 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
363
361
|
exports.push([name, " (..)"]);
|
|
364
362
|
});
|
|
365
363
|
this.forEachObject("none", (t, name) => {
|
|
366
|
-
if (!
|
|
364
|
+
if (!collection_utils_1.mapContains(this.topLevels, t))
|
|
367
365
|
exports.push([name, " (..)"]);
|
|
368
366
|
});
|
|
369
367
|
this.forEachEnum("none", (t, name) => {
|
|
370
|
-
if (!
|
|
368
|
+
if (!collection_utils_1.mapContains(this.topLevels, t))
|
|
371
369
|
exports.push([name, " (..)"]);
|
|
372
370
|
});
|
|
373
371
|
this.forEachUnion("none", (t, name) => {
|
|
374
|
-
if (!
|
|
372
|
+
if (!collection_utils_1.mapContains(this.topLevels, t))
|
|
375
373
|
exports.push([name, " (..)"]);
|
|
376
374
|
});
|
|
377
375
|
this.emitLanguageExtensions("StrictData");
|
|
@@ -7,9 +7,9 @@ import { RenderContext } from "../Renderer";
|
|
|
7
7
|
export declare class JSONSchemaTargetLanguage extends TargetLanguage {
|
|
8
8
|
constructor();
|
|
9
9
|
protected getOptions(): Option<any>[];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
readonly stringTypeMapping: StringTypeMapping;
|
|
11
|
+
readonly supportsOptionalClassProperties: boolean;
|
|
12
|
+
readonly supportsFullObjectType: boolean;
|
|
13
13
|
protected makeRenderer(renderContext: RenderContext, _untypedOptionValues: {
|
|
14
14
|
[name: string]: any;
|
|
15
15
|
}): JSONSchemaRenderer;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONSchemaRenderer = exports.JSONSchemaTargetLanguage = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
6
5
|
const Type_1 = require("../Type");
|
|
@@ -19,7 +18,7 @@ class JSONSchemaTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
19
18
|
return [];
|
|
20
19
|
}
|
|
21
20
|
get stringTypeMapping() {
|
|
22
|
-
return
|
|
21
|
+
return TypeBuilder_1.getNoStringTypeMapping();
|
|
23
22
|
}
|
|
24
23
|
get supportsOptionalClassProperties() {
|
|
25
24
|
return true;
|
|
@@ -32,11 +31,11 @@ class JSONSchemaTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
exports.JSONSchemaTargetLanguage = JSONSchemaTargetLanguage;
|
|
35
|
-
const namingFunction =
|
|
36
|
-
const legalizeName =
|
|
34
|
+
const namingFunction = Naming_1.funPrefixNamer("namer", jsonNameStyle);
|
|
35
|
+
const legalizeName = Strings_1.legalizeCharacters(cp => cp >= 32 && cp < 128 && cp !== 0x2f /* slash */);
|
|
37
36
|
function jsonNameStyle(original) {
|
|
38
|
-
const words =
|
|
39
|
-
return
|
|
37
|
+
const words = Strings_1.splitIntoWords(original);
|
|
38
|
+
return Strings_1.combineWords(words, legalizeName, Strings_1.firstUpperWordStyle, Strings_1.firstUpperWordStyle, Strings_1.allUpperWordStyle, Strings_1.allUpperWordStyle, "", _ => true);
|
|
40
39
|
}
|
|
41
40
|
class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
42
41
|
makeNamedTypeNamer() {
|
|
@@ -52,12 +51,12 @@ class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
52
51
|
return null;
|
|
53
52
|
}
|
|
54
53
|
nameForType(t) {
|
|
55
|
-
return
|
|
54
|
+
return Support_1.defined(this.names.get(this.nameForNamedType(t)));
|
|
56
55
|
}
|
|
57
56
|
makeOneOf(types) {
|
|
58
|
-
const first =
|
|
57
|
+
const first = collection_utils_1.iterableFirst(types);
|
|
59
58
|
if (first === undefined) {
|
|
60
|
-
return
|
|
59
|
+
return Support_1.panic("Must have at least one type for oneOf");
|
|
61
60
|
}
|
|
62
61
|
if (types.size === 1) {
|
|
63
62
|
return this.schemaForType(first);
|
|
@@ -74,8 +73,8 @@ class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
schemaForType(t) {
|
|
77
|
-
const schema =
|
|
78
|
-
return
|
|
76
|
+
const schema = TypeUtils_1.matchTypeExhaustive(t, _noneType => {
|
|
77
|
+
return Support_1.panic("none type should have been replaced");
|
|
79
78
|
}, _anyType => ({}), _nullType => ({ type: "null" }), _boolType => ({ type: "boolean" }), _integerType => ({ type: "integer" }), _doubleType => ({ type: "number" }), _stringType => ({ type: "string" }), arrayType => ({ type: "array", items: this.schemaForType(arrayType.items) }), classType => this.makeRef(classType), mapType => this.definitionForObject(mapType, undefined), objectType => this.makeRef(objectType), enumType => this.makeRef(enumType), unionType => {
|
|
80
79
|
if (this.unionNeedsName(unionType)) {
|
|
81
80
|
return this.makeRef(unionType);
|
|
@@ -86,7 +85,7 @@ class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
86
85
|
}, transformedStringType => {
|
|
87
86
|
const target = Type_1.transformedStringTypeTargetTypeKindsMap.get(transformedStringType.kind);
|
|
88
87
|
if (target === undefined) {
|
|
89
|
-
return
|
|
88
|
+
return Support_1.panic(`Unknown transformed string type ${transformedStringType.kind}`);
|
|
90
89
|
}
|
|
91
90
|
return { type: "string", format: target.jsonSchema };
|
|
92
91
|
});
|
|
@@ -108,7 +107,7 @@ class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
108
107
|
for (const [name, p] of o.getProperties()) {
|
|
109
108
|
const prop = this.schemaForType(p.type);
|
|
110
109
|
if (prop.description === undefined) {
|
|
111
|
-
|
|
110
|
+
Description_1.addDescriptionToSchema(prop, this.descriptionForClassProperty(o, name));
|
|
112
111
|
}
|
|
113
112
|
props[name] = prop;
|
|
114
113
|
if (!p.isOptional) {
|
|
@@ -145,21 +144,21 @@ class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
145
144
|
}
|
|
146
145
|
emitSourceStructure() {
|
|
147
146
|
// FIXME: Find a good way to do multiple top-levels. Maybe multiple files?
|
|
148
|
-
const topLevelType = this.topLevels.size === 1 ? this.schemaForType(
|
|
147
|
+
const topLevelType = this.topLevels.size === 1 ? this.schemaForType(Support_1.defined(collection_utils_1.mapFirst(this.topLevels))) : {};
|
|
149
148
|
const schema = Object.assign({ $schema: "http://json-schema.org/draft-06/schema#" }, topLevelType);
|
|
150
149
|
const definitions = {};
|
|
151
150
|
this.forEachObject("none", (o, name) => {
|
|
152
|
-
const title =
|
|
151
|
+
const title = Support_1.defined(this.names.get(name));
|
|
153
152
|
definitions[title] = this.definitionForObject(o, title);
|
|
154
153
|
});
|
|
155
154
|
this.forEachUnion("none", (u, name) => {
|
|
156
155
|
if (!this.unionNeedsName(u))
|
|
157
156
|
return;
|
|
158
|
-
const title =
|
|
157
|
+
const title = Support_1.defined(this.names.get(name));
|
|
159
158
|
definitions[title] = this.definitionForUnion(u, title);
|
|
160
159
|
});
|
|
161
160
|
this.forEachEnum("none", (e, name) => {
|
|
162
|
-
const title =
|
|
161
|
+
const title = Support_1.defined(this.names.get(name));
|
|
163
162
|
definitions[title] = this.definitionForEnum(e, title);
|
|
164
163
|
});
|
|
165
164
|
schema.definitions = definitions;
|
|
@@ -19,11 +19,11 @@ export declare const javaOptions: {
|
|
|
19
19
|
export declare class JavaTargetLanguage extends TargetLanguage {
|
|
20
20
|
constructor();
|
|
21
21
|
protected getOptions(): Option<any>[];
|
|
22
|
-
|
|
22
|
+
readonly supportsUnionsWithBothNumberTypes: boolean;
|
|
23
23
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
24
24
|
[name: string]: any;
|
|
25
25
|
}): JavaRenderer;
|
|
26
|
-
|
|
26
|
+
readonly stringTypeMapping: StringTypeMapping;
|
|
27
27
|
}
|
|
28
28
|
export declare const stringEscape: (s: string) => string;
|
|
29
29
|
export declare function javaNameStyle(startWithUpper: boolean, upperUnderscore: boolean, original: string, acronymsStyle?: (s: string) => string): string;
|