Skip to content

Commit a351095

Browse files
authored
fix(go): reserve JSON union methods (#3508)
1 parent b3e6070 commit a351095

5 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎packages/quicktype-core/src/language/Golang/GolangRenderer.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ export class GoRenderer extends ConvenienceRenderer {
5858
return namingFunction;
5959
}
6060

61+
protected forbiddenForUnionMembers() {
62+
return {
63+
names:
64+
this._options.justTypes || this._options.justTypesAndPackage
65+
? []
66+
: ["MarshalJSON", "UnmarshalJSON"],
67+
includeGlobalForbidden: false,
68+
};
69+
}
70+
6171
protected makeEnumCaseNamer(): Namer {
6272
return namingFunction;
6373
}

‎test/inputs/json/priority/keywords.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
"lock": { "lock": 123 },
188188
"long": { "long": 123 },
189189
"map": { "map": 123 },
190+
"MarshalJSON": { "MarshalJSON": 123 },
190191
"MapEntry": { "MapEntry": 123 },
191192
"metadata_property_handling": { "metadata_property_handling": 123 },
192193
"module": { "module": 123 },
@@ -329,6 +330,7 @@
329330
"unchecked": { "unchecked": 123 },
330331
"undefined": { "undefined": 123 },
331332
"union": { "union": 123 },
333+
"UnmarshalJSON": { "UnmarshalJSON": 123 },
332334
"UseSerializers": { "UseSerializers": 123 },
333335
"unowned": { "unowned": 123 },
334336
"unsafe": { "unsafe": 123 },

‎test/inputs/schema/keyword-enum.schema‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"lock",
186186
"long",
187187
"map",
188+
"MarshalJSON",
188189
"MapEntry",
189190
"metadata_property_handling",
190191
"module",
@@ -321,6 +322,7 @@
321322
"unchecked",
322323
"undefined",
323324
"union",
325+
"UnmarshalJSON",
324326
"UseSerializers",
325327
"unowned",
326328
"unsafe",

‎test/inputs/schema/keyword-unions.schema‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,13 @@
12681268
],
12691269
"title": "union_map"
12701270
},
1271+
"MarshalJSON": {
1272+
"oneOf": [
1273+
{ "type": "number" },
1274+
{ "type": "object", "additionalProperties": false, "title": "MarshalJSON" }
1275+
],
1276+
"title": "union_MarshalJSON"
1277+
},
12711278
"MapEntry": {
12721279
"oneOf": [
12731280
{ "type": "number" },
@@ -2220,6 +2227,13 @@
22202227
],
22212228
"title": "union_union"
22222229
},
2230+
"UnmarshalJSON": {
2231+
"oneOf": [
2232+
{ "type": "number" },
2233+
{ "type": "object", "additionalProperties": false, "title": "UnmarshalJSON" }
2234+
],
2235+
"title": "union_UnmarshalJSON"
2236+
},
22232237
"UseSerializers": {
22242238
"oneOf": [
22252239
{ "type": "number" },

‎test/keywords.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Locale
179179
lock
180180
long
181181
map
182+
MarshalJSON
182183
MapEntry
183184
metadata_property_handling
184185
module
@@ -315,6 +316,7 @@ ulong
315316
unchecked
316317
undefined
317318
union
319+
UnmarshalJSON
318320
UseSerializers
319321
unowned
320322
unsafe

0 commit comments

Comments
 (0)