quicktype 18.0.6 → 19.0.4
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/README.md +1 -1
- package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
- package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
- package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
- package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
- package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
- package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
- package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
- package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
- package/dist/{cli/index.d.ts → index.d.ts} +1 -1
- package/dist/{cli/index.js → index.js} +4 -5
- package/package.json +61 -77
- package/dist/quicktype-core/Annotation.d.ts +0 -8
- package/dist/quicktype-core/Annotation.js +0 -16
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
- package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
- package/dist/quicktype-core/DateTime.d.ts +0 -10
- package/dist/quicktype-core/DateTime.js +0 -57
- package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
- package/dist/quicktype-core/DeclarationIR.js +0 -167
- package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
- package/dist/quicktype-core/GatherNames.d.ts +0 -2
- package/dist/quicktype-core/GatherNames.js +0 -333
- package/dist/quicktype-core/Graph.d.ts +0 -12
- package/dist/quicktype-core/Graph.js +0 -220
- package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
- package/dist/quicktype-core/GraphRewriting.js +0 -421
- package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
- package/dist/quicktype-core/MakeTransformations.js +0 -193
- package/dist/quicktype-core/MarkovChain.d.ts +0 -15
- package/dist/quicktype-core/MarkovChain.js +0 -154
- package/dist/quicktype-core/Messages.d.ts +0 -294
- package/dist/quicktype-core/Messages.js +0 -105
- package/dist/quicktype-core/Naming.d.ts +0 -64
- package/dist/quicktype-core/Naming.js +0 -356
- package/dist/quicktype-core/Renderer.d.ts +0 -50
- package/dist/quicktype-core/Renderer.js +0 -274
- package/dist/quicktype-core/RendererOptions.d.ts +0 -71
- package/dist/quicktype-core/RendererOptions.js +0 -141
- package/dist/quicktype-core/Run.d.ts +0 -174
- package/dist/quicktype-core/Run.js +0 -393
- package/dist/quicktype-core/Source.d.ts +0 -65
- package/dist/quicktype-core/Source.js +0 -204
- package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
- package/dist/quicktype-core/TargetLanguage.js +0 -66
- package/dist/quicktype-core/Transformers.d.ts +0 -209
- package/dist/quicktype-core/Transformers.js +0 -836
- package/dist/quicktype-core/Type.d.ts +0 -206
- package/dist/quicktype-core/Type.js +0 -716
- package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
- package/dist/quicktype-core/TypeBuilder.js +0 -324
- package/dist/quicktype-core/TypeGraph.d.ts +0 -75
- package/dist/quicktype-core/TypeGraph.js +0 -420
- package/dist/quicktype-core/TypeUtils.d.ts +0 -33
- package/dist/quicktype-core/TypeUtils.js +0 -230
- package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
- package/dist/quicktype-core/UnifyClasses.js +0 -159
- package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
- package/dist/quicktype-core/UnionBuilder.js +0 -282
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
- package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
- package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
- package/dist/quicktype-core/attributes/Constraints.js +0 -172
- package/dist/quicktype-core/attributes/Description.d.ts +0 -9
- package/dist/quicktype-core/attributes/Description.js +0 -97
- package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
- package/dist/quicktype-core/attributes/EnumValues.js +0 -31
- package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
- package/dist/quicktype-core/attributes/StringTypes.js +0 -189
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
- package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
- package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
- package/dist/quicktype-core/attributes/TypeNames.js +0 -274
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
- package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
- package/dist/quicktype-core/index.d.ts +0 -48
- package/dist/quicktype-core/index.js +0 -180
- package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
- package/dist/quicktype-core/input/CompressedJSON.js +0 -276
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
- package/dist/quicktype-core/input/Inference.d.ts +0 -22
- package/dist/quicktype-core/input/Inference.js +0 -240
- package/dist/quicktype-core/input/Inputs.d.ts +0 -48
- package/dist/quicktype-core/input/Inputs.js +0 -145
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
- package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
- package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
- package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
- package/dist/quicktype-core/input/PostmanCollection.js +0 -60
- package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
- package/dist/quicktype-core/input/io/NodeIO.js +0 -87
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
- package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
- package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
- package/dist/quicktype-core/language/All.d.ts +0 -3
- package/dist/quicktype-core/language/All.js +0 -57
- package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
- package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
- package/dist/quicktype-core/language/CSharp.d.ts +0 -201
- package/dist/quicktype-core/language/CSharp.js +0 -1850
- package/dist/quicktype-core/language/Crystal.d.ts +0 -37
- package/dist/quicktype-core/language/Crystal.js +0 -337
- package/dist/quicktype-core/language/Dart.d.ts +0 -66
- package/dist/quicktype-core/language/Dart.js +0 -576
- package/dist/quicktype-core/language/Elm.d.ts +0 -58
- package/dist/quicktype-core/language/Elm.js +0 -522
- package/dist/quicktype-core/language/Golang.d.ts +0 -51
- package/dist/quicktype-core/language/Golang.js +0 -460
- package/dist/quicktype-core/language/Haskell.d.ts +0 -56
- package/dist/quicktype-core/language/Haskell.js +0 -411
- package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
- package/dist/quicktype-core/language/JSONSchema.js +0 -169
- package/dist/quicktype-core/language/Java.d.ts +0 -125
- package/dist/quicktype-core/language/Java.js +0 -1081
- package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
- package/dist/quicktype-core/language/JavaScript.js +0 -435
- package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
- package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
- package/dist/quicktype-core/language/Kotlin.js +0 -832
- package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
- package/dist/quicktype-core/language/Objective-C.js +0 -777
- package/dist/quicktype-core/language/Php.d.ts +0 -80
- package/dist/quicktype-core/language/Php.js +0 -702
- package/dist/quicktype-core/language/Pike.d.ts +0 -37
- package/dist/quicktype-core/language/Pike.js +0 -276
- package/dist/quicktype-core/language/Python.d.ts +0 -107
- package/dist/quicktype-core/language/Python.js +0 -969
- package/dist/quicktype-core/language/Rust.d.ts +0 -56
- package/dist/quicktype-core/language/Rust.js +0 -309
- package/dist/quicktype-core/language/Swift.d.ts +0 -96
- package/dist/quicktype-core/language/Swift.js +0 -1211
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
- package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
- package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
- package/dist/quicktype-core/language/ruby/index.js +0 -557
- package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
- package/dist/quicktype-core/language/ruby/keywords.js +0 -358
- package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
- package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
- package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
- package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
- package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
- package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
- package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
- package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
- package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
- package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
- package/dist/quicktype-core/support/Acronyms.js +0 -1128
- package/dist/quicktype-core/support/Chance.d.ts +0 -38
- package/dist/quicktype-core/support/Chance.js +0 -2146
- package/dist/quicktype-core/support/Converters.d.ts +0 -6
- package/dist/quicktype-core/support/Converters.js +0 -16
- package/dist/quicktype-core/support/Strings.d.ts +0 -44
- package/dist/quicktype-core/support/Strings.js +0 -525
- package/dist/quicktype-core/support/Support.d.ts +0 -29
- package/dist/quicktype-core/support/Support.js +0 -162
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
- package/dist/quicktype-graphql-input/index.d.ts +0 -17
- package/dist/quicktype-graphql-input/index.js +0 -407
- package/dist/quicktype-typescript-input/index.d.ts +0 -2
- package/dist/quicktype-typescript-input/index.js +0 -98
|
@@ -1,460 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoRenderer = exports.GoTargetLanguage = exports.goOptions = void 0;
|
|
4
|
-
const Type_1 = require("../Type");
|
|
5
|
-
const TypeUtils_1 = require("../TypeUtils");
|
|
6
|
-
const Naming_1 = require("../Naming");
|
|
7
|
-
const Strings_1 = require("../support/Strings");
|
|
8
|
-
const Support_1 = require("../support/Support");
|
|
9
|
-
const RendererOptions_1 = require("../RendererOptions");
|
|
10
|
-
const Source_1 = require("../Source");
|
|
11
|
-
const Annotation_1 = require("../Annotation");
|
|
12
|
-
const TargetLanguage_1 = require("../TargetLanguage");
|
|
13
|
-
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
14
|
-
exports.goOptions = {
|
|
15
|
-
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
16
|
-
justTypesAndPackage: new RendererOptions_1.BooleanOption("just-types-and-package", "Plain types with package only", false),
|
|
17
|
-
packageName: new RendererOptions_1.StringOption("package", "Generated package name", "NAME", "main"),
|
|
18
|
-
multiFileOutput: new RendererOptions_1.BooleanOption("multi-file-output", "Renders each top-level object in its own Go file", false)
|
|
19
|
-
};
|
|
20
|
-
class GoTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
21
|
-
constructor() {
|
|
22
|
-
super("Go", ["go", "golang"], "go");
|
|
23
|
-
}
|
|
24
|
-
getOptions() {
|
|
25
|
-
return [exports.goOptions.justTypes, exports.goOptions.packageName, exports.goOptions.multiFileOutput, exports.goOptions.justTypesAndPackage];
|
|
26
|
-
}
|
|
27
|
-
get supportsUnionsWithBothNumberTypes() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
get supportsOptionalClassProperties() {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
makeRenderer(renderContext, untypedOptionValues) {
|
|
34
|
-
return new GoRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.goOptions, untypedOptionValues));
|
|
35
|
-
}
|
|
36
|
-
get defaultIndentation() {
|
|
37
|
-
return "\t";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.GoTargetLanguage = GoTargetLanguage;
|
|
41
|
-
const namingFunction = (0, Naming_1.funPrefixNamer)("namer", goNameStyle);
|
|
42
|
-
const legalizeName = (0, Strings_1.legalizeCharacters)(Strings_1.isLetterOrUnderscoreOrDigit);
|
|
43
|
-
function goNameStyle(original) {
|
|
44
|
-
const words = (0, Strings_1.splitIntoWords)(original);
|
|
45
|
-
return (0, Strings_1.combineWords)(words, legalizeName, Strings_1.firstUpperWordStyle, Strings_1.firstUpperWordStyle, Strings_1.allUpperWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
|
|
46
|
-
}
|
|
47
|
-
const primitiveValueTypeKinds = ["integer", "double", "bool", "string"];
|
|
48
|
-
const compoundTypeKinds = ["array", "class", "map", "enum"];
|
|
49
|
-
function isValueType(t) {
|
|
50
|
-
const kind = t.kind;
|
|
51
|
-
return primitiveValueTypeKinds.indexOf(kind) >= 0 || kind === "class" || kind === "enum";
|
|
52
|
-
}
|
|
53
|
-
function canOmitEmpty(cp) {
|
|
54
|
-
if (!cp.isOptional)
|
|
55
|
-
return false;
|
|
56
|
-
const t = cp.type;
|
|
57
|
-
return ["union", "null", "any"].indexOf(t.kind) < 0;
|
|
58
|
-
}
|
|
59
|
-
class GoRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
60
|
-
_options;
|
|
61
|
-
_topLevelUnmarshalNames = new Map();
|
|
62
|
-
_currentFilename;
|
|
63
|
-
constructor(targetLanguage, renderContext, _options) {
|
|
64
|
-
super(targetLanguage, renderContext);
|
|
65
|
-
this._options = _options;
|
|
66
|
-
}
|
|
67
|
-
makeNamedTypeNamer() {
|
|
68
|
-
return namingFunction;
|
|
69
|
-
}
|
|
70
|
-
namerForObjectProperty() {
|
|
71
|
-
return namingFunction;
|
|
72
|
-
}
|
|
73
|
-
makeUnionMemberNamer() {
|
|
74
|
-
return namingFunction;
|
|
75
|
-
}
|
|
76
|
-
makeEnumCaseNamer() {
|
|
77
|
-
return namingFunction;
|
|
78
|
-
}
|
|
79
|
-
get enumCasesInGlobalNamespace() {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
makeTopLevelDependencyNames(_, topLevelName) {
|
|
83
|
-
const unmarshalName = new Naming_1.DependencyName(namingFunction, topLevelName.order, lookup => `unmarshal_${lookup(topLevelName)}`);
|
|
84
|
-
this._topLevelUnmarshalNames.set(topLevelName, unmarshalName);
|
|
85
|
-
return [unmarshalName];
|
|
86
|
-
}
|
|
87
|
-
/// startFile takes a file name, lowercases it, appends ".go" to it, and sets it as the current filename.
|
|
88
|
-
startFile(basename) {
|
|
89
|
-
if (this._options.multiFileOutput === false) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
(0, Support_1.assert)(this._currentFilename === undefined, "Previous file wasn't finished: " + this._currentFilename);
|
|
93
|
-
// FIXME: The filenames should actually be Sourcelikes, too
|
|
94
|
-
this._currentFilename = `${this.sourcelikeToString(basename)}.go`.toLowerCase();
|
|
95
|
-
this.initializeEmitContextForFilename(this._currentFilename);
|
|
96
|
-
}
|
|
97
|
-
/// endFile pushes the current file name onto the collection of finished files and then resets the current file name. These finished files are used in index.ts to write the output.
|
|
98
|
-
endFile() {
|
|
99
|
-
if (this._options.multiFileOutput === false) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.finishFile((0, Support_1.defined)(this._currentFilename));
|
|
103
|
-
this._currentFilename = undefined;
|
|
104
|
-
}
|
|
105
|
-
emitBlock(line, f) {
|
|
106
|
-
this.emitLine(line, " {");
|
|
107
|
-
this.indent(f);
|
|
108
|
-
this.emitLine("}");
|
|
109
|
-
}
|
|
110
|
-
emitFunc(decl, f) {
|
|
111
|
-
this.emitBlock(["func ", decl], f);
|
|
112
|
-
}
|
|
113
|
-
emitStruct(name, table) {
|
|
114
|
-
this.emitBlock(["type ", name, " struct"], () => this.emitTable(table));
|
|
115
|
-
}
|
|
116
|
-
nullableGoType(t, withIssues) {
|
|
117
|
-
const goType = this.goType(t, withIssues);
|
|
118
|
-
if (isValueType(t)) {
|
|
119
|
-
return ["*", goType];
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return goType;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
propertyGoType(cp) {
|
|
126
|
-
const t = cp.type;
|
|
127
|
-
if (t instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(t) === null) {
|
|
128
|
-
return ["*", this.goType(t, true)];
|
|
129
|
-
}
|
|
130
|
-
if (cp.isOptional) {
|
|
131
|
-
return this.nullableGoType(t, true);
|
|
132
|
-
}
|
|
133
|
-
return this.goType(t, true);
|
|
134
|
-
}
|
|
135
|
-
goType(t, withIssues = false) {
|
|
136
|
-
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, "interface{}"), _nullType => (0, 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
|
-
let valueSource;
|
|
138
|
-
const v = mapType.values;
|
|
139
|
-
if (v instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(v) === null) {
|
|
140
|
-
valueSource = ["*", this.nameForNamedType(v)];
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
valueSource = this.goType(v, withIssues);
|
|
144
|
-
}
|
|
145
|
-
return ["map[string]", valueSource];
|
|
146
|
-
}, enumType => this.nameForNamedType(enumType), unionType => {
|
|
147
|
-
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
148
|
-
if (nullable !== null)
|
|
149
|
-
return this.nullableGoType(nullable, withIssues);
|
|
150
|
-
return this.nameForNamedType(unionType);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
emitTopLevel(t, name) {
|
|
154
|
-
this.startFile(name);
|
|
155
|
-
if (this._options.multiFileOutput &&
|
|
156
|
-
this._options.justTypes === false &&
|
|
157
|
-
this._options.justTypesAndPackage === false &&
|
|
158
|
-
this.leadingComments === undefined) {
|
|
159
|
-
this.emitLineOnce("// This file was generated from JSON Schema using quicktype, do not modify it directly.");
|
|
160
|
-
this.emitLineOnce("// To parse and unparse this JSON data, add this code to your project and do:");
|
|
161
|
-
this.emitLineOnce("//");
|
|
162
|
-
const ref = (0, Source_1.modifySource)(Strings_1.camelCase, name);
|
|
163
|
-
this.emitLineOnce("// ", ref, ", err := ", (0, Support_1.defined)(this._topLevelUnmarshalNames.get(name)), "(bytes)");
|
|
164
|
-
this.emitLineOnce("// bytes, err = ", ref, ".Marshal()");
|
|
165
|
-
}
|
|
166
|
-
this.emitPackageDefinitons(true);
|
|
167
|
-
const unmarshalName = (0, Support_1.defined)(this._topLevelUnmarshalNames.get(name));
|
|
168
|
-
if (this.namedTypeToNameForTopLevel(t) === undefined) {
|
|
169
|
-
this.emitLine("type ", name, " ", this.goType(t));
|
|
170
|
-
}
|
|
171
|
-
if (this._options.justTypes || this._options.justTypesAndPackage)
|
|
172
|
-
return;
|
|
173
|
-
this.ensureBlankLine();
|
|
174
|
-
this.emitFunc([unmarshalName, "(data []byte) (", name, ", error)"], () => {
|
|
175
|
-
this.emitLine("var r ", name);
|
|
176
|
-
this.emitLine("err := json.Unmarshal(data, &r)");
|
|
177
|
-
this.emitLine("return r, err");
|
|
178
|
-
});
|
|
179
|
-
this.ensureBlankLine();
|
|
180
|
-
this.emitFunc(["(r *", name, ") Marshal() ([]byte, error)"], () => {
|
|
181
|
-
this.emitLine("return json.Marshal(r)");
|
|
182
|
-
});
|
|
183
|
-
this.endFile();
|
|
184
|
-
}
|
|
185
|
-
emitClass(c, className) {
|
|
186
|
-
this.startFile(className);
|
|
187
|
-
this.emitPackageDefinitons(false);
|
|
188
|
-
let columns = [];
|
|
189
|
-
this.forEachClassProperty(c, "none", (name, jsonName, p) => {
|
|
190
|
-
const description = this.descriptionForClassProperty(c, jsonName);
|
|
191
|
-
const docStrings = description !== undefined && description.length > 0 ? description.map(d => "// " + d) : [];
|
|
192
|
-
const goType = this.propertyGoType(p);
|
|
193
|
-
const omitEmpty = canOmitEmpty(p) ? ",omitempty" : [];
|
|
194
|
-
docStrings.forEach(doc => columns.push([doc]));
|
|
195
|
-
columns.push([
|
|
196
|
-
[name, " "],
|
|
197
|
-
[goType, " "],
|
|
198
|
-
['`json:"', (0, Strings_1.stringEscape)(jsonName), omitEmpty, '"`']
|
|
199
|
-
]);
|
|
200
|
-
});
|
|
201
|
-
this.emitDescription(this.descriptionForType(c));
|
|
202
|
-
this.emitStruct(className, columns);
|
|
203
|
-
this.endFile();
|
|
204
|
-
}
|
|
205
|
-
emitEnum(e, enumName) {
|
|
206
|
-
this.startFile(enumName);
|
|
207
|
-
this.emitPackageDefinitons(false);
|
|
208
|
-
this.emitDescription(this.descriptionForType(e));
|
|
209
|
-
this.emitLine("type ", enumName, " string");
|
|
210
|
-
this.emitLine("const (");
|
|
211
|
-
this.indent(() => this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
212
|
-
this.emitLine(name, " ", enumName, ' = "', (0, Strings_1.stringEscape)(jsonName), '"');
|
|
213
|
-
}));
|
|
214
|
-
this.emitLine(")");
|
|
215
|
-
this.endFile();
|
|
216
|
-
}
|
|
217
|
-
emitUnion(u, unionName) {
|
|
218
|
-
this.startFile(unionName);
|
|
219
|
-
this.emitPackageDefinitons(false);
|
|
220
|
-
const [hasNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
221
|
-
const isNullableArg = hasNull !== null ? "true" : "false";
|
|
222
|
-
const ifMember = (kind, ifNotMember, f) => {
|
|
223
|
-
const maybeType = u.findMember(kind);
|
|
224
|
-
if (maybeType === undefined)
|
|
225
|
-
return ifNotMember;
|
|
226
|
-
return f(maybeType, this.nameForUnionMember(u, maybeType), this.goType(maybeType));
|
|
227
|
-
};
|
|
228
|
-
const maybeAssignNil = (kind) => {
|
|
229
|
-
ifMember(kind, undefined, (_1, fieldName, _2) => {
|
|
230
|
-
this.emitLine("x.", fieldName, " = nil");
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
const makeArgs = (primitiveArg, compoundArg) => {
|
|
234
|
-
const args = [];
|
|
235
|
-
for (const kind of primitiveValueTypeKinds) {
|
|
236
|
-
args.push(ifMember(kind, "nil", (_1, fieldName, _2) => primitiveArg(fieldName)), ", ");
|
|
237
|
-
}
|
|
238
|
-
for (const kind of compoundTypeKinds) {
|
|
239
|
-
args.push(ifMember(kind, "false, nil", (t, fieldName, _) => compoundArg(t.kind === "class", fieldName)), ", ");
|
|
240
|
-
}
|
|
241
|
-
args.push(isNullableArg);
|
|
242
|
-
return args;
|
|
243
|
-
};
|
|
244
|
-
let columns = [];
|
|
245
|
-
this.forEachUnionMember(u, nonNulls, "none", null, (fieldName, t) => {
|
|
246
|
-
const goType = this.nullableGoType(t, true);
|
|
247
|
-
columns.push([[fieldName, " "], goType]);
|
|
248
|
-
});
|
|
249
|
-
this.emitDescription(this.descriptionForType(u));
|
|
250
|
-
this.emitStruct(unionName, columns);
|
|
251
|
-
if (this._options.justTypes || this._options.justTypesAndPackage)
|
|
252
|
-
return;
|
|
253
|
-
this.ensureBlankLine();
|
|
254
|
-
this.emitFunc(["(x *", unionName, ") UnmarshalJSON(data []byte) error"], () => {
|
|
255
|
-
for (const kind of compoundTypeKinds) {
|
|
256
|
-
maybeAssignNil(kind);
|
|
257
|
-
}
|
|
258
|
-
ifMember("class", undefined, (_1, _2, goType) => {
|
|
259
|
-
this.emitLine("var c ", goType);
|
|
260
|
-
});
|
|
261
|
-
const args = makeArgs(fn => ["&x.", fn], (isClass, fn) => {
|
|
262
|
-
if (isClass) {
|
|
263
|
-
return "true, &c";
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
return ["true, &x.", fn];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
this.emitLine("object, err := unmarshalUnion(data, ", args, ")");
|
|
270
|
-
this.emitBlock("if err != nil", () => {
|
|
271
|
-
this.emitLine("return err");
|
|
272
|
-
});
|
|
273
|
-
this.emitBlock("if object", () => {
|
|
274
|
-
ifMember("class", undefined, (_1, fieldName, _2) => {
|
|
275
|
-
this.emitLine("x.", fieldName, " = &c");
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
this.emitLine("return nil");
|
|
279
|
-
});
|
|
280
|
-
this.ensureBlankLine();
|
|
281
|
-
this.emitFunc(["(x *", unionName, ") MarshalJSON() ([]byte, error)"], () => {
|
|
282
|
-
const args = makeArgs(fn => ["x.", fn], (_, fn) => ["x.", fn, " != nil, x.", fn]);
|
|
283
|
-
this.emitLine("return marshalUnion(", args, ")");
|
|
284
|
-
});
|
|
285
|
-
this.endFile();
|
|
286
|
-
}
|
|
287
|
-
emitSingleFileHeaderComments() {
|
|
288
|
-
this.emitLineOnce("// This file was generated from JSON Schema using quicktype, do not modify it directly.");
|
|
289
|
-
this.emitLineOnce("// To parse and unparse this JSON data, add this code to your project and do:");
|
|
290
|
-
this.forEachTopLevel("none", (_, name) => {
|
|
291
|
-
this.emitLine("//");
|
|
292
|
-
const ref = (0, Source_1.modifySource)(Strings_1.camelCase, name);
|
|
293
|
-
this.emitLine("// ", ref, ", err := ", (0, Support_1.defined)(this._topLevelUnmarshalNames.get(name)), "(bytes)");
|
|
294
|
-
this.emitLine("// bytes, err = ", ref, ".Marshal()");
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
emitPackageDefinitons(includeJSONEncodingImport) {
|
|
298
|
-
if (!this._options.justTypes || this._options.justTypesAndPackage) {
|
|
299
|
-
this.ensureBlankLine();
|
|
300
|
-
const packageDeclaration = "package " + this._options.packageName;
|
|
301
|
-
this.emitLineOnce(packageDeclaration);
|
|
302
|
-
this.ensureBlankLine();
|
|
303
|
-
}
|
|
304
|
-
if (!this._options.justTypes && !this._options.justTypesAndPackage) {
|
|
305
|
-
this.ensureBlankLine();
|
|
306
|
-
if (this.haveNamedUnions && this._options.multiFileOutput === false) {
|
|
307
|
-
this.emitLineOnce('import "bytes"');
|
|
308
|
-
this.emitLineOnce('import "errors"');
|
|
309
|
-
}
|
|
310
|
-
if (includeJSONEncodingImport) {
|
|
311
|
-
this.emitLineOnce('import "encoding/json"');
|
|
312
|
-
}
|
|
313
|
-
this.ensureBlankLine();
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
emitHelperFunctions() {
|
|
317
|
-
if (this.haveNamedUnions) {
|
|
318
|
-
this.startFile("JSONSchemaSupport");
|
|
319
|
-
this.emitPackageDefinitons(true);
|
|
320
|
-
if (this._options.multiFileOutput) {
|
|
321
|
-
this.emitLineOnce('import "bytes"');
|
|
322
|
-
this.emitLineOnce('import "errors"');
|
|
323
|
-
}
|
|
324
|
-
this.ensureBlankLine();
|
|
325
|
-
this
|
|
326
|
-
.emitMultiline(`func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) (bool, error) {
|
|
327
|
-
if pi != nil {
|
|
328
|
-
*pi = nil
|
|
329
|
-
}
|
|
330
|
-
if pf != nil {
|
|
331
|
-
*pf = nil
|
|
332
|
-
}
|
|
333
|
-
if pb != nil {
|
|
334
|
-
*pb = nil
|
|
335
|
-
}
|
|
336
|
-
if ps != nil {
|
|
337
|
-
*ps = nil
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
dec := json.NewDecoder(bytes.NewReader(data))
|
|
341
|
-
dec.UseNumber()
|
|
342
|
-
tok, err := dec.Token()
|
|
343
|
-
if err != nil {
|
|
344
|
-
return false, err
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
switch v := tok.(type) {
|
|
348
|
-
case json.Number:
|
|
349
|
-
if pi != nil {
|
|
350
|
-
i, err := v.Int64()
|
|
351
|
-
if err == nil {
|
|
352
|
-
*pi = &i
|
|
353
|
-
return false, nil
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if pf != nil {
|
|
357
|
-
f, err := v.Float64()
|
|
358
|
-
if err == nil {
|
|
359
|
-
*pf = &f
|
|
360
|
-
return false, nil
|
|
361
|
-
}
|
|
362
|
-
return false, errors.New("Unparsable number")
|
|
363
|
-
}
|
|
364
|
-
return false, errors.New("Union does not contain number")
|
|
365
|
-
case float64:
|
|
366
|
-
return false, errors.New("Decoder should not return float64")
|
|
367
|
-
case bool:
|
|
368
|
-
if pb != nil {
|
|
369
|
-
*pb = &v
|
|
370
|
-
return false, nil
|
|
371
|
-
}
|
|
372
|
-
return false, errors.New("Union does not contain bool")
|
|
373
|
-
case string:
|
|
374
|
-
if haveEnum {
|
|
375
|
-
return false, json.Unmarshal(data, pe)
|
|
376
|
-
}
|
|
377
|
-
if ps != nil {
|
|
378
|
-
*ps = &v
|
|
379
|
-
return false, nil
|
|
380
|
-
}
|
|
381
|
-
return false, errors.New("Union does not contain string")
|
|
382
|
-
case nil:
|
|
383
|
-
if nullable {
|
|
384
|
-
return false, nil
|
|
385
|
-
}
|
|
386
|
-
return false, errors.New("Union does not contain null")
|
|
387
|
-
case json.Delim:
|
|
388
|
-
if v == '{' {
|
|
389
|
-
if haveObject {
|
|
390
|
-
return true, json.Unmarshal(data, pc)
|
|
391
|
-
}
|
|
392
|
-
if haveMap {
|
|
393
|
-
return false, json.Unmarshal(data, pm)
|
|
394
|
-
}
|
|
395
|
-
return false, errors.New("Union does not contain object")
|
|
396
|
-
}
|
|
397
|
-
if v == '[' {
|
|
398
|
-
if haveArray {
|
|
399
|
-
return false, json.Unmarshal(data, pa)
|
|
400
|
-
}
|
|
401
|
-
return false, errors.New("Union does not contain array")
|
|
402
|
-
}
|
|
403
|
-
return false, errors.New("Cannot handle delimiter")
|
|
404
|
-
}
|
|
405
|
-
return false, errors.New("Cannot unmarshal union")
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) ([]byte, error) {
|
|
410
|
-
if pi != nil {
|
|
411
|
-
return json.Marshal(*pi)
|
|
412
|
-
}
|
|
413
|
-
if pf != nil {
|
|
414
|
-
return json.Marshal(*pf)
|
|
415
|
-
}
|
|
416
|
-
if pb != nil {
|
|
417
|
-
return json.Marshal(*pb)
|
|
418
|
-
}
|
|
419
|
-
if ps != nil {
|
|
420
|
-
return json.Marshal(*ps)
|
|
421
|
-
}
|
|
422
|
-
if haveArray {
|
|
423
|
-
return json.Marshal(pa)
|
|
424
|
-
}
|
|
425
|
-
if haveObject {
|
|
426
|
-
return json.Marshal(pc)
|
|
427
|
-
}
|
|
428
|
-
if haveMap {
|
|
429
|
-
return json.Marshal(pm)
|
|
430
|
-
}
|
|
431
|
-
if haveEnum {
|
|
432
|
-
return json.Marshal(pe)
|
|
433
|
-
}
|
|
434
|
-
if nullable {
|
|
435
|
-
return json.Marshal(nil)
|
|
436
|
-
}
|
|
437
|
-
return nil, errors.New("Union must not be null")
|
|
438
|
-
}`);
|
|
439
|
-
this.endFile();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
emitSourceStructure() {
|
|
443
|
-
if (this._options.multiFileOutput === false &&
|
|
444
|
-
this._options.justTypes === false &&
|
|
445
|
-
this._options.justTypesAndPackage === false &&
|
|
446
|
-
this.leadingComments === undefined) {
|
|
447
|
-
this.emitSingleFileHeaderComments();
|
|
448
|
-
}
|
|
449
|
-
this.forEachTopLevel("leading-and-interposing", (t, name) => this.emitTopLevel(t, name), t => !(this._options.justTypes || this._options.justTypesAndPackage) ||
|
|
450
|
-
this.namedTypeToNameForTopLevel(t) === undefined);
|
|
451
|
-
this.forEachObject("leading-and-interposing", (c, className) => this.emitClass(c, className));
|
|
452
|
-
this.forEachEnum("leading-and-interposing", (u, enumName) => this.emitEnum(u, enumName));
|
|
453
|
-
this.forEachUnion("leading-and-interposing", (u, unionName) => this.emitUnion(u, unionName));
|
|
454
|
-
if (this._options.justTypes || this._options.justTypesAndPackage) {
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
this.emitHelperFunctions();
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
exports.GoRenderer = GoRenderer;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { TargetLanguage } from "../TargetLanguage";
|
|
2
|
-
import { EnumOption, StringOption, BooleanOption, Option, OptionValues } from "../RendererOptions";
|
|
3
|
-
import { Type, ClassType, UnionType } from "../Type";
|
|
4
|
-
import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer";
|
|
5
|
-
import { Namer, Name } from "../Naming";
|
|
6
|
-
import { Sourcelike } from "../Source";
|
|
7
|
-
import { RenderContext } from "../Renderer";
|
|
8
|
-
export declare const haskellOptions: {
|
|
9
|
-
justTypes: BooleanOption;
|
|
10
|
-
useList: EnumOption<boolean>;
|
|
11
|
-
moduleName: StringOption;
|
|
12
|
-
};
|
|
13
|
-
export declare class HaskellTargetLanguage extends TargetLanguage {
|
|
14
|
-
constructor();
|
|
15
|
-
protected getOptions(): Option<any>[];
|
|
16
|
-
get supportsOptionalClassProperties(): boolean;
|
|
17
|
-
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
18
|
-
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
19
|
-
[name: string]: any;
|
|
20
|
-
}): HaskellRenderer;
|
|
21
|
-
}
|
|
22
|
-
export declare class HaskellRenderer extends ConvenienceRenderer {
|
|
23
|
-
private readonly _options;
|
|
24
|
-
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _options: OptionValues<typeof haskellOptions>);
|
|
25
|
-
protected forbiddenNamesForGlobalNamespace(): string[];
|
|
26
|
-
protected makeNamedTypeNamer(): Namer;
|
|
27
|
-
protected namerForObjectProperty(): Namer;
|
|
28
|
-
protected forbiddenForObjectProperties(_c: ClassType, _className: Name): ForbiddenWordsInfo;
|
|
29
|
-
protected makeUnionMemberNamer(): Namer;
|
|
30
|
-
protected get unionMembersInGlobalNamespace(): boolean;
|
|
31
|
-
protected makeEnumCaseNamer(): Namer;
|
|
32
|
-
protected get enumCasesInGlobalNamespace(): boolean;
|
|
33
|
-
protected proposeUnionMemberName(u: UnionType, unionName: Name, fieldType: Type, lookup: (n: Name) => string): string;
|
|
34
|
-
protected get commentLineStart(): string;
|
|
35
|
-
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
36
|
-
private haskellType;
|
|
37
|
-
private haskellProperty;
|
|
38
|
-
private encoderNameForType;
|
|
39
|
-
private emitTopLevelDefinition;
|
|
40
|
-
private emitClassDefinition;
|
|
41
|
-
private emitEnumDefinition;
|
|
42
|
-
private emitUnionDefinition;
|
|
43
|
-
private emitTopLevelFunctions;
|
|
44
|
-
private classPropertyLength;
|
|
45
|
-
private emitClassEncoderInstance;
|
|
46
|
-
private emitClassDecoderInstance;
|
|
47
|
-
private emitClassFunctions;
|
|
48
|
-
private emitEnumEncoderInstance;
|
|
49
|
-
private emitEnumDecoderInstance;
|
|
50
|
-
private emitEnumFunctions;
|
|
51
|
-
private emitUnionEncoderInstance;
|
|
52
|
-
private emitUnionDecoderInstance;
|
|
53
|
-
private emitUnionFunctions;
|
|
54
|
-
private emitLanguageExtensions;
|
|
55
|
-
protected emitSourceStructure(): void;
|
|
56
|
-
}
|