Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
3test cases
98files differ
46modified
37new
15deleted
5,838changed lines
+3,308 −2,530insertions / deletions
Base a49b94e8f6f1b319a4da9fb15d57ef13ba316ddc · PR merge c2372b380ffb3fad627550d0c8adbb2acdc172ee · Head d07ad3b8c5ad367416c5627c388d290cc8a292c9 · raw patch
Test case

test/inputs/schema/recursive-ref-to-id.schema

31 generated files · +2,452 −0
Aschema-cplusplusdefault / quicktype.hpp+151 −0
@@ -0,0 +1,151 @@
1+// To parse this JSON data, first install
2+//
3+// json.hpp https://github.com/nlohmann/json
4+//
5+// Then include this file, and then do
6+//
7+// TopLevel data = nlohmann::json::parse(jsonString);
8+
9+#pragma once
10+
11+#include <optional>
12+#include "json.hpp"
13+
14+#include <optional>
15+#include <stdexcept>
16+#include <regex>
17+
18+#ifndef NLOHMANN_OPT_HELPER
19+#define NLOHMANN_OPT_HELPER
20+namespace nlohmann {
21+ template <typename T>
22+ struct adl_serializer<std::shared_ptr<T>> {
23+ static void to_json(json & j, const std::shared_ptr<T> & opt) {
24+ if (!opt) j = nullptr; else j = *opt;
25+ }
26+
27+ static std::shared_ptr<T> from_json(const json & j) {
28+ if (j.is_null()) return std::shared_ptr<T>(); else return std::make_shared<T>(j.get<T>());
29+ }
30+ };
31+ template <typename T>
32+ struct adl_serializer<std::optional<T>> {
33+ static void to_json(json & j, const std::optional<T> & opt) {
34+ if (!opt) j = nullptr; else j = *opt;
35+ }
36+
37+ static std::optional<T> from_json(const json & j) {
38+ if (j.is_null()) return std::optional<T>(); else return std::make_optional<T>(j.get<T>());
39+ }
40+ };
41+}
42+#endif
43+
44+namespace quicktype {
45+ using nlohmann::json;
46+
47+ #ifndef NLOHMANN_UNTYPED_quicktype_HELPER
48+ #define NLOHMANN_UNTYPED_quicktype_HELPER
49+ inline json get_untyped(const json & j, const char * property) {
50+ if (j.find(property) != j.end()) {
51+ return j.at(property).get<json>();
52+ }
53+ return json();
54+ }
55+
56+ inline json get_untyped(const json & j, std::string property) {
57+ return get_untyped(j, property.data());
58+ }
59+ #endif
60+
61+ #ifndef NLOHMANN_OPTIONAL_quicktype_HELPER
62+ #define NLOHMANN_OPTIONAL_quicktype_HELPER
63+ template <typename T>
64+ inline std::shared_ptr<T> get_heap_optional(const json & j, const char * property) {
65+ auto it = j.find(property);
66+ if (it != j.end() && !it->is_null()) {
67+ return j.at(property).get<std::shared_ptr<T>>();
68+ }
69+ return std::shared_ptr<T>();
70+ }
71+
72+ template <typename T>
73+ inline std::shared_ptr<T> get_heap_optional(const json & j, std::string property) {
74+ return get_heap_optional<T>(j, property.data());
75+ }
76+ template <typename T>
77+ inline std::optional<T> get_stack_optional(const json & j, const char * property) {
78+ auto it = j.find(property);
79+ if (it != j.end() && !it->is_null()) {
80+ return j.at(property).get<std::optional<T>>();
81+ }
82+ return std::optional<T>();
83+ }
84+
85+ template <typename T>
86+ inline std::optional<T> get_stack_optional(const json & j, std::string property) {
87+ return get_stack_optional<T>(j, property.data());
88+ }
89+ #endif
90+
91+ class Data {
92+ public:
93+ Data() = default;
94+ virtual ~Data() = default;
95+
96+ private:
97+ std::optional<std::string> id;
98+
99+ public:
100+ const std::optional<std::string> & get_id() const { return id; }
101+ std::optional<std::string> & get_mutable_id() { return id; }
102+ void set_id(const std::optional<std::string> & value) { this->id = value; }
103+ };
104+
105+ class TopLevel {
106+ public:
107+ TopLevel() = default;
108+ virtual ~TopLevel() = default;
109+
110+ private:
111+ std::optional<std::vector<TopLevel>> children;
112+ std::optional<Data> data;
113+
114+ public:
115+ const std::optional<std::vector<TopLevel>> & get_children() const { return children; }
116+ std::optional<std::vector<TopLevel>> & get_mutable_children() { return children; }
117+ void set_children(const std::optional<std::vector<TopLevel>> & value) { this->children = value; }
118+
119+ const std::optional<Data> & get_data() const { return data; }
120+ std::optional<Data> & get_mutable_data() { return data; }
121+ void set_data(const std::optional<Data> & value) { this->data = value; }
122+ };
123+}
124+
125+namespace quicktype {
126+ void from_json(const json & j, Data & x);
127+ void to_json(json & j, const Data & x);
128+
129+ void from_json(const json & j, TopLevel & x);
130+ void to_json(json & j, const TopLevel & x);
131+
132+ inline void from_json(const json & j, Data& x) {
133+ x.set_id(get_stack_optional<std::string>(j, "id"));
134+ }
135+
136+ inline void to_json(json & j, const Data & x) {
137+ j = json::object();
138+ j["id"] = x.get_id();
139+ }
140+
141+ inline void from_json(const json & j, TopLevel& x) {
142+ x.set_children(get_stack_optional<std::vector<TopLevel>>(j, "children"));
143+ x.set_data(get_stack_optional<Data>(j, "data"));
144+ }
145+
146+ inline void to_json(json & j, const TopLevel & x) {
147+ j = json::object();
148+ j["children"] = x.get_children();
149+ j["data"] = x.get_data();
150+ }
151+}
Aschema-csharp-recordsdefault / QuickType.cs+70 −0
@@ -0,0 +1,70 @@
1+// <auto-generated />
2+//
3+// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
4+//
5+// using QuickType;
6+//
7+// var topLevel = TopLevel.FromJson(jsonString);
8+#nullable enable
9+#pragma warning disable CS8618
10+#pragma warning disable CS8601
11+#pragma warning disable CS8602
12+#pragma warning disable CS8603
13+#pragma warning disable CS8604
14+#pragma warning disable CS8625
15+#pragma warning disable CS8765
16+
17+namespace QuickType
18+{
19+ using System;
20+ using System.Collections.Generic;
21+
22+ using System.Globalization;
23+ using Newtonsoft.Json;
24+ using Newtonsoft.Json.Converters;
25+
26+ public partial record TopLevel
27+ {
28+ [JsonProperty("children", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
29+ public TopLevel[]? Children { get; set; }
30+
31+ [JsonProperty("data", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
32+ public Data? Data { get; set; }
33+ }
34+
35+ public partial record Data
36+ {
37+ [JsonProperty("id", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
38+ public string? Id { get; set; }
39+ }
40+
41+ public partial record TopLevel
42+ {
43+ public static TopLevel FromJson(string json) => JsonConvert.DeserializeObject<TopLevel>(json, QuickType.Converter.Settings);
44+ }
45+
46+ public static partial class Serialize
47+ {
48+ public static string ToJson(this TopLevel self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
49+ }
50+
51+ internal static partial class Converter
52+ {
53+ public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
54+ {
55+ MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
56+ DateParseHandling = DateParseHandling.None,
57+ Converters =
58+ {
59+ new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
60+ },
61+ };
62+ }
63+}
64+#pragma warning restore CS8618
65+#pragma warning restore CS8601
66+#pragma warning restore CS8602
67+#pragma warning restore CS8603
68+#pragma warning restore CS8604
69+#pragma warning restore CS8625
70+#pragma warning restore CS8765
Aschema-csharp-SystemTextJsondefault / QuickType.cs+177 −0
@@ -0,0 +1,177 @@
1+// <auto-generated />
2+//
3+// To parse this JSON data, add NuGet 'System.Text.Json' then do:
4+//
5+// using QuickType;
6+//
7+// var topLevel = TopLevel.FromJson(jsonString);
8+#nullable enable
9+#pragma warning disable CS8618
10+#pragma warning disable CS8601
11+#pragma warning disable CS8602
12+#pragma warning disable CS8603
13+
14+namespace QuickType
15+{
16+ using System;
17+ using System.Collections.Generic;
18+
19+ using System.Text.Json;
20+ using System.Text.Json.Serialization;
21+ using System.Globalization;
22+
23+ public partial class TopLevel
24+ {
25+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26+ [JsonPropertyName("children")]
27+ public TopLevel[]? Children { get; set; }
28+
29+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
30+ [JsonPropertyName("data")]
31+ public Data? Data { get; set; }
32+ }
33+
34+ public partial class Data
35+ {
36+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
37+ [JsonPropertyName("id")]
38+ public string? Id { get; set; }
39+ }
40+
41+ public partial class TopLevel
42+ {
43+ public static TopLevel FromJson(string json) => JsonSerializer.Deserialize<TopLevel>(json, QuickType.Converter.Settings);
44+ }
45+
46+ public static partial class Serialize
47+ {
48+ public static string ToJson(this TopLevel self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings);
49+ }
50+
51+ internal static partial class Converter
52+ {
53+ public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
54+ {
55+ Converters =
56+ {
57+ new DateOnlyConverter(),
58+ new TimeOnlyConverter(),
59+ IsoDateTimeOffsetConverter.Singleton
60+ },
61+ };
62+ }
63+
64+ public class DateOnlyConverter : JsonConverter<DateOnly>
65+ {
66+ private readonly string serializationFormat;
67+ public DateOnlyConverter() : this(null) { }
68+
69+ public DateOnlyConverter(string? serializationFormat)
70+ {
71+ this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
72+ }
73+
74+ public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
75+ {
76+ var value = reader.GetString();
77+ return DateOnly.Parse(value!);
78+ }
79+
80+ public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
81+ => writer.WriteStringValue(value.ToString(serializationFormat));
82+ }
83+
84+ public class TimeOnlyConverter : JsonConverter<TimeOnly>
85+ {
86+ private readonly string serializationFormat;
87+
88+ public TimeOnlyConverter() : this(null) { }
89+
90+ public TimeOnlyConverter(string? serializationFormat)
91+ {
92+ this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
93+ }
94+
95+ public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
96+ {
97+ var value = reader.GetString();
98+ return TimeOnly.Parse(value!);
99+ }
100+
101+ public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
102+ => writer.WriteStringValue(value.ToString(serializationFormat));
103+ }
104+
105+ internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
106+ {
107+ public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
108+
109+ private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
110+
111+ private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
112+ private string? _dateTimeFormat;
113+ private CultureInfo? _culture;
114+
115+ public DateTimeStyles DateTimeStyles
116+ {
117+ get => _dateTimeStyles;
118+ set => _dateTimeStyles = value;
119+ }
120+
121+ public string? DateTimeFormat
122+ {
123+ get => _dateTimeFormat ?? string.Empty;
124+ set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
125+ }
126+
127+ public CultureInfo Culture
128+ {
129+ get => _culture ?? CultureInfo.CurrentCulture;
130+ set => _culture = value;
131+ }
132+
133+ public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
134+ {
135+ string text;
136+
137+
138+ if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
139+ || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
140+ {
141+ value = value.ToUniversalTime();
142+ }
143+
144+ text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
145+
146+ writer.WriteStringValue(text);
147+ }
148+
149+ public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
150+ {
151+ string? dateText = reader.GetString();
152+
153+ if (string.IsNullOrEmpty(dateText) == false)
154+ {
155+ if (!string.IsNullOrEmpty(_dateTimeFormat))
156+ {
157+ return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
158+ }
159+ else
160+ {
161+ return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
162+ }
163+ }
164+ else
165+ {
166+ return default(DateTimeOffset);
167+ }
168+ }
169+
170+
171+ public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
172+ }
173+}
174+#pragma warning restore CS8618
175+#pragma warning restore CS8601
176+#pragma warning restore CS8602
177+#pragma warning restore CS8603
Aschema-csharpdefault / QuickType.cs+70 −0
@@ -0,0 +1,70 @@
1+// <auto-generated />
2+//
3+// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
4+//
5+// using QuickType;
6+//
7+// var topLevel = TopLevel.FromJson(jsonString);
8+#nullable enable
9+#pragma warning disable CS8618
10+#pragma warning disable CS8601
11+#pragma warning disable CS8602
12+#pragma warning disable CS8603
13+#pragma warning disable CS8604
14+#pragma warning disable CS8625
15+#pragma warning disable CS8765
16+
17+namespace QuickType
18+{
19+ using System;
20+ using System.Collections.Generic;
21+
22+ using System.Globalization;
23+ using Newtonsoft.Json;
24+ using Newtonsoft.Json.Converters;
25+
26+ public partial class TopLevel
27+ {
28+ [JsonProperty("children", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
29+ public TopLevel[]? Children { get; set; }
30+
31+ [JsonProperty("data", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
32+ public Data? Data { get; set; }
33+ }
34+
35+ public partial class Data
36+ {
37+ [JsonProperty("id", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
38+ public string? Id { get; set; }
39+ }
40+
41+ public partial class TopLevel
42+ {
43+ public static TopLevel FromJson(string json) => JsonConvert.DeserializeObject<TopLevel>(json, QuickType.Converter.Settings);
44+ }
45+
46+ public static partial class Serialize
47+ {
48+ public static string ToJson(this TopLevel self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
49+ }
50+
51+ internal static partial class Converter
52+ {
53+ public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
54+ {
55+ MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
56+ DateParseHandling = DateParseHandling.None,
57+ Converters =
58+ {
59+ new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
60+ },
61+ };
62+ }
63+}
64+#pragma warning restore CS8618
65+#pragma warning restore CS8601
66+#pragma warning restore CS8602
67+#pragma warning restore CS8603
68+#pragma warning restore CS8604
69+#pragma warning restore CS8625
70+#pragma warning restore CS8765
Aschema-elixirdefault / QuickType.ex+73 −0
@@ -0,0 +1,73 @@
1+# This file was autogenerated using quicktype https://github.com/quicktype/quicktype
2+#
3+# Add Jason to your mix.exs
4+#
5+# Decode a JSON string: TopLevel.from_json(data)
6+# Encode into a JSON string: TopLevel.to_json(struct)
7+
8+defmodule Data do
9+ defstruct [:id]
10+
11+ @type t :: %__MODULE__{
12+ id: String.t() | nil
13+ }
14+
15+ def from_map(m) do
16+ %Data{
17+ id: m["id"],
18+ }
19+ end
20+
21+ def from_json(json) do
22+ json
23+ |> Jason.decode!()
24+ |> from_map()
25+ end
26+
27+ def to_map(struct) do
28+ %{
29+ "id" => struct.id,
30+ }
31+ end
32+
33+ def to_json(struct) do
34+ struct
35+ |> to_map()
36+ |> Jason.encode!()
37+ end
38+end
39+
40+defmodule TopLevel do
41+ defstruct [:children, :data]
42+
43+ @type t :: %__MODULE__{
44+ children: [TopLevel.t()] | nil,
45+ data: Data.t() | nil
46+ }
47+
48+ def from_map(m) do
49+ %TopLevel{
50+ children: m["children"] && Enum.map(m["children"], &TopLevel.from_map/1),
51+ data: m["data"] && Data.from_map(m["data"]),
52+ }
53+ end
54+
55+ def from_json(json) do
56+ json
57+ |> Jason.decode!()
58+ |> from_map()
59+ end
60+
61+ def to_map(struct) do
62+ %{
63+ "children" => struct.children && Enum.map(struct.children, &TopLevel.to_map/1),
64+ "data" => struct.data && Data.to_map(struct.data),
65+ }
66+ end
67+
68+ def to_json(struct) do
69+ struct
70+ |> to_map()
71+ |> Jason.encode!()
72+ end
73+end
Aschema-flowdefault / TopLevel.js+199 −0
@@ -0,0 +1,199 @@
1+// @flow
2+
3+// To parse this data:
4+//
5+// const Convert = require("./TopLevel");
6+//
7+// const topLevel = Convert.toTopLevel(json);
8+//
9+// These functions will throw an error if the JSON doesn't
10+// match the expected interface, even if the JSON is valid.
11+
12+export type TopLevel = {
13+ children?: TopLevel[];
14+ data?: Data;
15+ [property: string]: mixed;
16+};
17+
18+export type Data = {
19+ id?: string;
20+ [property: string]: mixed;
21+};
22+
23+// Converts JSON strings to/from your types
24+// and asserts the results of JSON.parse at runtime
25+function toTopLevel(json: string): TopLevel {
26+ return cast(JSON.parse(json), r("TopLevel"));
27+}
28+
29+function topLevelToJson(value: TopLevel): string {
30+ return JSON.stringify(uncast(value, r("TopLevel")), null, 2);
31+}
32+
33+function invalidValue(typ: any, val: any, key: any, parent: any = '') {
34+ const prettyTyp = prettyTypeName(typ);
35+ const parentText = parent ? ` on ${parent}` : '';
36+ const keyText = key ? ` for key "${key}"` : '';
37+ throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
38+}
39+
40+function prettyTypeName(typ: any): string {
41+ if (Array.isArray(typ)) {
42+ if (typ.length === 2 && typ[0] === undefined) {
43+ return `an optional ${prettyTypeName(typ[1])}`;
44+ } else {
45+ return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
46+ }
47+ } else if (typeof typ === "object" && typ.literal !== undefined) {
48+ return typ.literal;
49+ } else {
50+ return typeof typ;
51+ }
52+}
53+
54+function jsonToJSProps(typ: any): any {
55+ if (typ.jsonToJS === undefined) {
56+ const map: any = {};
57+ typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
58+ typ.jsonToJS = map;
59+ }
60+ return typ.jsonToJS;
61+}
62+
63+function jsToJSONProps(typ: any): any {
64+ if (typ.jsToJSON === undefined) {
65+ const map: any = {};
66+ typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
67+ typ.jsToJSON = map;
68+ }
69+ return typ.jsToJSON;
70+}
71+
72+function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
73+ function transformPrimitive(typ: string, val: any): any {
74+ if (typeof typ === typeof val) return val;
75+ return invalidValue(typ, val, key, parent);
76+ }
77+
78+ function transformUnion(typs: any[], val: any): any {
79+ // val must validate against one typ in typs
80+ const l = typs.length;
81+ for (let i = 0; i < l; i++) {
82+ const typ = typs[i];
83+ try {
84+ return transform(val, typ, getProps);
85+ } catch (_) {}
86+ }
87+ return invalidValue(typs, val, key, parent);
88+ }
89+
90+ function transformEnum(cases: string[], val: any): any {
91+ if (cases.indexOf(val) !== -1) return val;
92+ return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
93+ }
94+
95+ function transformArray(typ: any, val: any): any {
96+ // val must be an array with no invalid elements
97+ if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
98+ return val.map(el => transform(el, typ, getProps));
99+ }
100+
101+ function transformDate(val: any): any {
102+ if (val === null) {
103+ return null;
104+ }
105+ const d = new Date(val);
106+ if (isNaN(d.valueOf())) {
107+ return invalidValue(l("Date"), val, key, parent);
108+ }
109+ return d;
110+ }
111+
112+ function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
113+ if (val === null || typeof val !== "object" || Array.isArray(val)) {
114+ return invalidValue(l(ref || "object"), val, key, parent);
115+ }
116+ const result: any = {};
117+ Object.getOwnPropertyNames(props).forEach(key => {
118+ const prop = props[key];
119+ const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
120+ result[prop.key] = transform(v, prop.typ, getProps, key, ref);
121+ });
122+ Object.getOwnPropertyNames(val).forEach(key => {
123+ if (!Object.prototype.hasOwnProperty.call(props, key)) {
124+ result[key] = transform(val[key], additional, getProps, key, ref);
125+ }
126+ });
127+ return result;
128+ }
129+
130+ if (typ === "any") return val;
131+ if (typ === null) {
132+ if (val === null) return val;
133+ return invalidValue(typ, val, key, parent);
134+ }
135+ if (typ === false) return invalidValue(typ, val, key, parent);
136+ let ref: any = undefined;
137+ while (typeof typ === "object" && typ.ref !== undefined) {
138+ ref = typ.ref;
139+ typ = typeMap[typ.ref];
140+ }
141+ if (Array.isArray(typ)) return transformEnum(typ, val);
142+ if (typeof typ === "object") {
143+ return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
144+ : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
145+ : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
146+ : invalidValue(typ, val, key, parent);
147+ }
148+ // Numbers can be parsed by Date but shouldn't be.
149+ if (typ === Date && typeof val !== "number") return transformDate(val);
150+ return transformPrimitive(typ, val);
151+}
152+
153+function cast<T>(val: any, typ: any): T {
154+ return transform(val, typ, jsonToJSProps);
155+}
156+
157+function uncast<T>(val: T, typ: any): any {
158+ return transform(val, typ, jsToJSONProps);
159+}
160+
161+function l(typ: any) {
162+ return { literal: typ };
163+}
164+
165+function a(typ: any) {
166+ return { arrayItems: typ };
167+}
168+
169+function u(...typs: any[]) {
170+ return { unionMembers: typs };
171+}
172+
173+function o(props: any[], additional: any) {
174+ return { props, additional };
175+}
176+
177+function m(additional: any) {
178+ const props: any[] = [];
179+ return { props, additional };
180+}
181+
182+function r(name: string) {
183+ return { ref: name };
184+}
185+
186+const typeMap: any = {
187+ "TopLevel": o([
188+ { json: "children", js: "children", typ: u(undefined, a(r("TopLevel"))) },
189+ { json: "data", js: "data", typ: u(undefined, r("Data")) },
190+ ], "any"),
191+ "Data": o([
192+ { json: "id", js: "id", typ: u(undefined, "") },
193+ ], "any"),
194+};
195+
196+module.exports = {
197+ "topLevelToJson": topLevelToJson,
198+ "toTopLevel": toTopLevel,
199+};
Aschema-golangdefault / quicktype.go+28 −0
@@ -0,0 +1,28 @@
1+// Code generated from JSON Schema using quicktype. DO NOT EDIT.
2+// To parse and unparse this JSON data, add this code to your project and do:
3+//
4+// topLevel, err := UnmarshalTopLevel(bytes)
5+// bytes, err = topLevel.Marshal()
6+
7+package main
8+
9+import "encoding/json"
10+
11+func UnmarshalTopLevel(data []byte) (TopLevel, error) {
12+ var r TopLevel
13+ err := json.Unmarshal(data, &r)
14+ return r, err
15+}
16+
17+func (r *TopLevel) Marshal() ([]byte, error) {
18+ return json.Marshal(r)
19+}
20+
21+type TopLevel struct {
22+ Children []TopLevel `json:"children,omitempty"`
23+ Data *Data `json:"data,omitempty"`
24+}
25+
26+type Data struct {
27+ ID *string `json:"id,omitempty"`
28+}
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / Converter.java+121 −0
@@ -0,0 +1,121 @@
1+// To use this code, add the following Maven dependency to your project:
2+//
3+//
4+// com.fasterxml.jackson.core : jackson-databind : 2.9.0
5+//
6+//
7+// Import this package:
8+//
9+// import io.quicktype.Converter;
10+//
11+// Then you can deserialize a JSON string with
12+//
13+// TopLevel data = Converter.fromJsonString(jsonString);
14+
15+package io.quicktype;
16+
17+import java.io.IOException;
18+import com.fasterxml.jackson.databind.*;
19+import com.fasterxml.jackson.databind.module.SimpleModule;
20+import com.fasterxml.jackson.core.JsonParser;
21+import com.fasterxml.jackson.core.JsonProcessingException;
22+import java.util.*;
23+import java.util.Date;
24+import java.text.SimpleDateFormat;
25+
26+public class Converter {
27+ // Date-time helpers
28+
29+ private static final String[] DATE_TIME_FORMATS = {
30+ "yyyy-MM-dd'T'HH:mm:ss.SX",
31+ "yyyy-MM-dd'T'HH:mm:ss.S",
32+ "yyyy-MM-dd'T'HH:mm:ssX",
33+ "yyyy-MM-dd'T'HH:mm:ss",
34+ "yyyy-MM-dd HH:mm:ss.SX",
35+ "yyyy-MM-dd HH:mm:ss.S",
36+ "yyyy-MM-dd HH:mm:ssX",
37+ "yyyy-MM-dd HH:mm:ss",
38+ "HH:mm:ss.SZ",
39+ "HH:mm:ss.S",
40+ "HH:mm:ssZ",
41+ "HH:mm:ss",
42+ "yyyy-MM-dd",
43+ };
44+
45+ public static Date parseAllDateTimeString(String str) {
46+ for (String format : DATE_TIME_FORMATS) {
47+ try {
48+ return new SimpleDateFormat(format).parse(str);
49+ } catch (Exception ex) {
50+ // Ignored
51+ }
52+ }
53+ return null;
54+ }
55+
56+ public static String serializeDateTime(Date datetime) {
57+ return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ").format(datetime);
58+ }
59+
60+ public static String serializeDate(Date datetime) {
61+ return new SimpleDateFormat("yyyy-MM-dd").format(datetime);
62+ }
63+
64+ public static String serializeTime(Date datetime) {
65+ return new SimpleDateFormat("hh:mm:ssZ").format(datetime);
66+ }
67+ // Serialize/deserialize helpers
68+
69+ public static TopLevel fromJsonString(String json) throws IOException {
70+ return getObjectReader().readValue(json);
71+ }
72+
73+ public static String toJsonString(TopLevel obj) throws JsonProcessingException {
74+ return getObjectWriter().writeValueAsString(obj);
75+ }
76+
77+ private static ObjectReader reader;
78+ private static ObjectWriter writer;
79+
80+ private static void instantiateMapper() {
81+ ObjectMapper mapper = new ObjectMapper();
82+ mapper.findAndRegisterModules();
83+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
84+ mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
85+ SimpleModule module = new SimpleModule();
86+ module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
87+ @Override
88+ public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
89+ String value = jsonParser.getText();
90+ return Converter.parseAllDateTimeString(value);
91+ }
92+ });
93+ module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
94+ @Override
95+ public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
96+ String value = jsonParser.getText();
97+ return Converter.parseAllDateTimeString(value);
98+ }
99+ });
100+ module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
101+ @Override
102+ public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
103+ String value = jsonParser.getText();
104+ return Converter.parseAllDateTimeString(value);
105+ }
106+ });
107+ mapper.registerModule(module);
108+ reader = mapper.readerFor(TopLevel.class);
109+ writer = mapper.writerFor(TopLevel.class);
110+ }
111+
112+ private static ObjectReader getObjectReader() {
113+ if (reader == null) instantiateMapper();
114+ return reader;
115+ }
116+
117+ private static ObjectWriter getObjectWriter() {
118+ if (writer == null) instantiateMapper();
119+ return writer;
120+ }
121+}
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / Data.java+12 −0
@@ -0,0 +1,12 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+
5+public class Data {
6+ private String id;
7+
8+ @JsonProperty("id")
9+ public String getID() { return id; }
10+ @JsonProperty("id")
11+ public void setID(String value) { this.id = value; }
12+}
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevel.java+19 −0
@@ -0,0 +1,19 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+import java.util.List;
5+
6+public class TopLevel {
7+ private List<TopLevel> children;
8+ private Data data;
9+
10+ @JsonProperty("children")
11+ public List<TopLevel> getChildren() { return children; }
12+ @JsonProperty("children")
13+ public void setChildren(List<TopLevel> value) { this.children = value; }
14+
15+ @JsonProperty("data")
16+ public Data getData() { return data; }
17+ @JsonProperty("data")
18+ public void setData(Data value) { this.data = value; }
19+}
Aschema-java-lombokdefault / src / main / java / io / quicktype / Converter.java+101 −0
@@ -0,0 +1,101 @@
1+// To use this code, add the following Maven dependency to your project:
2+//
3+//
4+// com.fasterxml.jackson.core : jackson-databind : 2.9.0
5+// com.fasterxml.jackson.datatype : jackson-datatype-jsr310 : 2.9.0
6+//
7+// Import this package:
8+//
9+// import io.quicktype.Converter;
10+//
11+// Then you can deserialize a JSON string with
12+//
13+// TopLevel data = Converter.fromJsonString(jsonString);
14+
15+package io.quicktype;
16+
17+import java.io.IOException;
18+import com.fasterxml.jackson.databind.*;
19+import com.fasterxml.jackson.databind.module.SimpleModule;
20+import com.fasterxml.jackson.core.JsonParser;
21+import com.fasterxml.jackson.core.JsonProcessingException;
22+import java.util.*;
23+import java.time.LocalDate;
24+import java.time.OffsetDateTime;
25+import java.time.OffsetTime;
26+import java.time.ZoneOffset;
27+import java.time.ZonedDateTime;
28+import java.time.format.DateTimeFormatter;
29+import java.time.format.DateTimeFormatterBuilder;
30+import java.time.temporal.ChronoField;
31+
32+public class Converter {
33+ // Date-time helpers
34+
35+ private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
36+ .appendOptional(DateTimeFormatter.ISO_DATE_TIME)
37+ .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
38+ .appendOptional(DateTimeFormatter.ISO_INSTANT)
39+ .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))
40+ .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))
41+ .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
42+ .toFormatter()
43+ .withZone(ZoneOffset.UTC);
44+
45+ public static OffsetDateTime parseDateTimeString(String str) {
46+ return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime();
47+ }
48+
49+ private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder()
50+ .appendOptional(DateTimeFormatter.ISO_TIME)
51+ .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME)
52+ .parseDefaulting(ChronoField.YEAR, 2020)
53+ .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
54+ .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
55+ .toFormatter()
56+ .withZone(ZoneOffset.UTC);
57+
58+ public static OffsetTime parseTimeString(String str) {
59+ return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime();
60+ }
61+ // Serialize/deserialize helpers
62+
63+ public static TopLevel fromJsonString(String json) throws IOException {
64+ return getObjectReader().readValue(json);
65+ }
66+
67+ public static String toJsonString(TopLevel obj) throws JsonProcessingException {
68+ return getObjectWriter().writeValueAsString(obj);
69+ }
70+
71+ private static ObjectReader reader;
72+ private static ObjectWriter writer;
73+
74+ private static void instantiateMapper() {
75+ ObjectMapper mapper = new ObjectMapper();
76+ mapper.findAndRegisterModules();
77+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
78+ mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
79+ SimpleModule module = new SimpleModule();
80+ module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() {
81+ @Override
82+ public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
83+ String value = jsonParser.getText();
84+ return Converter.parseDateTimeString(value);
85+ }
86+ });
87+ mapper.registerModule(module);
88+ reader = mapper.readerFor(TopLevel.class);
89+ writer = mapper.writerFor(TopLevel.class);
90+ }
91+
92+ private static ObjectReader getObjectReader() {
93+ if (reader == null) instantiateMapper();
94+ return reader;
95+ }
96+
97+ private static ObjectWriter getObjectWriter() {
98+ if (writer == null) instantiateMapper();
99+ return writer;
100+ }
101+}
Aschema-java-lombokdefault / src / main / java / io / quicktype / Data.java+12 −0
@@ -0,0 +1,12 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+
5+public class Data {
6+ private String id;
7+
8+ @JsonProperty("id")
9+ public String getID() { return id; }
10+ @JsonProperty("id")
11+ public void setID(String value) { this.id = value; }
12+}
Aschema-java-lombokdefault / src / main / java / io / quicktype / TopLevel.java+19 −0
@@ -0,0 +1,19 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+import java.util.List;
5+
6+public class TopLevel {
7+ private List<TopLevel> children;
8+ private Data data;
9+
10+ @JsonProperty("children")
11+ public List<TopLevel> getChildren() { return children; }
12+ @JsonProperty("children")
13+ public void setChildren(List<TopLevel> value) { this.children = value; }
14+
15+ @JsonProperty("data")
16+ public Data getData() { return data; }
17+ @JsonProperty("data")
18+ public void setData(Data value) { this.data = value; }
19+}
Aschema-javadefault / src / main / java / io / quicktype / Converter.java+101 −0
@@ -0,0 +1,101 @@
1+// To use this code, add the following Maven dependency to your project:
2+//
3+//
4+// com.fasterxml.jackson.core : jackson-databind : 2.9.0
5+// com.fasterxml.jackson.datatype : jackson-datatype-jsr310 : 2.9.0
6+//
7+// Import this package:
8+//
9+// import io.quicktype.Converter;
10+//
11+// Then you can deserialize a JSON string with
12+//
13+// TopLevel data = Converter.fromJsonString(jsonString);
14+
15+package io.quicktype;
16+
17+import java.io.IOException;
18+import com.fasterxml.jackson.databind.*;
19+import com.fasterxml.jackson.databind.module.SimpleModule;
20+import com.fasterxml.jackson.core.JsonParser;
21+import com.fasterxml.jackson.core.JsonProcessingException;
22+import java.util.*;
23+import java.time.LocalDate;
24+import java.time.OffsetDateTime;
25+import java.time.OffsetTime;
26+import java.time.ZoneOffset;
27+import java.time.ZonedDateTime;
28+import java.time.format.DateTimeFormatter;
29+import java.time.format.DateTimeFormatterBuilder;
30+import java.time.temporal.ChronoField;
31+
32+public class Converter {
33+ // Date-time helpers
34+
35+ private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
36+ .appendOptional(DateTimeFormatter.ISO_DATE_TIME)
37+ .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
38+ .appendOptional(DateTimeFormatter.ISO_INSTANT)
39+ .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))
40+ .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))
41+ .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
42+ .toFormatter()
43+ .withZone(ZoneOffset.UTC);
44+
45+ public static OffsetDateTime parseDateTimeString(String str) {
46+ return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime();
47+ }
48+
49+ private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder()
50+ .appendOptional(DateTimeFormatter.ISO_TIME)
51+ .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME)
52+ .parseDefaulting(ChronoField.YEAR, 2020)
53+ .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
54+ .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
55+ .toFormatter()
56+ .withZone(ZoneOffset.UTC);
57+
58+ public static OffsetTime parseTimeString(String str) {
59+ return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime();
60+ }
61+ // Serialize/deserialize helpers
62+
63+ public static TopLevel fromJsonString(String json) throws IOException {
64+ return getObjectReader().readValue(json);
65+ }
66+
67+ public static String toJsonString(TopLevel obj) throws JsonProcessingException {
68+ return getObjectWriter().writeValueAsString(obj);
69+ }
70+
71+ private static ObjectReader reader;
72+ private static ObjectWriter writer;
73+
74+ private static void instantiateMapper() {
75+ ObjectMapper mapper = new ObjectMapper();
76+ mapper.findAndRegisterModules();
77+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
78+ mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
79+ SimpleModule module = new SimpleModule();
80+ module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() {
81+ @Override
82+ public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
83+ String value = jsonParser.getText();
84+ return Converter.parseDateTimeString(value);
85+ }
86+ });
87+ mapper.registerModule(module);
88+ reader = mapper.readerFor(TopLevel.class);
89+ writer = mapper.writerFor(TopLevel.class);
90+ }
91+
92+ private static ObjectReader getObjectReader() {
93+ if (reader == null) instantiateMapper();
94+ return reader;
95+ }
96+
97+ private static ObjectWriter getObjectWriter() {
98+ if (writer == null) instantiateMapper();
99+ return writer;
100+ }
101+}
Aschema-javadefault / src / main / java / io / quicktype / Data.java+12 −0
@@ -0,0 +1,12 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+
5+public class Data {
6+ private String id;
7+
8+ @JsonProperty("id")
9+ public String getID() { return id; }
10+ @JsonProperty("id")
11+ public void setID(String value) { this.id = value; }
12+}
Aschema-javadefault / src / main / java / io / quicktype / TopLevel.java+19 −0
@@ -0,0 +1,19 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+import java.util.List;
5+
6+public class TopLevel {
7+ private List<TopLevel> children;
8+ private Data data;
9+
10+ @JsonProperty("children")
11+ public List<TopLevel> getChildren() { return children; }
12+ @JsonProperty("children")
13+ public void setChildren(List<TopLevel> value) { this.children = value; }
14+
15+ @JsonProperty("data")
16+ public Data getData() { return data; }
17+ @JsonProperty("data")
18+ public void setData(Data value) { this.data = value; }
19+}
Aschema-javascriptdefault / TopLevel.js+186 −0
@@ -0,0 +1,186 @@
1+// To parse this data:
2+//
3+// const Convert = require("./TopLevel");
4+//
5+// const topLevel = Convert.toTopLevel(json);
6+//
7+// These functions will throw an error if the JSON doesn't
8+// match the expected interface, even if the JSON is valid.
9+
10+// Converts JSON strings to/from your types
11+// and asserts the results of JSON.parse at runtime
12+function toTopLevel(json) {
13+ return cast(JSON.parse(json), r("TopLevel"));
14+}
15+
16+function topLevelToJson(value) {
17+ return JSON.stringify(uncast(value, r("TopLevel")), null, 2);
18+}
19+
20+function invalidValue(typ, val, key, parent = '') {
21+ const prettyTyp = prettyTypeName(typ);
22+ const parentText = parent ? ` on ${parent}` : '';
23+ const keyText = key ? ` for key "${key}"` : '';
24+ throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
25+}
26+
27+function prettyTypeName(typ) {
28+ if (Array.isArray(typ)) {
29+ if (typ.length === 2 && typ[0] === undefined) {
30+ return `an optional ${prettyTypeName(typ[1])}`;
31+ } else {
32+ return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
33+ }
34+ } else if (typeof typ === "object" && typ.literal !== undefined) {
35+ return typ.literal;
36+ } else {
37+ return typeof typ;
38+ }
39+}
40+
41+function jsonToJSProps(typ) {
42+ if (typ.jsonToJS === undefined) {
43+ const map = {};
44+ typ.props.forEach((p) => map[p.json] = { key: p.js, typ: p.typ });
45+ typ.jsonToJS = map;
46+ }
47+ return typ.jsonToJS;
48+}
49+
50+function jsToJSONProps(typ) {
51+ if (typ.jsToJSON === undefined) {
52+ const map = {};
53+ typ.props.forEach((p) => map[p.js] = { key: p.json, typ: p.typ });
54+ typ.jsToJSON = map;
55+ }
56+ return typ.jsToJSON;
57+}
58+
59+function transform(val, typ, getProps, key = '', parent = '') {
60+ function transformPrimitive(typ, val) {
61+ if (typeof typ === typeof val) return val;
62+ return invalidValue(typ, val, key, parent);
63+ }
64+
65+ function transformUnion(typs, val) {
66+ // val must validate against one typ in typs
67+ const l = typs.length;
68+ for (let i = 0; i < l; i++) {
69+ const typ = typs[i];
70+ try {
71+ return transform(val, typ, getProps);
72+ } catch (_) {}
73+ }
74+ return invalidValue(typs, val, key, parent);
75+ }
76+
77+ function transformEnum(cases, val) {
78+ if (cases.indexOf(val) !== -1) return val;
79+ return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
80+ }
81+
82+ function transformArray(typ, val) {
83+ // val must be an array with no invalid elements
84+ if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
85+ return val.map(el => transform(el, typ, getProps));
86+ }
87+
88+ function transformDate(val) {
89+ if (val === null) {
90+ return null;
91+ }
92+ const d = new Date(val);
93+ if (isNaN(d.valueOf())) {
94+ return invalidValue(l("Date"), val, key, parent);
95+ }
96+ return d;
97+ }
98+
99+ function transformObject(props, additional, val) {
100+ if (val === null || typeof val !== "object" || Array.isArray(val)) {
101+ return invalidValue(l(ref || "object"), val, key, parent);
102+ }
103+ const result = {};
104+ Object.getOwnPropertyNames(props).forEach(key => {
105+ const prop = props[key];
106+ const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
107+ result[prop.key] = transform(v, prop.typ, getProps, key, ref);
108+ });
109+ Object.getOwnPropertyNames(val).forEach(key => {
110+ if (!Object.prototype.hasOwnProperty.call(props, key)) {
111+ result[key] = transform(val[key], additional, getProps, key, ref);
112+ }
113+ });
114+ return result;
115+ }
116+
117+ if (typ === "any") return val;
118+ if (typ === null) {
119+ if (val === null) return val;
120+ return invalidValue(typ, val, key, parent);
121+ }
122+ if (typ === false) return invalidValue(typ, val, key, parent);
123+ let ref = undefined;
124+ while (typeof typ === "object" && typ.ref !== undefined) {
125+ ref = typ.ref;
126+ typ = typeMap[typ.ref];
127+ }
128+ if (Array.isArray(typ)) return transformEnum(typ, val);
129+ if (typeof typ === "object") {
130+ return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
131+ : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
132+ : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
133+ : invalidValue(typ, val, key, parent);
134+ }
135+ // Numbers can be parsed by Date but shouldn't be.
136+ if (typ === Date && typeof val !== "number") return transformDate(val);
137+ return transformPrimitive(typ, val);
138+}
139+
140+function cast(val, typ) {
141+ return transform(val, typ, jsonToJSProps);
142+}
143+
144+function uncast(val, typ) {
145+ return transform(val, typ, jsToJSONProps);
146+}
147+
148+function l(typ) {
149+ return { literal: typ };
150+}
151+
152+function a(typ) {
153+ return { arrayItems: typ };
154+}
155+
156+function u(...typs) {
157+ return { unionMembers: typs };
158+}
159+
160+function o(props, additional) {
161+ return { props, additional };
162+}
163+
164+function m(additional) {
165+ const props = [];
166+ return { props, additional };
167+}
168+
169+function r(name) {
170+ return { ref: name };
171+}
172+
173+const typeMap = {
174+ "TopLevel": o([
175+ { json: "children", js: "children", typ: u(undefined, a(r("TopLevel"))) },
176+ { json: "data", js: "data", typ: u(undefined, r("Data")) },
177+ ], "any"),
178+ "Data": o([
179+ { json: "id", js: "id", typ: u(undefined, "") },
180+ ], "any"),
181+};
182+
183+module.exports = {
184+ "topLevelToJson": topLevelToJson,
185+ "toTopLevel": toTopLevel,
186+};
Aschema-kotlin-jacksondefault / TopLevel.kt+34 −0
@@ -0,0 +1,34 @@
1+// To parse the JSON, install jackson-module-kotlin and do:
2+//
3+// val topLevel = TopLevel.fromJson(jsonString)
4+
5+package quicktype
6+
7+import com.fasterxml.jackson.annotation.*
8+import com.fasterxml.jackson.core.*
9+import com.fasterxml.jackson.databind.*
10+import com.fasterxml.jackson.databind.deser.std.StdDeserializer
11+import com.fasterxml.jackson.databind.module.SimpleModule
12+import com.fasterxml.jackson.databind.node.*
13+import com.fasterxml.jackson.databind.ser.std.StdSerializer
14+import com.fasterxml.jackson.module.kotlin.*
15+
16+val mapper = jacksonObjectMapper().apply {
17+ propertyNamingStrategy = PropertyNamingStrategy.LOWER_CAMEL_CASE
18+ setSerializationInclusion(JsonInclude.Include.NON_NULL)
19+}
20+
21+data class TopLevel (
22+ val children: List<TopLevel>? = null,
23+ val data: Data? = null
24+) {
25+ fun toJson() = mapper.writeValueAsString(this)
26+
27+ companion object {
28+ fun fromJson(json: String) = mapper.readValue<TopLevel>(json)
29+ }
30+}
31+
32+data class Data (
33+ val id: String? = null
34+)
Aschema-kotlindefault / TopLevel.kt+24 −0
@@ -0,0 +1,24 @@
1+// To parse the JSON, install Klaxon and do:
2+//
3+// val topLevel = TopLevel.fromJson(jsonString)
4+
5+package quicktype
6+
7+import com.beust.klaxon.*
8+
9+private val klaxon = Klaxon()
10+
11+data class TopLevel (
12+ val children: List<TopLevel>? = null,
13+ val data: Data? = null
14+) {
15+ public fun toJson() = klaxon.toJsonString(this)
16+
17+ companion object {
18+ public fun fromJson(json: String) = klaxon.parse<TopLevel>(json)
19+ }
20+}
21+
22+data class Data (
23+ val id: String? = null
24+)
Aschema-kotlinxdefault / TopLevel.kt+22 −0
@@ -0,0 +1,22 @@
1+// To parse the JSON, install kotlin's serialization plugin and do:
2+//
3+// val json = Json { allowStructuredMapKeys = true }
4+// val topLevel = json.parse(TopLevel.serializer(), jsonString)
5+
6+package quicktype
7+
8+import kotlinx.serialization.*
9+import kotlinx.serialization.json.*
10+import kotlinx.serialization.descriptors.*
11+import kotlinx.serialization.encoding.*
12+
13+@Serializable
14+data class TopLevel (
15+ val children: List<TopLevel>? = null,
16+ val data: Data? = null
17+)
18+
19+@Serializable
20+data class Data (
21+ val id: String? = null
22+)
Aschema-phpdefault / TopLevel.php+295 −0
@@ -0,0 +1,295 @@
1+<?php
2+declare(strict_types=1);
3+
4+// This is an autogenerated file:TopLevel
5+
6+class TopLevel {
7+ private ?array $children; // json:children Optional
8+ private ?Data $data; // json:data Optional
9+
10+ /**
11+ * @param array|null $children
12+ * @param Data|null $data
13+ */
14+ public function __construct(?array $children, ?Data $data) {
15+ $this->children = $children;
16+ $this->data = $data;
17+ }
18+
19+ /**
20+ * @param ?array $value
21+ * @throws Exception
22+ * @return ?array
23+ */
24+ public static function fromChildren(?array $value): ?array {
25+ if (!is_null($value)) {
26+ return array_map(function ($value) {
27+ return TopLevel::from($value); /*class*/
28+ }, $value);
29+ } else {
30+ return null;
31+ }
32+ }
33+
34+ /**
35+ * @throws Exception
36+ * @return ?array
37+ */
38+ public function toChildren(): ?array {
39+ if (TopLevel::validateChildren($this->children)) {
40+ if (!is_null($this->children)) {
41+ return array_map(function ($value) {
42+ return $value->to(); /*class*/
43+ }, $this->children);
44+ } else {
45+ return null;
46+ }
47+ }
48+ throw new Exception('never get to this TopLevel::children');
49+ }
50+
51+ /**
52+ * @param array|null
53+ * @return bool
54+ * @throws Exception
55+ */
56+ public static function validateChildren(?array $value): bool {
57+ if (!is_null($value)) {
58+ if (!is_array($value)) {
59+ throw new Exception("Attribute Error:TopLevel::children");
60+ }
61+ array_walk($value, function($value_v) {
62+ $value_v->validate();
63+ });
64+ }
65+ return true;
66+ }
67+
68+ /**
69+ * @throws Exception
70+ * @return ?array
71+ */
72+ public function getChildren(): ?array {
73+ if (TopLevel::validateChildren($this->children)) {
74+ return $this->children;
75+ }
76+ throw new Exception('never get to getChildren TopLevel::children');
77+ }
78+
79+ /**
80+ * @return ?array
81+ */
82+ public static function sampleChildren(): ?array {
83+ return array(
84+ TopLevel::sample() /*31:*/
85+ ); /* 31:children*/
86+ }
87+
88+ /**
89+ * @param ?stdClass $value
90+ * @throws Exception
91+ * @return ?Data
92+ */
93+ public static function fromData(?stdClass $value): ?Data {
94+ if (!is_null($value)) {
95+ return Data::from($value); /*class*/
96+ } else {
97+ return null;
98+ }
99+ }
100+
101+ /**
102+ * @throws Exception
103+ * @return ?stdClass
104+ */
105+ public function toData(): ?stdClass {
106+ if (TopLevel::validateData($this->data)) {
107+ if (!is_null($this->data)) {
108+ return $this->data->to(); /*class*/
109+ } else {
110+ return null;
111+ }
112+ }
113+ throw new Exception('never get to this TopLevel::data');
114+ }
115+
116+ /**
117+ * @param Data|null
118+ * @return bool
119+ * @throws Exception
120+ */
121+ public static function validateData(?Data $value): bool {
122+ if (!is_null($value)) {
123+ $value->validate();
124+ }
125+ return true;
126+ }
127+
128+ /**
129+ * @throws Exception
130+ * @return ?Data
131+ */
132+ public function getData(): ?Data {
133+ if (TopLevel::validateData($this->data)) {
134+ return $this->data;
135+ }
136+ throw new Exception('never get to getData TopLevel::data');
137+ }
138+
139+ /**
140+ * @return ?Data
141+ */
142+ public static function sampleData(): ?Data {
143+ return Data::sample(); /*32:data*/
144+ }
145+
146+ /**
147+ * @throws Exception
148+ * @return bool
149+ */
150+ public function validate(): bool {
151+ return TopLevel::validateChildren($this->children)
152+ || TopLevel::validateData($this->data);
153+ }
154+
155+ /**
156+ * @return stdClass
157+ * @throws Exception
158+ */
159+ public function to(): stdClass {
160+ $out = new stdClass();
161+ $out->{'children'} = $this->toChildren();
162+ $out->{'data'} = $this->toData();
163+ return $out;
164+ }
165+
166+ /**
167+ * @param stdClass $obj
168+ * @return TopLevel
169+ * @throws Exception
170+ */
171+ public static function from(stdClass $obj): TopLevel {
172+ return new TopLevel(
173+ TopLevel::fromChildren($obj->{'children'})
174+ ,TopLevel::fromData($obj->{'data'})
175+ );
176+ }
177+
178+ /**
179+ * @return TopLevel
180+ */
181+ public static function sample(): TopLevel {
182+ return new TopLevel(
183+ TopLevel::sampleChildren()
184+ ,TopLevel::sampleData()
185+ );
186+ }
187+}
188+
189+// This is an autogenerated file:Data
190+
191+class Data {
192+ private ?string $id; // json:id Optional
193+
194+ /**
195+ * @param string|null $id
196+ */
197+ public function __construct(?string $id) {
198+ $this->id = $id;
199+ }
200+
201+ /**
202+ * @param ?string $value
203+ * @throws Exception
204+ * @return ?string
205+ */
206+ public static function fromID(?string $value): ?string {
207+ if (!is_null($value)) {
208+ return $value; /*string*/
209+ } else {
210+ return null;
211+ }
212+ }
213+
214+ /**
215+ * @throws Exception
216+ * @return ?string
217+ */
218+ public function toID(): ?string {
219+ if (Data::validateID($this->id)) {
220+ if (!is_null($this->id)) {
221+ return $this->id; /*string*/
222+ } else {
223+ return null;
224+ }
225+ }
226+ throw new Exception('never get to this Data::id');
227+ }
228+
229+ /**
230+ * @param string|null
231+ * @return bool
232+ * @throws Exception
233+ */
234+ public static function validateID(?string $value): bool {
235+ if (!is_null($value)) {
236+ }
237+ return true;
238+ }
239+
240+ /**
241+ * @throws Exception
242+ * @return ?string
243+ */
244+ public function getID(): ?string {
245+ if (Data::validateID($this->id)) {
246+ return $this->id;
247+ }
248+ throw new Exception('never get to getID Data::id');
249+ }
250+
251+ /**
252+ * @return ?string
253+ */
254+ public static function sampleID(): ?string {
255+ return 'Data::id::31'; /*31:id*/
256+ }
257+
258+ /**
259+ * @throws Exception
260+ * @return bool
261+ */
262+ public function validate(): bool {
263+ return Data::validateID($this->id);
264+ }
265+
266+ /**
267+ * @return stdClass
268+ * @throws Exception
269+ */
270+ public function to(): stdClass {
271+ $out = new stdClass();
272+ $out->{'id'} = $this->toID();
273+ return $out;
274+ }
275+
276+ /**
277+ * @param stdClass $obj
278+ * @return Data
279+ * @throws Exception
280+ */
281+ public static function from(stdClass $obj): Data {
282+ return new Data(
283+ Data::fromID($obj->{'id'})
284+ );
285+ }
286+
287+ /**
288+ * @return Data
289+ */
290+ public static function sample(): Data {
291+ return new Data(
292+ Data::sampleID()
293+ );
294+ }
295+}
Aschema-pikedefault / TopLevel.pmod+56 −0
@@ -0,0 +1,56 @@
1+// This source has been automatically generated by quicktype.
2+// ( https://github.com/quicktype/quicktype )
3+//
4+// To use this code, simply import it into your project as a Pike module.
5+// To JSON-encode your object, you can pass it to `Standards.JSON.encode`
6+// or call `encode_json` on it.
7+//
8+// To decode a JSON string, first pass it to `Standards.JSON.decode`,
9+// and then pass the result to `<YourClass>_from_JSON`.
10+// It will return an instance of <YourClass>.
11+// Bear in mind that these functions have unexpected behavior,
12+// and will likely throw an error, if the JSON string does not
13+// match the expected interface, even if the JSON itself is valid.
14+
15+class TopLevel {
16+ array(TopLevel)|mixed children; // json: "children"
17+ Data|mixed data; // json: "data"
18+
19+ string encode_json() {
20+ mapping(string:mixed) json = ([
21+ "children" : children,
22+ "data" : data,
23+ ]);
24+
25+ return Standards.JSON.encode(json);
26+ }
27+}
28+
29+TopLevel TopLevel_from_JSON(mixed json) {
30+ TopLevel retval = TopLevel();
31+
32+ retval.children = json["children"];
33+ retval.data = json["data"];
34+
35+ return retval;
36+}
37+
38+class Data {
39+ mixed|string id; // json: "id"
40+
41+ string encode_json() {
42+ mapping(string:mixed) json = ([
43+ "id" : id,
44+ ]);
45+
46+ return Standards.JSON.encode(json);
47+ }
48+}
49+
50+Data Data_from_JSON(mixed json) {
51+ Data retval = Data();
52+
53+ retval.id = json["id"];
54+
55+ return retval;
56+}
Aschema-pythondefault / quicktype.py+80 −0
@@ -0,0 +1,80 @@
1+from dataclasses import dataclass
2+from typing import Any, TypeVar, Callable, Type, cast
3+
4+
5+T = TypeVar("T")
6+
7+
8+def from_str(x: Any) -> str:
9+ assert isinstance(x, str)
10+ return x
11+
12+
13+def from_none(x: Any) -> Any:
14+ assert x is None
15+ return x
16+
17+
18+def from_union(fs, x):
19+ for f in fs:
20+ try:
21+ return f(x)
22+ except:
23+ pass
24+ assert False
25+
26+
27+def from_list(f: Callable[[Any], T], x: Any) -> list[T]:
28+ assert isinstance(x, list)
29+ return [f(y) for y in x]
30+
31+
32+def to_class(c: Type[T], x: Any) -> dict:
33+ assert isinstance(x, c)
34+ return cast(Any, x).to_dict()
35+
36+
37+@dataclass
38+class Data:
39+ id: str | None = None
40+
41+ @staticmethod
42+ def from_dict(obj: Any) -> 'Data':
43+ assert isinstance(obj, dict)
44+ id = from_union([from_str, from_none], obj.get("id"))
45+ return Data(id)
46+
47+ def to_dict(self) -> dict:
48+ result: dict = {}
49+ if self.id is not None:
50+ result["id"] = from_union([from_str, from_none], self.id)
51+ return result
52+
53+
54+@dataclass
55+class TopLevel:
56+ children: 'list[TopLevel] | None' = None
57+ data: Data | None = None
58+
59+ @staticmethod
60+ def from_dict(obj: Any) -> 'TopLevel':
61+ assert isinstance(obj, dict)
62+ children = from_union([lambda x: from_list(TopLevel.from_dict, x), from_none], obj.get("children"))
63+ data = from_union([Data.from_dict, from_none], obj.get("data"))
64+ return TopLevel(children, data)
65+
66+ def to_dict(self) -> dict:
67+ result: dict = {}
68+ if self.children is not None:
69+ result["children"] = from_union([lambda x: from_list(lambda x: to_class(TopLevel, x), x), from_none], self.children)
70+ if self.data is not None:
71+ result["data"] = from_union([lambda x: to_class(Data, x), from_none], self.data)
72+ return result
73+
74+
75+def top_level_from_dict(s: Any) -> TopLevel:
76+ return TopLevel.from_dict(s)
77+
78+
79+def top_level_to_dict(x: TopLevel) -> Any:
80+ return to_class(TopLevel, x)
Aschema-rubydefault / TopLevel.rb+73 −0
@@ -0,0 +1,73 @@
1+# This code may look unusually verbose for Ruby (and it is), but
2+# it performs some subtle and complex validation of JSON data.
3+#
4+# To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do:
5+#
6+# top_level = TopLevel.from_json! "{…}"
7+# puts top_level.data&.id
8+#
9+# If from_json! succeeds, the value returned matches the schema.
10+
11+require 'json'
12+require 'dry-types'
13+require 'dry-struct'
14+
15+module Types
16+ include Dry.Types(default: :nominal)
17+
18+ Hash = Strict::Hash
19+ String = Strict::String
20+end
21+
22+class DataClass < Dry::Struct
23+ attribute :id, Types::String.optional
24+
25+ def self.from_dynamic!(d)
26+ d = Types::Hash[d]
27+ new(
28+ id: d["id"],
29+ )
30+ end
31+
32+ def self.from_json!(json)
33+ from_dynamic!(JSON.parse(json))
34+ end
35+
36+ def to_dynamic
37+ {
38+ "id" => id,
39+ }
40+ end
41+
42+ def to_json(options = nil)
43+ JSON.generate(to_dynamic, options)
44+ end
45+end
46+
47+class TopLevel < Dry::Struct
48+ attribute :children, Types.Array(TopLevel).optional
49+ attribute :data, DataClass.optional
50+
51+ def self.from_dynamic!(d)
52+ d = Types::Hash[d]
53+ new(
54+ children: d["children"]&.map { |x| TopLevel.from_dynamic!(x) },
55+ data: d["data"] ? DataClass.from_dynamic!(d["data"]) : nil,
56+ )
57+ end
58+
59+ def self.from_json!(json)
60+ from_dynamic!(JSON.parse(json))
61+ end
62+
63+ def to_dynamic
64+ {
65+ "children" => children&.map { |x| x.to_dynamic },
66+ "data" => data&.to_dynamic,
67+ }
68+ end
69+
70+ def to_json(options = nil)
71+ JSON.generate(to_dynamic, options)
72+ end
73+end
Aschema-rustdefault / module_under_test.rs+26 −0
@@ -0,0 +1,26 @@
1+// Example code that deserializes and serializes the model.
2+// extern crate serde;
3+// #[macro_use]
4+// extern crate serde_derive;
5+// extern crate serde_json;
6+//
7+// use generated_module::TopLevel;
8+//
9+// fn main() {
10+// let json = r#"{"answer": 42}"#;
11+// let model: TopLevel = serde_json::from_str(&json).unwrap();
12+// }
13+
14+use serde::{Serialize, Deserialize};
15+
16+#[derive(Debug, Clone, Serialize, Deserialize)]
17+pub struct TopLevel {
18+ pub children: Option<Vec<TopLevel>>,
19+
20+ pub data: Option<Data>,
21+}
22+
23+#[derive(Debug, Clone, Serialize, Deserialize)]
24+pub struct Data {
25+ pub id: Option<String>,
26+}
Aschema-scala3-upickledefault / TopLevel.scala+75 −0
@@ -0,0 +1,75 @@
1+package quicktype
2+
3+// Custom pickler so that missing keys and JSON nulls both read as None,
4+// and None is left out when writing (upickle's default for Option is a
5+// JSON array).
6+object OptionPickler extends upickle.AttributeTagged:
7+ import upickle.default.Writer
8+ import upickle.default.Reader
9+ override implicit def OptionWriter[T: Writer]: Writer[Option[T]] =
10+ implicitly[Writer[T]].comap[Option[T]] {
11+ case None => null.asInstanceOf[T]
12+ case Some(x) => x
13+ }
14+
15+ override implicit def OptionReader[T: Reader]: Reader[Option[T]] = {
16+ new Reader.Delegate[Any, Option[T]](implicitly[Reader[T]].map(Some(_))){
17+ override def visitNull(index: Int) = None
18+ }
19+ }
20+end OptionPickler
21+
22+// If a union has a null in, then we'll need this too...
23+type NullValue = None.type
24+given OptionPickler.ReadWriter[NullValue] = OptionPickler.readwriter[ujson.Value].bimap[NullValue](
25+ _ => ujson.Null,
26+ json => if json.isNull then None else throw new upickle.core.Abort("not null")
27+)
28+
29+object JsonExt:
30+ val valueReader = OptionPickler.readwriter[ujson.Value]
31+
32+ // upickle's built-in primitive readers are lenient -- the numeric and
33+ // boolean readers accept strings, and the string reader accepts
34+ // numbers and booleans -- so untagged unions need strict readers to
35+ // pick the right member.
36+ val strictString: OptionPickler.Reader[String] = valueReader.map {
37+ case ujson.Str(s) => s
38+ case json => throw new upickle.core.Abort("expected string, got " + json)
39+ }
40+ val strictLong: OptionPickler.Reader[Long] = valueReader.map {
41+ case ujson.Num(n) if n.isWhole => n.toLong
42+ case json => throw new upickle.core.Abort("expected integer, got " + json)
43+ }
44+ val strictDouble: OptionPickler.Reader[Double] = valueReader.map {
45+ case ujson.Num(n) => n
46+ case json => throw new upickle.core.Abort("expected number, got " + json)
47+ }
48+ val strictBoolean: OptionPickler.Reader[Boolean] = valueReader.map {
49+ case ujson.Bool(b) => b
50+ case json => throw new upickle.core.Abort("expected boolean, got " + json)
51+ }
52+
53+ def badMerge[T](r1: => OptionPickler.Reader[?], rest: OptionPickler.Reader[?]*): OptionPickler.Reader[T] = valueReader.map { json =>
54+ var t: T | Null = null
55+ val stack = Vector.newBuilder[Throwable]
56+ (r1 +: rest).foreach { reader =>
57+ if t == null then
58+ try
59+ t = OptionPickler.read[T](json, trace = true)(using reader.asInstanceOf[OptionPickler.Reader[T]])
60+ catch
61+ case exc => stack += exc
62+ }
63+ if t != null then t.nn else throw new Exception(json.toString(), stack.result().headOption.getOrElse(null))
64+ }
65+end JsonExt
66+
67+
68+case class TopLevel (
69+ val children : Option[Seq[TopLevel]] = None,
70+ val data : Option[Data] = None
71+) derives OptionPickler.ReadWriter
72+
73+case class Data (
74+ val id : Option[String] = None
75+) derives OptionPickler.ReadWriter
Aschema-scala3default / TopLevel.scala+17 −0
@@ -0,0 +1,17 @@
1+package quicktype
2+
3+import io.circe.syntax._
4+import io.circe._
5+import cats.syntax.functor._
6+
7+// If a union has a null in, then we'll need this too...
8+type NullValue = None.type
9+
10+case class TopLevel (
11+ val children : Option[Seq[TopLevel]] = None,
12+ val data : Option[Data] = None
13+) derives Encoder.AsObject, Decoder
14+
15+case class Data (
16+ val id : Option[String] = None
17+) derives Encoder.AsObject, Decoder
Aschema-schemadefault / TopLevel.schema+34 −0
@@ -0,0 +1,34 @@
1+{
2+ "$schema": "http://json-schema.org/draft-06/schema#",
3+ "$ref": "#/definitions/TopLevel",
4+ "definitions": {
5+ "TopLevel": {
6+ "type": "object",
7+ "additionalProperties": {},
8+ "properties": {
9+ "children": {
10+ "type": "array",
11+ "items": {
12+ "$ref": "#/definitions/TopLevel"
13+ }
14+ },
15+ "data": {
16+ "$ref": "#/definitions/Data"
17+ }
18+ },
19+ "required": [],
20+ "title": "TopLevel"
21+ },
22+ "Data": {
23+ "type": "object",
24+ "additionalProperties": {},
25+ "properties": {
26+ "id": {
27+ "type": "string"
28+ }
29+ },
30+ "required": [],
31+ "title": "Data"
32+ }
33+ }
34+}
Aschema-swiftdefault / quicktype.swift+134 −0
@@ -0,0 +1,134 @@
1+// This file was generated from JSON Schema using quicktype, do not modify it directly.
2+// To parse the JSON, add this file to your project and do:
3+//
4+// let topLevel = try TopLevel(json)
5+
6+import Foundation
7+
8+// MARK: - TopLevel
9+struct TopLevel: Codable {
10+ let children: [TopLevel]?
11+ let data: DataClass?
12+
13+ enum CodingKeys: String, CodingKey {
14+ case children = "children"
15+ case data = "data"
16+ }
17+}
18+
19+// MARK: TopLevel convenience initializers and mutators
20+
21+extension TopLevel {
22+ init(data: Data) throws {
23+ self = try newJSONDecoder().decode(TopLevel.self, from: data)
24+ }
25+
26+ init(_ json: String, using encoding: String.Encoding = .utf8) throws {
27+ guard let data = json.data(using: encoding) else {
28+ throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
29+ }
30+ try self.init(data: data)
31+ }
32+
33+ init(fromURL url: URL) throws {
34+ try self.init(data: try Data(contentsOf: url))
35+ }
36+
37+ func with(
38+ children: [TopLevel]?? = nil,
39+ data: DataClass?? = nil
40+ ) -> TopLevel {
41+ return TopLevel(
42+ children: children ?? self.children,
43+ data: data ?? self.data
44+ )
45+ }
46+
47+ func jsonData() throws -> Data {
48+ return try newJSONEncoder().encode(self)
49+ }
50+
51+ func jsonString(encoding: String.Encoding = .utf8) throws -> String? {
52+ return String(data: try self.jsonData(), encoding: encoding)
53+ }
54+}
55+
56+// MARK: - DataClass
57+struct DataClass: Codable {
58+ let id: String?
59+
60+ enum CodingKeys: String, CodingKey {
61+ case id = "id"
62+ }
63+}
64+
65+// MARK: DataClass convenience initializers and mutators
66+
67+extension DataClass {
68+ init(data: Data) throws {
69+ self = try newJSONDecoder().decode(DataClass.self, from: data)
70+ }
71+
72+ init(_ json: String, using encoding: String.Encoding = .utf8) throws {
73+ guard let data = json.data(using: encoding) else {
74+ throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
75+ }
76+ try self.init(data: data)
77+ }
78+
79+ init(fromURL url: URL) throws {
80+ try self.init(data: try Data(contentsOf: url))
81+ }
82+
83+ func with(
84+ id: String?? = nil
85+ ) -> DataClass {
86+ return DataClass(
87+ id: id ?? self.id
88+ )
89+ }
90+
91+ func jsonData() throws -> Data {
92+ return try newJSONEncoder().encode(self)
93+ }
94+
95+ func jsonString(encoding: String.Encoding = .utf8) throws -> String? {
96+ return String(data: try self.jsonData(), encoding: encoding)
97+ }
98+}
99+
100+// MARK: - Helper functions for creating encoders and decoders
101+
102+func newJSONDecoder() -> JSONDecoder {
103+ let decoder = JSONDecoder()
104+ decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in
105+ let container = try decoder.singleValueContainer()
106+ let dateStr = try container.decode(String.self)
107+
108+ let formatter = DateFormatter()
109+ formatter.calendar = Calendar(identifier: .iso8601)
110+ formatter.locale = Locale(identifier: "en_US_POSIX")
111+ formatter.timeZone = TimeZone(secondsFromGMT: 0)
112+ formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
113+ if let date = formatter.date(from: dateStr) {
114+ return date
115+ }
116+ formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXXXX"
117+ if let date = formatter.date(from: dateStr) {
118+ return date
119+ }
120+ throw DecodingError.typeMismatch(Date.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Could not decode date"))
121+ })
122+ return decoder
123+}
124+
125+func newJSONEncoder() -> JSONEncoder {
126+ let encoder = JSONEncoder()
127+ let formatter = DateFormatter()
128+ formatter.calendar = Calendar(identifier: .iso8601)
129+ formatter.locale = Locale(identifier: "en_US_POSIX")
130+ formatter.timeZone = TimeZone(secondsFromGMT: 0)
131+ formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXXXX"
132+ encoder.dateEncodingStrategy = .formatted(formatter)
133+ return encoder
134+}
Aschema-typescript-zoddefault / TopLevel.ts+18 −0
@@ -0,0 +1,18 @@
1+import * as z from "zod";
2+
3+
4+export type TopLevel = {
5+ "children"?: Array<TopLevel>;
6+ "data"?: Data;
7+};
8+export const TopLevelSchema: z.ZodType<TopLevel> = z.lazy(() =>
9+ z.object({
10+ "children": z.array(TopLevelSchema).optional(),
11+ "data": DataSchema.optional(),
12+ })
13+);
14+
15+export const DataSchema = z.object({
16+ "id": z.string().optional(),
17+});
18+export type Data = z.infer<typeof DataSchema>;
Aschema-typescriptdefault / TopLevel.ts+194 −0
@@ -0,0 +1,194 @@
1+// To parse this data:
2+//
3+// import { Convert, TopLevel } from "./TopLevel";
4+//
5+// const topLevel = Convert.toTopLevel(json);
6+//
7+// These functions will throw an error if the JSON doesn't
8+// match the expected interface, even if the JSON is valid.
9+
10+export interface TopLevel {
11+ children?: TopLevel[];
12+ data?: Data;
13+ [property: string]: unknown;
14+}
15+
16+export interface Data {
17+ id?: string;
18+ [property: string]: unknown;
19+}
20+
21+// Converts JSON strings to/from your types
22+// and asserts the results of JSON.parse at runtime
23+export class Convert {
24+ public static toTopLevel(json: string): TopLevel {
25+ return cast(JSON.parse(json), r("TopLevel"));
26+ }
27+
28+ public static topLevelToJson(value: TopLevel): string {
29+ return JSON.stringify(uncast(value, r("TopLevel")), null, 2);
30+ }
31+}
32+
33+function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
34+ const prettyTyp = prettyTypeName(typ);
35+ const parentText = parent ? ` on ${parent}` : '';
36+ const keyText = key ? ` for key "${key}"` : '';
37+ throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
38+}
39+
40+function prettyTypeName(typ: any): string {
41+ if (Array.isArray(typ)) {
42+ if (typ.length === 2 && typ[0] === undefined) {
43+ return `an optional ${prettyTypeName(typ[1])}`;
44+ } else {
45+ return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
46+ }
47+ } else if (typeof typ === "object" && typ.literal !== undefined) {
48+ return typ.literal;
49+ } else {
50+ return typeof typ;
51+ }
52+}
53+
54+function jsonToJSProps(typ: any): any {
55+ if (typ.jsonToJS === undefined) {
56+ const map: any = {};
57+ typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
58+ typ.jsonToJS = map;
59+ }
60+ return typ.jsonToJS;
61+}
62+
63+function jsToJSONProps(typ: any): any {
64+ if (typ.jsToJSON === undefined) {
65+ const map: any = {};
66+ typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
67+ typ.jsToJSON = map;
68+ }
69+ return typ.jsToJSON;
70+}
71+
72+function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
73+ function transformPrimitive(typ: string, val: any): any {
74+ if (typeof typ === typeof val) return val;
75+ return invalidValue(typ, val, key, parent);
76+ }
77+
78+ function transformUnion(typs: any[], val: any): any {
79+ // val must validate against one typ in typs
80+ const l = typs.length;
81+ for (let i = 0; i < l; i++) {
82+ const typ = typs[i];
83+ try {
84+ return transform(val, typ, getProps);
85+ } catch (_) {}
86+ }
87+ return invalidValue(typs, val, key, parent);
88+ }
89+
90+ function transformEnum(cases: string[], val: any): any {
91+ if (cases.indexOf(val) !== -1) return val;
92+ return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
93+ }
94+
95+ function transformArray(typ: any, val: any): any {
96+ // val must be an array with no invalid elements
97+ if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
98+ return val.map(el => transform(el, typ, getProps));
99+ }
100+
101+ function transformDate(val: any): any {
102+ if (val === null) {
103+ return null;
104+ }
105+ const d = new Date(val);
106+ if (isNaN(d.valueOf())) {
107+ return invalidValue(l("Date"), val, key, parent);
108+ }
109+ return d;
110+ }
111+
112+ function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
113+ if (val === null || typeof val !== "object" || Array.isArray(val)) {
114+ return invalidValue(l(ref || "object"), val, key, parent);
115+ }
116+ const result: any = {};
117+ Object.getOwnPropertyNames(props).forEach(key => {
118+ const prop = props[key];
119+ const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
120+ result[prop.key] = transform(v, prop.typ, getProps, key, ref);
121+ });
122+ Object.getOwnPropertyNames(val).forEach(key => {
123+ if (!Object.prototype.hasOwnProperty.call(props, key)) {
124+ result[key] = transform(val[key], additional, getProps, key, ref);
125+ }
126+ });
127+ return result;
128+ }
129+
130+ if (typ === "any") return val;
131+ if (typ === null) {
132+ if (val === null) return val;
133+ return invalidValue(typ, val, key, parent);
134+ }
135+ if (typ === false) return invalidValue(typ, val, key, parent);
136+ let ref: any = undefined;
137+ while (typeof typ === "object" && typ.ref !== undefined) {
138+ ref = typ.ref;
139+ typ = typeMap[typ.ref];
140+ }
141+ if (Array.isArray(typ)) return transformEnum(typ, val);
142+ if (typeof typ === "object") {
143+ return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
144+ : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
145+ : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
146+ : invalidValue(typ, val, key, parent);
147+ }
148+ // Numbers can be parsed by Date but shouldn't be.
149+ if (typ === Date && typeof val !== "number") return transformDate(val);
150+ return transformPrimitive(typ, val);
151+}
152+
153+function cast<T>(val: any, typ: any): T {
154+ return transform(val, typ, jsonToJSProps);
155+}
156+
157+function uncast<T>(val: T, typ: any): any {
158+ return transform(val, typ, jsToJSONProps);
159+}
160+
161+function l(typ: any) {
162+ return { literal: typ };
163+}
164+
165+function a(typ: any) {
166+ return { arrayItems: typ };
167+}
168+
169+function u(...typs: any[]) {
170+ return { unionMembers: typs };
171+}
172+
173+function o(props: any[], additional: any) {
174+ return { props, additional };
175+}
176+
177+function m(additional: any) {
178+ const props: any[] = [];
179+ return { props, additional };
180+}
181+
182+function r(name: string) {
183+ return { ref: name };
184+}
185+
186+const typeMap: any = {
187+ "TopLevel": o([
188+ { json: "children", js: "children", typ: u(undefined, a(r("TopLevel"))) },
189+ { json: "data", js: "data", typ: u(undefined, r("Data")) },
190+ ], "any"),
191+ "Data": o([
192+ { json: "id", js: "id", typ: u(undefined, "") },
193+ ], "any"),
194+};
Test case

test/inputs/schema/recursive-union-flattening.schema

38 generated files · +633 −1,735
Mschema-csharp-recordsdefault / QuickType.cs+40 −142
@@ -23,70 +23,46 @@ namespace QuickType
2323 using Newtonsoft.Json;
2424 using Newtonsoft.Json.Converters;
2525
26- public partial record TopLevelClass
26+ public partial record A
2727 {
2828 [JsonProperty("x")]
29- public X? X { get; set; }
29+ public PurpleTopLevel? X { get; set; }
3030 }
3131
32- public partial record XClass
33- {
34- [JsonProperty("x")]
35- public X? X { get; set; }
36- }
37-
38- public partial struct X
39- {
40- public XElement[]? AnythingArray;
41- public Dictionary<string, object>? AnythingMap;
42- public bool? Bool;
43- public double? Double;
44- public long? Integer;
45- public string? String;
46-
47- public static implicit operator X(XElement[] AnythingArray) => new X { AnythingArray = AnythingArray };
48- public static implicit operator X(Dictionary<string, object> AnythingMap) => new X { AnythingMap = AnythingMap };
49- public static implicit operator X(bool Bool) => new X { Bool = Bool };
50- public static implicit operator X(double Double) => new X { Double = Double };
51- public static implicit operator X(long Integer) => new X { Integer = Integer };
52- public static implicit operator X(string String) => new X { String = String };
53- public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
54- }
55-
56- public partial struct XElement
32+ public partial struct TopLevelElement
5733 {
34+ public A? A;
5835 public object[]? AnythingArray;
5936 public bool? Bool;
6037 public double? Double;
6138 public long? Integer;
6239 public string? String;
63- public XClass? XClass;
6440
65- public static implicit operator XElement(object[] AnythingArray) => new XElement { AnythingArray = AnythingArray };
66- public static implicit operator XElement(bool Bool) => new XElement { Bool = Bool };
67- public static implicit operator XElement(double Double) => new XElement { Double = Double };
68- public static implicit operator XElement(long Integer) => new XElement { Integer = Integer };
69- public static implicit operator XElement(string String) => new XElement { String = String };
70- public static implicit operator XElement(XClass XClass) => new XElement { XClass = XClass };
71- public bool IsNull => AnythingArray == null && Bool == null && XClass == null && Double == null && Integer == null && String == null;
41+ public static implicit operator TopLevelElement(A A) => new TopLevelElement { A = A };
42+ public static implicit operator TopLevelElement(object[] AnythingArray) => new TopLevelElement { AnythingArray = AnythingArray };
43+ public static implicit operator TopLevelElement(bool Bool) => new TopLevelElement { Bool = Bool };
44+ public static implicit operator TopLevelElement(double Double) => new TopLevelElement { Double = Double };
45+ public static implicit operator TopLevelElement(long Integer) => new TopLevelElement { Integer = Integer };
46+ public static implicit operator TopLevelElement(string String) => new TopLevelElement { String = String };
47+ public bool IsNull => AnythingArray == null && Bool == null && A == null && Double == null && Integer == null && String == null;
7248 }
7349
74- public partial struct TopLevelElement
50+ public partial struct PurpleTopLevel
7551 {
76- public object[]? AnythingArray;
52+ public TopLevelElement[]? AnythingArray;
53+ public Dictionary<string, object>? AnythingMap;
7754 public bool? Bool;
7855 public double? Double;
7956 public long? Integer;
8057 public string? String;
81- public TopLevelClass? TopLevelClass;
8258
83- public static implicit operator TopLevelElement(object[] AnythingArray) => new TopLevelElement { AnythingArray = AnythingArray };
84- public static implicit operator TopLevelElement(bool Bool) => new TopLevelElement { Bool = Bool };
85- public static implicit operator TopLevelElement(double Double) => new TopLevelElement { Double = Double };
86- public static implicit operator TopLevelElement(long Integer) => new TopLevelElement { Integer = Integer };
87- public static implicit operator TopLevelElement(string String) => new TopLevelElement { String = String };
88- public static implicit operator TopLevelElement(TopLevelClass TopLevelClass) => new TopLevelElement { TopLevelClass = TopLevelClass };
89- public bool IsNull => AnythingArray == null && Bool == null && TopLevelClass == null && Double == null && Integer == null && String == null;
59+ public static implicit operator PurpleTopLevel(TopLevelElement[] AnythingArray) => new PurpleTopLevel { AnythingArray = AnythingArray };
60+ public static implicit operator PurpleTopLevel(Dictionary<string, object> AnythingMap) => new PurpleTopLevel { AnythingMap = AnythingMap };
61+ public static implicit operator PurpleTopLevel(bool Bool) => new PurpleTopLevel { Bool = Bool };
62+ public static implicit operator PurpleTopLevel(double Double) => new PurpleTopLevel { Double = Double };
63+ public static implicit operator PurpleTopLevel(long Integer) => new PurpleTopLevel { Integer = Integer };
64+ public static implicit operator PurpleTopLevel(string String) => new PurpleTopLevel { String = String };
65+ public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
9066 }
9167
9268 public partial struct TopLevelUnion
@@ -127,8 +103,7 @@ namespace QuickType
127103 {
128104 TopLevelUnionConverter.Singleton,
129105 TopLevelElementConverter.Singleton,
130- XConverter.Singleton,
131- XElementConverter.Singleton,
106+ PurpleTopLevelConverter.Singleton,
132107 new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
133108 },
134109 };
@@ -235,8 +210,8 @@ namespace QuickType
235210 var stringValue = serializer.Deserialize<string>(reader);
236211 return new TopLevelElement { String = stringValue };
237212 case JsonToken.StartObject:
238- var objectValue = serializer.Deserialize<TopLevelClass>(reader);
239- return new TopLevelElement { TopLevelClass = objectValue };
213+ var objectValue = serializer.Deserialize<A>(reader);
214+ return new TopLevelElement { A = objectValue };
240215 case JsonToken.StartArray:
241216 var arrayValue = serializer.Deserialize<object[]>(reader);
242217 return new TopLevelElement { AnythingArray = arrayValue };
@@ -277,9 +252,9 @@ namespace QuickType
277252 serializer.Serialize(writer, value.AnythingArray);
278253 return;
279254 }
280- if (value.TopLevelClass != null)
255+ if (value.A != null)
281256 {
282- serializer.Serialize(writer, value.TopLevelClass);
257+ serializer.Serialize(writer, value.A);
283258 return;
284259 }
285260 throw new Exception("Cannot marshal type TopLevelElement");
@@ -288,42 +263,42 @@ namespace QuickType
288263 public static readonly TopLevelElementConverter Singleton = new TopLevelElementConverter();
289264 }
290265
291- internal class XConverter : JsonConverter
266+ internal class PurpleTopLevelConverter : JsonConverter
292267 {
293- public override bool CanConvert(Type t) => t == typeof(X) || t == typeof(X?);
268+ public override bool CanConvert(Type t) => t == typeof(PurpleTopLevel) || t == typeof(PurpleTopLevel?);
294269
295270 public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
296271 {
297272 switch (reader.TokenType)
298273 {
299274 case JsonToken.Null:
300- return new X { };
275+ return new PurpleTopLevel { };
301276 case JsonToken.Integer:
302277 var integerValue = serializer.Deserialize<long>(reader);
303- return new X { Integer = integerValue };
278+ return new PurpleTopLevel { Integer = integerValue };
304279 case JsonToken.Float:
305280 var doubleValue = serializer.Deserialize<double>(reader);
306- return new X { Double = doubleValue };
281+ return new PurpleTopLevel { Double = doubleValue };
307282 case JsonToken.Boolean:
308283 var boolValue = serializer.Deserialize<bool>(reader);
309- return new X { Bool = boolValue };
284+ return new PurpleTopLevel { Bool = boolValue };
310285 case JsonToken.String:
311286 case JsonToken.Date:
312287 var stringValue = serializer.Deserialize<string>(reader);
313- return new X { String = stringValue };
288+ return new PurpleTopLevel { String = stringValue };
314289 case JsonToken.StartObject:
315290 var objectValue = serializer.Deserialize<Dictionary<string, object>>(reader);
316- return new X { AnythingMap = objectValue };
291+ return new PurpleTopLevel { AnythingMap = objectValue };
317292 case JsonToken.StartArray:
318- var arrayValue = serializer.Deserialize<XElement[]>(reader);
319- return new X { AnythingArray = arrayValue };
293+ var arrayValue = serializer.Deserialize<TopLevelElement[]>(reader);
294+ return new PurpleTopLevel { AnythingArray = arrayValue };
320295 }
321- throw new Exception("Cannot unmarshal type X");
296+ throw new Exception("Cannot unmarshal type PurpleTopLevel");
322297 }
323298
324299 public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
325300 {
326- var value = (X)untypedValue;
301+ var value = (PurpleTopLevel)untypedValue;
327302 if (value.IsNull)
328303 {
329304 serializer.Serialize(writer, null);
@@ -359,87 +334,10 @@ namespace QuickType
359334 serializer.Serialize(writer, value.AnythingMap);
360335 return;
361336 }
362- throw new Exception("Cannot marshal type X");
363- }
364-
365- public static readonly XConverter Singleton = new XConverter();
366- }
367-
368- internal class XElementConverter : JsonConverter
369- {
370- public override bool CanConvert(Type t) => t == typeof(XElement) || t == typeof(XElement?);
371-
372- public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
373- {
374- switch (reader.TokenType)
375- {
376- case JsonToken.Null:
377- return new XElement { };
378- case JsonToken.Integer:
379- var integerValue = serializer.Deserialize<long>(reader);
380- return new XElement { Integer = integerValue };
381- case JsonToken.Float:
382- var doubleValue = serializer.Deserialize<double>(reader);
383- return new XElement { Double = doubleValue };
384- case JsonToken.Boolean:
385- var boolValue = serializer.Deserialize<bool>(reader);
386- return new XElement { Bool = boolValue };
387- case JsonToken.String:
388- case JsonToken.Date:
389- var stringValue = serializer.Deserialize<string>(reader);
390- return new XElement { String = stringValue };
391- case JsonToken.StartObject:
392- var objectValue = serializer.Deserialize<XClass>(reader);
393- return new XElement { XClass = objectValue };
394- case JsonToken.StartArray:
395- var arrayValue = serializer.Deserialize<object[]>(reader);
396- return new XElement { AnythingArray = arrayValue };
397- }
398- throw new Exception("Cannot unmarshal type XElement");
399- }
400-
401- public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
402- {
403- var value = (XElement)untypedValue;
404- if (value.IsNull)
405- {
406- serializer.Serialize(writer, null);
407- return;
408- }
409- if (value.Integer != null)
410- {
411- serializer.Serialize(writer, value.Integer.Value);
412- return;
413- }
414- if (value.Double != null)
415- {
416- serializer.Serialize(writer, value.Double.Value);
417- return;
418- }
419- if (value.Bool != null)
420- {
421- serializer.Serialize(writer, value.Bool.Value);
422- return;
423- }
424- if (value.String != null)
425- {
426- serializer.Serialize(writer, value.String);
427- return;
428- }
429- if (value.AnythingArray != null)
430- {
431- serializer.Serialize(writer, value.AnythingArray);
432- return;
433- }
434- if (value.XClass != null)
435- {
436- serializer.Serialize(writer, value.XClass);
437- return;
438- }
439- throw new Exception("Cannot marshal type XElement");
337+ throw new Exception("Cannot marshal type PurpleTopLevel");
440338 }
441339
442- public static readonly XElementConverter Singleton = new XElementConverter();
340+ public static readonly PurpleTopLevelConverter Singleton = new PurpleTopLevelConverter();
443341 }
444342 }
445343 #pragma warning restore CS8618
Mschema-csharp-SystemTextJsondefault / QuickType.cs+42 −148
@@ -20,70 +20,46 @@ namespace QuickType
2020 using System.Text.Json.Serialization;
2121 using System.Globalization;
2222
23- public partial class TopLevelClass
23+ public partial class A
2424 {
2525 [JsonPropertyName("x")]
26- public X? X { get; set; }
26+ public PurpleTopLevel? X { get; set; }
2727 }
2828
29- public partial class XClass
30- {
31- [JsonPropertyName("x")]
32- public X? X { get; set; }
33- }
34-
35- public partial struct X
36- {
37- public XElement[]? AnythingArray;
38- public Dictionary<string, object>? AnythingMap;
39- public bool? Bool;
40- public double? Double;
41- public long? Integer;
42- public string? String;
43-
44- public static implicit operator X(XElement[] AnythingArray) => new X { AnythingArray = AnythingArray };
45- public static implicit operator X(Dictionary<string, object> AnythingMap) => new X { AnythingMap = AnythingMap };
46- public static implicit operator X(bool Bool) => new X { Bool = Bool };
47- public static implicit operator X(double Double) => new X { Double = Double };
48- public static implicit operator X(long Integer) => new X { Integer = Integer };
49- public static implicit operator X(string String) => new X { String = String };
50- public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
51- }
52-
53- public partial struct XElement
29+ public partial struct TopLevelElement
5430 {
31+ public A? A;
5532 public object[]? AnythingArray;
5633 public bool? Bool;
5734 public double? Double;
5835 public long? Integer;
5936 public string? String;
60- public XClass? XClass;
61-
62- public static implicit operator XElement(object[] AnythingArray) => new XElement { AnythingArray = AnythingArray };
63- public static implicit operator XElement(bool Bool) => new XElement { Bool = Bool };
64- public static implicit operator XElement(double Double) => new XElement { Double = Double };
65- public static implicit operator XElement(long Integer) => new XElement { Integer = Integer };
66- public static implicit operator XElement(string String) => new XElement { String = String };
67- public static implicit operator XElement(XClass XClass) => new XElement { XClass = XClass };
68- public bool IsNull => AnythingArray == null && Bool == null && XClass == null && Double == null && Integer == null && String == null;
37+
38+ public static implicit operator TopLevelElement(A A) => new TopLevelElement { A = A };
39+ public static implicit operator TopLevelElement(object[] AnythingArray) => new TopLevelElement { AnythingArray = AnythingArray };
40+ public static implicit operator TopLevelElement(bool Bool) => new TopLevelElement { Bool = Bool };
41+ public static implicit operator TopLevelElement(double Double) => new TopLevelElement { Double = Double };
42+ public static implicit operator TopLevelElement(long Integer) => new TopLevelElement { Integer = Integer };
43+ public static implicit operator TopLevelElement(string String) => new TopLevelElement { String = String };
44+ public bool IsNull => AnythingArray == null && Bool == null && A == null && Double == null && Integer == null && String == null;
6945 }
7046
71- public partial struct TopLevelElement
47+ public partial struct PurpleTopLevel
7248 {
73- public object[]? AnythingArray;
49+ public TopLevelElement[]? AnythingArray;
50+ public Dictionary<string, object>? AnythingMap;
7451 public bool? Bool;
7552 public double? Double;
7653 public long? Integer;
7754 public string? String;
78- public TopLevelClass? TopLevelClass;
7955
80- public static implicit operator TopLevelElement(object[] AnythingArray) => new TopLevelElement { AnythingArray = AnythingArray };
81- public static implicit operator TopLevelElement(bool Bool) => new TopLevelElement { Bool = Bool };
82- public static implicit operator TopLevelElement(double Double) => new TopLevelElement { Double = Double };
83- public static implicit operator TopLevelElement(long Integer) => new TopLevelElement { Integer = Integer };
84- public static implicit operator TopLevelElement(string String) => new TopLevelElement { String = String };
85- public static implicit operator TopLevelElement(TopLevelClass TopLevelClass) => new TopLevelElement { TopLevelClass = TopLevelClass };
86- public bool IsNull => AnythingArray == null && Bool == null && TopLevelClass == null && Double == null && Integer == null && String == null;
56+ public static implicit operator PurpleTopLevel(TopLevelElement[] AnythingArray) => new PurpleTopLevel { AnythingArray = AnythingArray };
57+ public static implicit operator PurpleTopLevel(Dictionary<string, object> AnythingMap) => new PurpleTopLevel { AnythingMap = AnythingMap };
58+ public static implicit operator PurpleTopLevel(bool Bool) => new PurpleTopLevel { Bool = Bool };
59+ public static implicit operator PurpleTopLevel(double Double) => new PurpleTopLevel { Double = Double };
60+ public static implicit operator PurpleTopLevel(long Integer) => new PurpleTopLevel { Integer = Integer };
61+ public static implicit operator PurpleTopLevel(string String) => new PurpleTopLevel { String = String };
62+ public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
8763 }
8864
8965 public partial struct TopLevelUnion
@@ -122,8 +98,7 @@ namespace QuickType
12298 {
12399 TopLevelUnionConverter.Singleton,
124100 TopLevelElementConverter.Singleton,
125- XConverter.Singleton,
126- XElementConverter.Singleton,
101+ PurpleTopLevelConverter.Singleton,
127102 new DateOnlyConverter(),
128103 new TimeOnlyConverter(),
129104 IsoDateTimeOffsetConverter.Singleton
@@ -241,8 +216,8 @@ namespace QuickType
241216 var stringValue = reader.GetString();
242217 return new TopLevelElement { String = stringValue };
243218 case JsonTokenType.StartObject:
244- var objectValue = JsonSerializer.Deserialize<TopLevelClass>(ref reader, options);
245- return new TopLevelElement { TopLevelClass = objectValue };
219+ var objectValue = JsonSerializer.Deserialize<A>(ref reader, options);
220+ return new TopLevelElement { A = objectValue };
246221 case JsonTokenType.StartArray:
247222 var arrayValue = JsonSerializer.Deserialize<object[]>(ref reader, options);
248223 return new TopLevelElement { AnythingArray = arrayValue };
@@ -282,9 +257,9 @@ namespace QuickType
282257 JsonSerializer.Serialize(writer, value.AnythingArray, options);
283258 return;
284259 }
285- if (value.TopLevelClass != null)
260+ if (value.A != null)
286261 {
287- JsonSerializer.Serialize(writer, value.TopLevelClass, options);
262+ JsonSerializer.Serialize(writer, value.A, options);
288263 return;
289264 }
290265 throw new NotSupportedException("Cannot marshal type TopLevelElement");
@@ -293,45 +268,45 @@ namespace QuickType
293268 public static readonly TopLevelElementConverter Singleton = new TopLevelElementConverter();
294269 }
295270
296- internal class XConverter : JsonConverter<X>
271+ internal class PurpleTopLevelConverter : JsonConverter<PurpleTopLevel>
297272 {
298- public override bool CanConvert(Type t) => t == typeof(X);
273+ public override bool CanConvert(Type t) => t == typeof(PurpleTopLevel);
299274
300- public override X Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
275+ public override PurpleTopLevel Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
301276 {
302277 switch (reader.TokenType)
303278 {
304279 case JsonTokenType.Null:
305- return new X { };
280+ return new PurpleTopLevel { };
306281 case JsonTokenType.Number:
307282 if (reader.TryGetInt64(out long intTryValue1))
308283 {
309284 var intValue2 = reader.GetInt64();
310- return new X { Integer = intValue2 };
285+ return new PurpleTopLevel { Integer = intValue2 };
311286 }
312287 else
313288 {
314289 var doubleValue3 = reader.GetDouble();
315- return new X { Double = doubleValue3 };
290+ return new PurpleTopLevel { Double = doubleValue3 };
316291 }
317292 case JsonTokenType.True:
318293 case JsonTokenType.False:
319294 var boolValue = reader.GetBoolean();
320- return new X { Bool = boolValue };
295+ return new PurpleTopLevel { Bool = boolValue };
321296 case JsonTokenType.String:
322297 var stringValue = reader.GetString();
323- return new X { String = stringValue };
298+ return new PurpleTopLevel { String = stringValue };
324299 case JsonTokenType.StartObject:
325300 var objectValue = JsonSerializer.Deserialize<Dictionary<string, object>>(ref reader, options);
326- return new X { AnythingMap = objectValue };
301+ return new PurpleTopLevel { AnythingMap = objectValue };
327302 case JsonTokenType.StartArray:
328- var arrayValue = JsonSerializer.Deserialize<XElement[]>(ref reader, options);
329- return new X { AnythingArray = arrayValue };
303+ var arrayValue = JsonSerializer.Deserialize<TopLevelElement[]>(ref reader, options);
304+ return new PurpleTopLevel { AnythingArray = arrayValue };
330305 }
331- throw new JsonException("Cannot unmarshal type X");
306+ throw new JsonException("Cannot unmarshal type PurpleTopLevel");
332307 }
333308
334- public override void Write(Utf8JsonWriter writer, X value, JsonSerializerOptions options)
309+ public override void Write(Utf8JsonWriter writer, PurpleTopLevel value, JsonSerializerOptions options)
335310 {
336311 if (value.IsNull)
337312 {
@@ -368,91 +343,10 @@ namespace QuickType
368343 JsonSerializer.Serialize(writer, value.AnythingMap, options);
369344 return;
370345 }
371- throw new NotSupportedException("Cannot marshal type X");
372- }
373-
374- public static readonly XConverter Singleton = new XConverter();
375- }
376-
377- internal class XElementConverter : JsonConverter<XElement>
378- {
379- public override bool CanConvert(Type t) => t == typeof(XElement);
380-
381- public override XElement Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
382- {
383- switch (reader.TokenType)
384- {
385- case JsonTokenType.Null:
386- return new XElement { };
387- case JsonTokenType.Number:
388- if (reader.TryGetInt64(out long intTryValue1))
389- {
390- var intValue2 = reader.GetInt64();
391- return new XElement { Integer = intValue2 };
392- }
393- else
394- {
395- var doubleValue3 = reader.GetDouble();
396- return new XElement { Double = doubleValue3 };
397- }
398- case JsonTokenType.True:
399- case JsonTokenType.False:
400- var boolValue = reader.GetBoolean();
401- return new XElement { Bool = boolValue };
402- case JsonTokenType.String:
403- var stringValue = reader.GetString();
404- return new XElement { String = stringValue };
405- case JsonTokenType.StartObject:
406- var objectValue = JsonSerializer.Deserialize<XClass>(ref reader, options);
407- return new XElement { XClass = objectValue };
408- case JsonTokenType.StartArray:
409- var arrayValue = JsonSerializer.Deserialize<object[]>(ref reader, options);
410- return new XElement { AnythingArray = arrayValue };
411- }
412- throw new JsonException("Cannot unmarshal type XElement");
413- }
414-
415- public override void Write(Utf8JsonWriter writer, XElement value, JsonSerializerOptions options)
416- {
417- if (value.IsNull)
418- {
419- writer.WriteNullValue();
420- return;
421- }
422- if (value.Integer != null)
423- {
424- JsonSerializer.Serialize(writer, value.Integer.Value, options);
425- return;
426- }
427- if (value.Double != null)
428- {
429- JsonSerializer.Serialize(writer, value.Double.Value, options);
430- return;
431- }
432- if (value.Bool != null)
433- {
434- JsonSerializer.Serialize(writer, value.Bool.Value, options);
435- return;
436- }
437- if (value.String != null)
438- {
439- JsonSerializer.Serialize(writer, value.String, options);
440- return;
441- }
442- if (value.AnythingArray != null)
443- {
444- JsonSerializer.Serialize(writer, value.AnythingArray, options);
445- return;
446- }
447- if (value.XClass != null)
448- {
449- JsonSerializer.Serialize(writer, value.XClass, options);
450- return;
451- }
452- throw new NotSupportedException("Cannot marshal type XElement");
346+ throw new NotSupportedException("Cannot marshal type PurpleTopLevel");
453347 }
454348
455- public static readonly XElementConverter Singleton = new XElementConverter();
349+ public static readonly PurpleTopLevelConverter Singleton = new PurpleTopLevelConverter();
456350 }
457351
458352 public class DateOnlyConverter : JsonConverter<DateOnly>
Mschema-csharpdefault / QuickType.cs+40 −142
@@ -23,70 +23,46 @@ namespace QuickType
2323 using Newtonsoft.Json;
2424 using Newtonsoft.Json.Converters;
2525
26- public partial class TopLevelClass
26+ public partial class A
2727 {
2828 [JsonProperty("x")]
29- public X? X { get; set; }
29+ public PurpleTopLevel? X { get; set; }
3030 }
3131
32- public partial class XClass
33- {
34- [JsonProperty("x")]
35- public X? X { get; set; }
36- }
37-
38- public partial struct X
39- {
40- public XElement[]? AnythingArray;
41- public Dictionary<string, object>? AnythingMap;
42- public bool? Bool;
43- public double? Double;
44- public long? Integer;
45- public string? String;
46-
47- public static implicit operator X(XElement[] AnythingArray) => new X { AnythingArray = AnythingArray };
48- public static implicit operator X(Dictionary<string, object> AnythingMap) => new X { AnythingMap = AnythingMap };
49- public static implicit operator X(bool Bool) => new X { Bool = Bool };
50- public static implicit operator X(double Double) => new X { Double = Double };
51- public static implicit operator X(long Integer) => new X { Integer = Integer };
52- public static implicit operator X(string String) => new X { String = String };
53- public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
54- }
55-
56- public partial struct XElement
32+ public partial struct TopLevelElement
5733 {
34+ public A? A;
5835 public object[]? AnythingArray;
5936 public bool? Bool;
6037 public double? Double;
6138 public long? Integer;
6239 public string? String;
63- public XClass? XClass;
6440
65- public static implicit operator XElement(object[] AnythingArray) => new XElement { AnythingArray = AnythingArray };
66- public static implicit operator XElement(bool Bool) => new XElement { Bool = Bool };
67- public static implicit operator XElement(double Double) => new XElement { Double = Double };
68- public static implicit operator XElement(long Integer) => new XElement { Integer = Integer };
69- public static implicit operator XElement(string String) => new XElement { String = String };
70- public static implicit operator XElement(XClass XClass) => new XElement { XClass = XClass };
71- public bool IsNull => AnythingArray == null && Bool == null && XClass == null && Double == null && Integer == null && String == null;
41+ public static implicit operator TopLevelElement(A A) => new TopLevelElement { A = A };
42+ public static implicit operator TopLevelElement(object[] AnythingArray) => new TopLevelElement { AnythingArray = AnythingArray };
43+ public static implicit operator TopLevelElement(bool Bool) => new TopLevelElement { Bool = Bool };
44+ public static implicit operator TopLevelElement(double Double) => new TopLevelElement { Double = Double };
45+ public static implicit operator TopLevelElement(long Integer) => new TopLevelElement { Integer = Integer };
46+ public static implicit operator TopLevelElement(string String) => new TopLevelElement { String = String };
47+ public bool IsNull => AnythingArray == null && Bool == null && A == null && Double == null && Integer == null && String == null;
7248 }
7349
74- public partial struct TopLevelElement
50+ public partial struct PurpleTopLevel
7551 {
76- public object[]? AnythingArray;
52+ public TopLevelElement[]? AnythingArray;
53+ public Dictionary<string, object>? AnythingMap;
7754 public bool? Bool;
7855 public double? Double;
7956 public long? Integer;
8057 public string? String;
81- public TopLevelClass? TopLevelClass;
8258
83- public static implicit operator TopLevelElement(object[] AnythingArray) => new TopLevelElement { AnythingArray = AnythingArray };
84- public static implicit operator TopLevelElement(bool Bool) => new TopLevelElement { Bool = Bool };
85- public static implicit operator TopLevelElement(double Double) => new TopLevelElement { Double = Double };
86- public static implicit operator TopLevelElement(long Integer) => new TopLevelElement { Integer = Integer };
87- public static implicit operator TopLevelElement(string String) => new TopLevelElement { String = String };
88- public static implicit operator TopLevelElement(TopLevelClass TopLevelClass) => new TopLevelElement { TopLevelClass = TopLevelClass };
89- public bool IsNull => AnythingArray == null && Bool == null && TopLevelClass == null && Double == null && Integer == null && String == null;
59+ public static implicit operator PurpleTopLevel(TopLevelElement[] AnythingArray) => new PurpleTopLevel { AnythingArray = AnythingArray };
60+ public static implicit operator PurpleTopLevel(Dictionary<string, object> AnythingMap) => new PurpleTopLevel { AnythingMap = AnythingMap };
61+ public static implicit operator PurpleTopLevel(bool Bool) => new PurpleTopLevel { Bool = Bool };
62+ public static implicit operator PurpleTopLevel(double Double) => new PurpleTopLevel { Double = Double };
63+ public static implicit operator PurpleTopLevel(long Integer) => new PurpleTopLevel { Integer = Integer };
64+ public static implicit operator PurpleTopLevel(string String) => new PurpleTopLevel { String = String };
65+ public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
9066 }
9167
9268 public partial struct TopLevelUnion
@@ -127,8 +103,7 @@ namespace QuickType
127103 {
128104 TopLevelUnionConverter.Singleton,
129105 TopLevelElementConverter.Singleton,
130- XConverter.Singleton,
131- XElementConverter.Singleton,
106+ PurpleTopLevelConverter.Singleton,
132107 new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
133108 },
134109 };
@@ -235,8 +210,8 @@ namespace QuickType
235210 var stringValue = serializer.Deserialize<string>(reader);
236211 return new TopLevelElement { String = stringValue };
237212 case JsonToken.StartObject:
238- var objectValue = serializer.Deserialize<TopLevelClass>(reader);
239- return new TopLevelElement { TopLevelClass = objectValue };
213+ var objectValue = serializer.Deserialize<A>(reader);
214+ return new TopLevelElement { A = objectValue };
240215 case JsonToken.StartArray:
241216 var arrayValue = serializer.Deserialize<object[]>(reader);
242217 return new TopLevelElement { AnythingArray = arrayValue };
@@ -277,9 +252,9 @@ namespace QuickType
277252 serializer.Serialize(writer, value.AnythingArray);
278253 return;
279254 }
280- if (value.TopLevelClass != null)
255+ if (value.A != null)
281256 {
282- serializer.Serialize(writer, value.TopLevelClass);
257+ serializer.Serialize(writer, value.A);
283258 return;
284259 }
285260 throw new Exception("Cannot marshal type TopLevelElement");
@@ -288,42 +263,42 @@ namespace QuickType
288263 public static readonly TopLevelElementConverter Singleton = new TopLevelElementConverter();
289264 }
290265
291- internal class XConverter : JsonConverter
266+ internal class PurpleTopLevelConverter : JsonConverter
292267 {
293- public override bool CanConvert(Type t) => t == typeof(X) || t == typeof(X?);
268+ public override bool CanConvert(Type t) => t == typeof(PurpleTopLevel) || t == typeof(PurpleTopLevel?);
294269
295270 public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
296271 {
297272 switch (reader.TokenType)
298273 {
299274 case JsonToken.Null:
300- return new X { };
275+ return new PurpleTopLevel { };
301276 case JsonToken.Integer:
302277 var integerValue = serializer.Deserialize<long>(reader);
303- return new X { Integer = integerValue };
278+ return new PurpleTopLevel { Integer = integerValue };
304279 case JsonToken.Float:
305280 var doubleValue = serializer.Deserialize<double>(reader);
306- return new X { Double = doubleValue };
281+ return new PurpleTopLevel { Double = doubleValue };
307282 case JsonToken.Boolean:
308283 var boolValue = serializer.Deserialize<bool>(reader);
309- return new X { Bool = boolValue };
284+ return new PurpleTopLevel { Bool = boolValue };
310285 case JsonToken.String:
311286 case JsonToken.Date:
312287 var stringValue = serializer.Deserialize<string>(reader);
313- return new X { String = stringValue };
288+ return new PurpleTopLevel { String = stringValue };
314289 case JsonToken.StartObject:
315290 var objectValue = serializer.Deserialize<Dictionary<string, object>>(reader);
316- return new X { AnythingMap = objectValue };
291+ return new PurpleTopLevel { AnythingMap = objectValue };
317292 case JsonToken.StartArray:
318- var arrayValue = serializer.Deserialize<XElement[]>(reader);
319- return new X { AnythingArray = arrayValue };
293+ var arrayValue = serializer.Deserialize<TopLevelElement[]>(reader);
294+ return new PurpleTopLevel { AnythingArray = arrayValue };
320295 }
321- throw new Exception("Cannot unmarshal type X");
296+ throw new Exception("Cannot unmarshal type PurpleTopLevel");
322297 }
323298
324299 public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
325300 {
326- var value = (X)untypedValue;
301+ var value = (PurpleTopLevel)untypedValue;
327302 if (value.IsNull)
328303 {
329304 serializer.Serialize(writer, null);
@@ -359,87 +334,10 @@ namespace QuickType
359334 serializer.Serialize(writer, value.AnythingMap);
360335 return;
361336 }
362- throw new Exception("Cannot marshal type X");
363- }
364-
365- public static readonly XConverter Singleton = new XConverter();
366- }
367-
368- internal class XElementConverter : JsonConverter
369- {
370- public override bool CanConvert(Type t) => t == typeof(XElement) || t == typeof(XElement?);
371-
372- public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
373- {
374- switch (reader.TokenType)
375- {
376- case JsonToken.Null:
377- return new XElement { };
378- case JsonToken.Integer:
379- var integerValue = serializer.Deserialize<long>(reader);
380- return new XElement { Integer = integerValue };
381- case JsonToken.Float:
382- var doubleValue = serializer.Deserialize<double>(reader);
383- return new XElement { Double = doubleValue };
384- case JsonToken.Boolean:
385- var boolValue = serializer.Deserialize<bool>(reader);
386- return new XElement { Bool = boolValue };
387- case JsonToken.String:
388- case JsonToken.Date:
389- var stringValue = serializer.Deserialize<string>(reader);
390- return new XElement { String = stringValue };
391- case JsonToken.StartObject:
392- var objectValue = serializer.Deserialize<XClass>(reader);
393- return new XElement { XClass = objectValue };
394- case JsonToken.StartArray:
395- var arrayValue = serializer.Deserialize<object[]>(reader);
396- return new XElement { AnythingArray = arrayValue };
397- }
398- throw new Exception("Cannot unmarshal type XElement");
399- }
400-
401- public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
402- {
403- var value = (XElement)untypedValue;
404- if (value.IsNull)
405- {
406- serializer.Serialize(writer, null);
407- return;
408- }
409- if (value.Integer != null)
410- {
411- serializer.Serialize(writer, value.Integer.Value);
412- return;
413- }
414- if (value.Double != null)
415- {
416- serializer.Serialize(writer, value.Double.Value);
417- return;
418- }
419- if (value.Bool != null)
420- {
421- serializer.Serialize(writer, value.Bool.Value);
422- return;
423- }
424- if (value.String != null)
425- {
426- serializer.Serialize(writer, value.String);
427- return;
428- }
429- if (value.AnythingArray != null)
430- {
431- serializer.Serialize(writer, value.AnythingArray);
432- return;
433- }
434- if (value.XClass != null)
435- {
436- serializer.Serialize(writer, value.XClass);
437- return;
438- }
439- throw new Exception("Cannot marshal type XElement");
337+ throw new Exception("Cannot marshal type PurpleTopLevel");
440338 }
441339
442- public static readonly XElementConverter Singleton = new XElementConverter();
340+ public static readonly PurpleTopLevelConverter Singleton = new PurpleTopLevelConverter();
443341 }
444342 }
445343 #pragma warning restore CS8618
Mschema-dartdefault / TopLevel.dart+3 −19
@@ -8,30 +8,14 @@ dynamic topLevelFromJson(String str) => json.decode(str);
88
99 String topLevelToJson(dynamic data) => json.encode(data);
1010
11-class TopLevelClass {
11+class A {
1212 final dynamic x;
1313
14- TopLevelClass({
14+ A({
1515 this.x,
1616 });
1717
18- factory TopLevelClass.fromJson(Map<String, dynamic> json) => TopLevelClass(
19- x: json["x"],
20- );
21-
22- Map<String, dynamic> toJson() => {
23- "x": x,
24- };
25-}
26-
27-class XClass {
28- final dynamic x;
29-
30- XClass({
31- this.x,
32- });
33-
34- factory XClass.fromJson(Map<String, dynamic> json) => XClass(
18+ factory A.fromJson(Map<String, dynamic> json) => A(
3519 x: json["x"],
3620 );
Mschema-flowdefault / TopLevel.js+8 −18
@@ -11,30 +11,23 @@
1111
1212 export type TopLevel = TopLevelElement[] | boolean | number | number | { [key: string]: mixed } | null | string;
1313
14-export type TopLevelElement = mixed[] | boolean | number | null | TopLevelObject | string;
14+export type PurpleTopLevel = TopLevelElement[] | boolean | number | { [key: string]: mixed } | null | string;
1515
16-export type TopLevelObject = {
17- x?: X;
16+export type A = {
17+ x?: PurpleTopLevel;
1818 [property: string]: mixed;
1919 };
2020
21-export type XObject = {
22- x?: X;
23- [property: string]: mixed;
24-};
25-
26-export type XElement = mixed[] | boolean | number | null | XObject | string;
27-
28-export type X = XElement[] | boolean | number | { [key: string]: mixed } | null | string;
21+export type TopLevelElement = mixed[] | boolean | number | null | A | string;
2922
3023 // Converts JSON strings to/from your types
3124 // and asserts the results of JSON.parse at runtime
3225 function toTopLevel(json: string): TopLevel {
33- return cast(JSON.parse(json), u(a(u(a("any"), true, 3.14, null, r("TopLevelObject"), "")), true, 3.14, 0, m("any"), null, ""));
26+ return cast(JSON.parse(json), u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, 0, m("any"), null, ""));
3427 }
3528
3629 function topLevelToJson(value: TopLevel): string {
37- return JSON.stringify(uncast(value, u(a(u(a("any"), true, 3.14, null, r("TopLevelObject"), "")), true, 3.14, 0, m("any"), null, "")), null, 2);
30+ return JSON.stringify(uncast(value, u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, 0, m("any"), null, "")), null, 2);
3831 }
3932
4033 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -191,11 +184,8 @@ function r(name: string) {
191184 }
192185
193186 const typeMap: any = {
194- "TopLevelObject": o([
195- { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("XObject"), "")), true, 3.14, m("any"), null, "")) },
196- ], "any"),
197- "XObject": o([
198- { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("XObject"), "")), true, 3.14, m("any"), null, "")) },
187+ "A": o([
188+ { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, m("any"), null, "")) },
199189 ], "any"),
200190 };
Mschema-golangdefault / quicktype.go+23 −54
@@ -21,12 +21,8 @@ func (r *TopLevel) Marshal() ([]byte, error) {
2121 return json.Marshal(r)
2222 }
2323
24-type TopLevelClass struct {
25- X *X `json:"x"`
26-}
27-
28-type XClass struct {
29- X *X `json:"x"`
24+type A struct {
25+ X *PurpleTopLevel `json:"x"`
3026 }
3127
3228 type TopLevel struct {
@@ -54,83 +50,56 @@ func (x *TopLevel) MarshalJSON() ([]byte, error) {
5450 return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.UnionArray != nil, x.UnionArray, false, nil, x.AnythingMap != nil, x.AnythingMap, false, nil, true)
5551 }
5652
57-type TopLevelElement struct {
58- AnythingArray []interface{}
59- Bool *bool
60- Double *float64
61- Integer *int64
62- String *string
63- TopLevelClass *TopLevelClass
53+type PurpleTopLevel struct {
54+ AnythingMap map[string]interface{}
55+ Bool *bool
56+ Double *float64
57+ Integer *int64
58+ String *string
59+ UnionArray []TopLevelElement
6460 }
6561
66-func (x *TopLevelElement) UnmarshalJSON(data []byte) error {
67- x.AnythingArray = nil
68- x.TopLevelClass = nil
69- var c TopLevelClass
70- object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true)
62+func (x *PurpleTopLevel) UnmarshalJSON(data []byte) error {
63+ x.UnionArray = nil
64+ x.AnythingMap = nil
65+ object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.UnionArray, false, nil, true, &x.AnythingMap, false, nil, true)
7166 if err != nil {
7267 return err
7368 }
7469 if object {
75- x.TopLevelClass = &c
7670 }
7771 return nil
7872 }
7973
80-func (x *TopLevelElement) MarshalJSON() ([]byte, error) {
81- return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.TopLevelClass != nil, x.TopLevelClass, false, nil, false, nil, true)
74+func (x *PurpleTopLevel) MarshalJSON() ([]byte, error) {
75+ return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.UnionArray != nil, x.UnionArray, false, nil, x.AnythingMap != nil, x.AnythingMap, false, nil, true)
8276 }
8377
84-type XElement struct {
78+type TopLevelElement struct {
79+ A *A
8580 AnythingArray []interface{}
8681 Bool *bool
8782 Double *float64
8883 Integer *int64
8984 String *string
90- XClass *XClass
9185 }
9286
93-func (x *XElement) UnmarshalJSON(data []byte) error {
87+func (x *TopLevelElement) UnmarshalJSON(data []byte) error {
9488 x.AnythingArray = nil
95- x.XClass = nil
96- var c XClass
89+ x.A = nil
90+ var c A
9791 object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true)
9892 if err != nil {
9993 return err
10094 }
10195 if object {
102- x.XClass = &c
96+ x.A = &c
10397 }
10498 return nil
10599 }
106100
107-func (x *XElement) MarshalJSON() ([]byte, error) {
108- return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.XClass != nil, x.XClass, false, nil, false, nil, true)
109-}
110-
111-type X struct {
112- AnythingMap map[string]interface{}
113- Bool *bool
114- Double *float64
115- Integer *int64
116- String *string
117- UnionArray []XElement
118-}
119-
120-func (x *X) UnmarshalJSON(data []byte) error {
121- x.UnionArray = nil
122- x.AnythingMap = nil
123- object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.UnionArray, false, nil, true, &x.AnythingMap, false, nil, true)
124- if err != nil {
125- return err
126- }
127- if object {
128- }
129- return nil
130-}
131-
132-func (x *X) MarshalJSON() ([]byte, error) {
133- return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.UnionArray != nil, x.UnionArray, false, nil, x.AnythingMap != nil, x.AnythingMap, false, nil, true)
101+func (x *TopLevelElement) MarshalJSON() ([]byte, error) {
102+ return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.A != nil, x.A, false, nil, false, nil, true)
134103 }
135104
136105 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) {
Mschema-haskelldefault / QuickType.hs+48 −92
@@ -3,11 +3,9 @@
33
44 module QuickType
55 ( QuickType (..)
6- , QuickTypeClass (..)
7- , XClass (..)
6+ , A (..)
7+ , PurpleQuickType (..)
88 , QuickTypeElement (..)
9- , XElement (..)
10- , X (..)
119 , decodeTopLevel
1210 ) where
1311
@@ -27,44 +25,30 @@ data QuickType
2725 | UnionArrayInQuickType ([QuickTypeElement])
2826 deriving (Show)
2927
28+data PurpleQuickType
29+ = AnythingMapInPurpleQuickType (HashMap Text Value)
30+ | BoolInPurpleQuickType Bool
31+ | DoubleInPurpleQuickType Float
32+ | IntegerInPurpleQuickType Int
33+ | NullInPurpleQuickType
34+ | StringInPurpleQuickType Text
35+ | UnionArrayInPurpleQuickType ([QuickTypeElement])
36+ deriving (Show)
37+
38+data A = A
39+ { xA :: Maybe PurpleQuickType
40+ } deriving (Show)
41+
3042 data QuickTypeElement
31- = AnythingArrayInQuickTypeElement ([Value])
43+ = AInQuickTypeElement A
44+ | AnythingArrayInQuickTypeElement ([Value])
3245 | BoolInQuickTypeElement Bool
3346 | DoubleInQuickTypeElement Float
3447 | IntegerInQuickTypeElement Int
3548 | NullInQuickTypeElement
36- | QuickTypeClassInQuickTypeElement QuickTypeClass
3749 | StringInQuickTypeElement Text
3850 deriving (Show)
3951
40-data QuickTypeClass = QuickTypeClass
41- { xQuickTypeClass :: Maybe X
42- } deriving (Show)
43-
44-data XClass = XClass
45- { xXClass :: Maybe X
46- } deriving (Show)
47-
48-data XElement
49- = AnythingArrayInXElement ([Value])
50- | BoolInXElement Bool
51- | DoubleInXElement Float
52- | IntegerInXElement Int
53- | NullInXElement
54- | StringInXElement Text
55- | XClassInXElement XClass
56- deriving (Show)
57-
58-data X
59- = AnythingMapInX (HashMap Text Value)
60- | BoolInX Bool
61- | DoubleInX Float
62- | IntegerInX Int
63- | NullInX
64- | StringInX Text
65- | UnionArrayInX ([XElement])
66- deriving (Show)
67-
6852 decodeTopLevel :: ByteString -> Maybe QuickType
6953 decodeTopLevel = decode
7054
@@ -86,76 +70,48 @@ instance FromJSON QuickType where
8670 parseJSON xs@(String _) = (fmap StringInQuickType . parseJSON) xs
8771 parseJSON xs@(Array _) = (fmap UnionArrayInQuickType . parseJSON) xs
8872
73+instance ToJSON PurpleQuickType where
74+ toJSON (AnythingMapInPurpleQuickType x) = toJSON x
75+ toJSON (BoolInPurpleQuickType x) = toJSON x
76+ toJSON (DoubleInPurpleQuickType x) = toJSON x
77+ toJSON (IntegerInPurpleQuickType x) = toJSON x
78+ toJSON NullInPurpleQuickType = Null
79+ toJSON (StringInPurpleQuickType x) = toJSON x
80+ toJSON (UnionArrayInPurpleQuickType x) = toJSON x
81+
82+instance FromJSON PurpleQuickType where
83+ parseJSON xs@(Object _) = (fmap AnythingMapInPurpleQuickType . parseJSON) xs
84+ parseJSON xs@(Bool _) = (fmap BoolInPurpleQuickType . parseJSON) xs
85+ parseJSON xs@(Number _) = (fmap DoubleInPurpleQuickType . parseJSON) xs
86+ parseJSON xs@(Number _) = (fmap IntegerInPurpleQuickType . parseJSON) xs
87+ parseJSON Null = return NullInPurpleQuickType
88+ parseJSON xs@(String _) = (fmap StringInPurpleQuickType . parseJSON) xs
89+ parseJSON xs@(Array _) = (fmap UnionArrayInPurpleQuickType . parseJSON) xs
90+
91+instance ToJSON A where
92+ toJSON (A xA) =
93+ object
94+ [ "x" .= xA
95+ ]
96+
97+instance FromJSON A where
98+ parseJSON (Object v) = A
99+ <$> v .:? "x"
100+
89101 instance ToJSON QuickTypeElement where
102+ toJSON (AInQuickTypeElement x) = toJSON x
90103 toJSON (AnythingArrayInQuickTypeElement x) = toJSON x
91104 toJSON (BoolInQuickTypeElement x) = toJSON x
92105 toJSON (DoubleInQuickTypeElement x) = toJSON x
93106 toJSON (IntegerInQuickTypeElement x) = toJSON x
94107 toJSON NullInQuickTypeElement = Null
95- toJSON (QuickTypeClassInQuickTypeElement x) = toJSON x
96108 toJSON (StringInQuickTypeElement x) = toJSON x
97109
98110 instance FromJSON QuickTypeElement where
111+ parseJSON xs@(Object _) = (fmap AInQuickTypeElement . parseJSON) xs
99112 parseJSON xs@(Array _) = (fmap AnythingArrayInQuickTypeElement . parseJSON) xs
100113 parseJSON xs@(Bool _) = (fmap BoolInQuickTypeElement . parseJSON) xs
101114 parseJSON xs@(Number _) = (fmap DoubleInQuickTypeElement . parseJSON) xs
102115 parseJSON xs@(Number _) = (fmap IntegerInQuickTypeElement . parseJSON) xs
103116 parseJSON Null = return NullInQuickTypeElement
104- parseJSON xs@(Object _) = (fmap QuickTypeClassInQuickTypeElement . parseJSON) xs
105117 parseJSON xs@(String _) = (fmap StringInQuickTypeElement . parseJSON) xs
106-
107-instance ToJSON QuickTypeClass where
108- toJSON (QuickTypeClass xQuickTypeClass) =
109- object
110- [ "x" .= xQuickTypeClass
111- ]
112-
113-instance FromJSON QuickTypeClass where
114- parseJSON (Object v) = QuickTypeClass
115- <$> v .:? "x"
116-
117-instance ToJSON XClass where
118- toJSON (XClass xXClass) =
119- object
120- [ "x" .= xXClass
121- ]
122-
123-instance FromJSON XClass where
124- parseJSON (Object v) = XClass
125- <$> v .:? "x"
126-
127-instance ToJSON XElement where
128- toJSON (AnythingArrayInXElement x) = toJSON x
129- toJSON (BoolInXElement x) = toJSON x
130- toJSON (DoubleInXElement x) = toJSON x
131- toJSON (IntegerInXElement x) = toJSON x
132- toJSON NullInXElement = Null
133- toJSON (StringInXElement x) = toJSON x
134- toJSON (XClassInXElement x) = toJSON x
135-
136-instance FromJSON XElement where
137- parseJSON xs@(Array _) = (fmap AnythingArrayInXElement . parseJSON) xs
138- parseJSON xs@(Bool _) = (fmap BoolInXElement . parseJSON) xs
139- parseJSON xs@(Number _) = (fmap DoubleInXElement . parseJSON) xs
140- parseJSON xs@(Number _) = (fmap IntegerInXElement . parseJSON) xs
141- parseJSON Null = return NullInXElement
142- parseJSON xs@(String _) = (fmap StringInXElement . parseJSON) xs
143- parseJSON xs@(Object _) = (fmap XClassInXElement . parseJSON) xs
144-
145-instance ToJSON X where
146- toJSON (AnythingMapInX x) = toJSON x
147- toJSON (BoolInX x) = toJSON x
148- toJSON (DoubleInX x) = toJSON x
149- toJSON (IntegerInX x) = toJSON x
150- toJSON NullInX = Null
151- toJSON (StringInX x) = toJSON x
152- toJSON (UnionArrayInX x) = toJSON x
153-
154-instance FromJSON X where
155- parseJSON xs@(Object _) = (fmap AnythingMapInX . parseJSON) xs
156- parseJSON xs@(Bool _) = (fmap BoolInX . parseJSON) xs
157- parseJSON xs@(Number _) = (fmap DoubleInX . parseJSON) xs
158- parseJSON xs@(Number _) = (fmap IntegerInX . parseJSON) xs
159- parseJSON Null = return NullInX
160- parseJSON xs@(String _) = (fmap StringInX . parseJSON) xs
161- parseJSON xs@(Array _) = (fmap UnionArrayInX . parseJSON) xs
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / A.java+14 −0
@@ -0,0 +1,14 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+import java.util.List;
5+import java.util.Map;
6+
7+public class A {
8+ private PurpleTopLevel x;
9+
10+ @JsonProperty("x")
11+ public PurpleTopLevel getX() { return x; }
12+ @JsonProperty("x")
13+ public void setX(PurpleTopLevel value) { this.x = value; }
14+}
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / PurpleTopLevel.java+85 −0
@@ -0,0 +1,85 @@
1+package io.quicktype;
2+
3+import java.io.IOException;
4+import java.io.IOException;
5+import com.fasterxml.jackson.core.*;
6+import com.fasterxml.jackson.databind.*;
7+import com.fasterxml.jackson.databind.annotation.*;
8+import com.fasterxml.jackson.core.type.*;
9+import java.util.List;
10+import java.util.Map;
11+
12+@JsonDeserialize(using = PurpleTopLevel.Deserializer.class)
13+@JsonSerialize(using = PurpleTopLevel.Serializer.class)
14+public class PurpleTopLevel {
15+ public Double doubleValue;
16+ public Long integerValue;
17+ public Boolean boolValue;
18+ public List<TopLevelElement> unionArrayValue;
19+ public Map<String, Object> anythingMapValue;
20+ public String stringValue;
21+
22+ static class Deserializer extends JsonDeserializer<PurpleTopLevel> {
23+ @Override
24+ public PurpleTopLevel deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
25+ PurpleTopLevel value = new PurpleTopLevel();
26+ switch (jsonParser.currentToken()) {
27+ case VALUE_NULL:
28+ break;
29+ case VALUE_NUMBER_INT:
30+ value.integerValue = jsonParser.readValueAs(Long.class);
31+ break;
32+ case VALUE_NUMBER_FLOAT:
33+ value.doubleValue = jsonParser.readValueAs(Double.class);
34+ break;
35+ case VALUE_TRUE:
36+ case VALUE_FALSE:
37+ value.boolValue = jsonParser.readValueAs(Boolean.class);
38+ break;
39+ case VALUE_STRING:
40+ String string = jsonParser.readValueAs(String.class);
41+ value.stringValue = string;
42+ break;
43+ case START_ARRAY:
44+ value.unionArrayValue = jsonParser.readValueAs(new TypeReference<List<TopLevelElement>>() {});
45+ break;
46+ case START_OBJECT:
47+ value.anythingMapValue = jsonParser.readValueAs(Map.class);
48+ break;
49+ default: throw new IOException("Cannot deserialize PurpleTopLevel");
50+ }
51+ return value;
52+ }
53+ }
54+
55+ static class Serializer extends JsonSerializer<PurpleTopLevel> {
56+ @Override
57+ public void serialize(PurpleTopLevel obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
58+ if (obj.doubleValue != null) {
59+ jsonGenerator.writeObject(obj.doubleValue);
60+ return;
61+ }
62+ if (obj.integerValue != null) {
63+ jsonGenerator.writeObject(obj.integerValue);
64+ return;
65+ }
66+ if (obj.boolValue != null) {
67+ jsonGenerator.writeObject(obj.boolValue);
68+ return;
69+ }
70+ if (obj.unionArrayValue != null) {
71+ jsonGenerator.writeObject(obj.unionArrayValue);
72+ return;
73+ }
74+ if (obj.anythingMapValue != null) {
75+ jsonGenerator.writeObject(obj.anythingMapValue);
76+ return;
77+ }
78+ if (obj.stringValue != null) {
79+ jsonGenerator.writeObject(obj.stringValue);
80+ return;
81+ }
82+ jsonGenerator.writeNull();
83+ }
84+ }
85+}
Dschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevelClass.java+0 −14
@@ -1,14 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-import java.util.List;
5-import java.util.Map;
6-
7-public class TopLevelClass {
8- private X x;
9-
10- @JsonProperty("x")
11- public X getX() { return x; }
12- @JsonProperty("x")
13- public void setX(X value) { this.x = value; }
14-}
Mschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevelElement.java+4 −4
@@ -15,7 +15,7 @@ public class TopLevelElement {
1515 public Long integerValue;
1616 public Boolean boolValue;
1717 public List<Object> anythingArrayValue;
18- public TopLevelClass topLevelClassValue;
18+ public A aValue;
1919 public String stringValue;
2020
2121 static class Deserializer extends JsonDeserializer<TopLevelElement> {
@@ -43,7 +43,7 @@ public class TopLevelElement {
4343 value.anythingArrayValue = jsonParser.readValueAs(new TypeReference<List<Object>>() {});
4444 break;
4545 case START_OBJECT:
46- value.topLevelClassValue = jsonParser.readValueAs(TopLevelClass.class);
46+ value.aValue = jsonParser.readValueAs(A.class);
4747 break;
4848 default: throw new IOException("Cannot deserialize TopLevelElement");
4949 }
@@ -70,8 +70,8 @@ public class TopLevelElement {
7070 jsonGenerator.writeObject(obj.anythingArrayValue);
7171 return;
7272 }
73- if (obj.topLevelClassValue != null) {
74- jsonGenerator.writeObject(obj.topLevelClassValue);
73+ if (obj.aValue != null) {
74+ jsonGenerator.writeObject(obj.aValue);
7575 return;
7676 }
7777 if (obj.stringValue != null) {
Dschema-java-datetime-legacydefault / src / main / java / io / quicktype / X.java+0 −85
@@ -1,85 +0,0 @@
1-package io.quicktype;
2-
3-import java.io.IOException;
4-import java.io.IOException;
5-import com.fasterxml.jackson.core.*;
6-import com.fasterxml.jackson.databind.*;
7-import com.fasterxml.jackson.databind.annotation.*;
8-import com.fasterxml.jackson.core.type.*;
9-import java.util.List;
10-import java.util.Map;
11-
12-@JsonDeserialize(using = X.Deserializer.class)
13-@JsonSerialize(using = X.Serializer.class)
14-public class X {
15- public Double doubleValue;
16- public Long integerValue;
17- public Boolean boolValue;
18- public List<XElement> unionArrayValue;
19- public Map<String, Object> anythingMapValue;
20- public String stringValue;
21-
22- static class Deserializer extends JsonDeserializer<X> {
23- @Override
24- public X deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
25- X value = new X();
26- switch (jsonParser.currentToken()) {
27- case VALUE_NULL:
28- break;
29- case VALUE_NUMBER_INT:
30- value.integerValue = jsonParser.readValueAs(Long.class);
31- break;
32- case VALUE_NUMBER_FLOAT:
33- value.doubleValue = jsonParser.readValueAs(Double.class);
34- break;
35- case VALUE_TRUE:
36- case VALUE_FALSE:
37- value.boolValue = jsonParser.readValueAs(Boolean.class);
38- break;
39- case VALUE_STRING:
40- String string = jsonParser.readValueAs(String.class);
41- value.stringValue = string;
42- break;
43- case START_ARRAY:
44- value.unionArrayValue = jsonParser.readValueAs(new TypeReference<List<XElement>>() {});
45- break;
46- case START_OBJECT:
47- value.anythingMapValue = jsonParser.readValueAs(Map.class);
48- break;
49- default: throw new IOException("Cannot deserialize X");
50- }
51- return value;
52- }
53- }
54-
55- static class Serializer extends JsonSerializer<X> {
56- @Override
57- public void serialize(X obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
58- if (obj.doubleValue != null) {
59- jsonGenerator.writeObject(obj.doubleValue);
60- return;
61- }
62- if (obj.integerValue != null) {
63- jsonGenerator.writeObject(obj.integerValue);
64- return;
65- }
66- if (obj.boolValue != null) {
67- jsonGenerator.writeObject(obj.boolValue);
68- return;
69- }
70- if (obj.unionArrayValue != null) {
71- jsonGenerator.writeObject(obj.unionArrayValue);
72- return;
73- }
74- if (obj.anythingMapValue != null) {
75- jsonGenerator.writeObject(obj.anythingMapValue);
76- return;
77- }
78- if (obj.stringValue != null) {
79- jsonGenerator.writeObject(obj.stringValue);
80- return;
81- }
82- jsonGenerator.writeNull();
83- }
84- }
85-}
Dschema-java-datetime-legacydefault / src / main / java / io / quicktype / XClass.java+0 −14
@@ -1,14 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-import java.util.List;
5-import java.util.Map;
6-
7-public class XClass {
8- private X x;
9-
10- @JsonProperty("x")
11- public X getX() { return x; }
12- @JsonProperty("x")
13- public void setX(X value) { this.x = value; }
14-}
Dschema-java-datetime-legacydefault / src / main / java / io / quicktype / XElement.java+0 −84
@@ -1,84 +0,0 @@
1-package io.quicktype;
2-
3-import java.io.IOException;
4-import java.io.IOException;
5-import com.fasterxml.jackson.core.*;
6-import com.fasterxml.jackson.databind.*;
7-import com.fasterxml.jackson.databind.annotation.*;
8-import com.fasterxml.jackson.core.type.*;
9-import java.util.List;
10-
11-@JsonDeserialize(using = XElement.Deserializer.class)
12-@JsonSerialize(using = XElement.Serializer.class)
13-public class XElement {
14- public Double doubleValue;
15- public Long integerValue;
16- public Boolean boolValue;
17- public List<Object> anythingArrayValue;
18- public XClass xClassValue;
19- public String stringValue;
20-
21- static class Deserializer extends JsonDeserializer<XElement> {
22- @Override
23- public XElement deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
24- XElement value = new XElement();
25- switch (jsonParser.currentToken()) {
26- case VALUE_NULL:
27- break;
28- case VALUE_NUMBER_INT:
29- value.integerValue = jsonParser.readValueAs(Long.class);
30- break;
31- case VALUE_NUMBER_FLOAT:
32- value.doubleValue = jsonParser.readValueAs(Double.class);
33- break;
34- case VALUE_TRUE:
35- case VALUE_FALSE:
36- value.boolValue = jsonParser.readValueAs(Boolean.class);
37- break;
38- case VALUE_STRING:
39- String string = jsonParser.readValueAs(String.class);
40- value.stringValue = string;
41- break;
42- case START_ARRAY:
43- value.anythingArrayValue = jsonParser.readValueAs(new TypeReference<List<Object>>() {});
44- break;
45- case START_OBJECT:
46- value.xClassValue = jsonParser.readValueAs(XClass.class);
47- break;
48- default: throw new IOException("Cannot deserialize XElement");
49- }
50- return value;
51- }
52- }
53-
54- static class Serializer extends JsonSerializer<XElement> {
55- @Override
56- public void serialize(XElement obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
57- if (obj.doubleValue != null) {
58- jsonGenerator.writeObject(obj.doubleValue);
59- return;
60- }
61- if (obj.integerValue != null) {
62- jsonGenerator.writeObject(obj.integerValue);
63- return;
64- }
65- if (obj.boolValue != null) {
66- jsonGenerator.writeObject(obj.boolValue);
67- return;
68- }
69- if (obj.anythingArrayValue != null) {
70- jsonGenerator.writeObject(obj.anythingArrayValue);
71- return;
72- }
73- if (obj.xClassValue != null) {
74- jsonGenerator.writeObject(obj.xClassValue);
75- return;
76- }
77- if (obj.stringValue != null) {
78- jsonGenerator.writeObject(obj.stringValue);
79- return;
80- }
81- jsonGenerator.writeNull();
82- }
83- }
84-}
Aschema-java-lombokdefault / src / main / java / io / quicktype / A.java+14 −0
@@ -0,0 +1,14 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+import java.util.List;
5+import java.util.Map;
6+
7+public class A {
8+ private PurpleTopLevel x;
9+
10+ @JsonProperty("x")
11+ public PurpleTopLevel getX() { return x; }
12+ @JsonProperty("x")
13+ public void setX(PurpleTopLevel value) { this.x = value; }
14+}
Aschema-java-lombokdefault / src / main / java / io / quicktype / PurpleTopLevel.java+85 −0
@@ -0,0 +1,85 @@
1+package io.quicktype;
2+
3+import java.io.IOException;
4+import java.io.IOException;
5+import com.fasterxml.jackson.core.*;
6+import com.fasterxml.jackson.databind.*;
7+import com.fasterxml.jackson.databind.annotation.*;
8+import com.fasterxml.jackson.core.type.*;
9+import java.util.List;
10+import java.util.Map;
11+
12+@JsonDeserialize(using = PurpleTopLevel.Deserializer.class)
13+@JsonSerialize(using = PurpleTopLevel.Serializer.class)
14+public class PurpleTopLevel {
15+ public Double doubleValue;
16+ public Long integerValue;
17+ public Boolean boolValue;
18+ public List<TopLevelElement> unionArrayValue;
19+ public Map<String, Object> anythingMapValue;
20+ public String stringValue;
21+
22+ static class Deserializer extends JsonDeserializer<PurpleTopLevel> {
23+ @Override
24+ public PurpleTopLevel deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
25+ PurpleTopLevel value = new PurpleTopLevel();
26+ switch (jsonParser.currentToken()) {
27+ case VALUE_NULL:
28+ break;
29+ case VALUE_NUMBER_INT:
30+ value.integerValue = jsonParser.readValueAs(Long.class);
31+ break;
32+ case VALUE_NUMBER_FLOAT:
33+ value.doubleValue = jsonParser.readValueAs(Double.class);
34+ break;
35+ case VALUE_TRUE:
36+ case VALUE_FALSE:
37+ value.boolValue = jsonParser.readValueAs(Boolean.class);
38+ break;
39+ case VALUE_STRING:
40+ String string = jsonParser.readValueAs(String.class);
41+ value.stringValue = string;
42+ break;
43+ case START_ARRAY:
44+ value.unionArrayValue = jsonParser.readValueAs(new TypeReference<List<TopLevelElement>>() {});
45+ break;
46+ case START_OBJECT:
47+ value.anythingMapValue = jsonParser.readValueAs(Map.class);
48+ break;
49+ default: throw new IOException("Cannot deserialize PurpleTopLevel");
50+ }
51+ return value;
52+ }
53+ }
54+
55+ static class Serializer extends JsonSerializer<PurpleTopLevel> {
56+ @Override
57+ public void serialize(PurpleTopLevel obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
58+ if (obj.doubleValue != null) {
59+ jsonGenerator.writeObject(obj.doubleValue);
60+ return;
61+ }
62+ if (obj.integerValue != null) {
63+ jsonGenerator.writeObject(obj.integerValue);
64+ return;
65+ }
66+ if (obj.boolValue != null) {
67+ jsonGenerator.writeObject(obj.boolValue);
68+ return;
69+ }
70+ if (obj.unionArrayValue != null) {
71+ jsonGenerator.writeObject(obj.unionArrayValue);
72+ return;
73+ }
74+ if (obj.anythingMapValue != null) {
75+ jsonGenerator.writeObject(obj.anythingMapValue);
76+ return;
77+ }
78+ if (obj.stringValue != null) {
79+ jsonGenerator.writeObject(obj.stringValue);
80+ return;
81+ }
82+ jsonGenerator.writeNull();
83+ }
84+ }
85+}
Dschema-java-lombokdefault / src / main / java / io / quicktype / TopLevelClass.java+0 −14
@@ -1,14 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-import java.util.List;
5-import java.util.Map;
6-
7-public class TopLevelClass {
8- private X x;
9-
10- @JsonProperty("x")
11- public X getX() { return x; }
12- @JsonProperty("x")
13- public void setX(X value) { this.x = value; }
14-}
Mschema-java-lombokdefault / src / main / java / io / quicktype / TopLevelElement.java+4 −4
@@ -15,7 +15,7 @@ public class TopLevelElement {
1515 public Long integerValue;
1616 public Boolean boolValue;
1717 public List<Object> anythingArrayValue;
18- public TopLevelClass topLevelClassValue;
18+ public A aValue;
1919 public String stringValue;
2020
2121 static class Deserializer extends JsonDeserializer<TopLevelElement> {
@@ -43,7 +43,7 @@ public class TopLevelElement {
4343 value.anythingArrayValue = jsonParser.readValueAs(new TypeReference<List<Object>>() {});
4444 break;
4545 case START_OBJECT:
46- value.topLevelClassValue = jsonParser.readValueAs(TopLevelClass.class);
46+ value.aValue = jsonParser.readValueAs(A.class);
4747 break;
4848 default: throw new IOException("Cannot deserialize TopLevelElement");
4949 }
@@ -70,8 +70,8 @@ public class TopLevelElement {
7070 jsonGenerator.writeObject(obj.anythingArrayValue);
7171 return;
7272 }
73- if (obj.topLevelClassValue != null) {
74- jsonGenerator.writeObject(obj.topLevelClassValue);
73+ if (obj.aValue != null) {
74+ jsonGenerator.writeObject(obj.aValue);
7575 return;
7676 }
7777 if (obj.stringValue != null) {
Dschema-java-lombokdefault / src / main / java / io / quicktype / X.java+0 −85
@@ -1,85 +0,0 @@
1-package io.quicktype;
2-
3-import java.io.IOException;
4-import java.io.IOException;
5-import com.fasterxml.jackson.core.*;
6-import com.fasterxml.jackson.databind.*;
7-import com.fasterxml.jackson.databind.annotation.*;
8-import com.fasterxml.jackson.core.type.*;
9-import java.util.List;
10-import java.util.Map;
11-
12-@JsonDeserialize(using = X.Deserializer.class)
13-@JsonSerialize(using = X.Serializer.class)
14-public class X {
15- public Double doubleValue;
16- public Long integerValue;
17- public Boolean boolValue;
18- public List<XElement> unionArrayValue;
19- public Map<String, Object> anythingMapValue;
20- public String stringValue;
21-
22- static class Deserializer extends JsonDeserializer<X> {
23- @Override
24- public X deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
25- X value = new X();
26- switch (jsonParser.currentToken()) {
27- case VALUE_NULL:
28- break;
29- case VALUE_NUMBER_INT:
30- value.integerValue = jsonParser.readValueAs(Long.class);
31- break;
32- case VALUE_NUMBER_FLOAT:
33- value.doubleValue = jsonParser.readValueAs(Double.class);
34- break;
35- case VALUE_TRUE:
36- case VALUE_FALSE:
37- value.boolValue = jsonParser.readValueAs(Boolean.class);
38- break;
39- case VALUE_STRING:
40- String string = jsonParser.readValueAs(String.class);
41- value.stringValue = string;
42- break;
43- case START_ARRAY:
44- value.unionArrayValue = jsonParser.readValueAs(new TypeReference<List<XElement>>() {});
45- break;
46- case START_OBJECT:
47- value.anythingMapValue = jsonParser.readValueAs(Map.class);
48- break;
49- default: throw new IOException("Cannot deserialize X");
50- }
51- return value;
52- }
53- }
54-
55- static class Serializer extends JsonSerializer<X> {
56- @Override
57- public void serialize(X obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
58- if (obj.doubleValue != null) {
59- jsonGenerator.writeObject(obj.doubleValue);
60- return;
61- }
62- if (obj.integerValue != null) {
63- jsonGenerator.writeObject(obj.integerValue);
64- return;
65- }
66- if (obj.boolValue != null) {
67- jsonGenerator.writeObject(obj.boolValue);
68- return;
69- }
70- if (obj.unionArrayValue != null) {
71- jsonGenerator.writeObject(obj.unionArrayValue);
72- return;
73- }
74- if (obj.anythingMapValue != null) {
75- jsonGenerator.writeObject(obj.anythingMapValue);
76- return;
77- }
78- if (obj.stringValue != null) {
79- jsonGenerator.writeObject(obj.stringValue);
80- return;
81- }
82- jsonGenerator.writeNull();
83- }
84- }
85-}
Dschema-java-lombokdefault / src / main / java / io / quicktype / XClass.java+0 −14
@@ -1,14 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-import java.util.List;
5-import java.util.Map;
6-
7-public class XClass {
8- private X x;
9-
10- @JsonProperty("x")
11- public X getX() { return x; }
12- @JsonProperty("x")
13- public void setX(X value) { this.x = value; }
14-}
Dschema-java-lombokdefault / src / main / java / io / quicktype / XElement.java+0 −84
@@ -1,84 +0,0 @@
1-package io.quicktype;
2-
3-import java.io.IOException;
4-import java.io.IOException;
5-import com.fasterxml.jackson.core.*;
6-import com.fasterxml.jackson.databind.*;
7-import com.fasterxml.jackson.databind.annotation.*;
8-import com.fasterxml.jackson.core.type.*;
9-import java.util.List;
10-
11-@JsonDeserialize(using = XElement.Deserializer.class)
12-@JsonSerialize(using = XElement.Serializer.class)
13-public class XElement {
14- public Double doubleValue;
15- public Long integerValue;
16- public Boolean boolValue;
17- public List<Object> anythingArrayValue;
18- public XClass xClassValue;
19- public String stringValue;
20-
21- static class Deserializer extends JsonDeserializer<XElement> {
22- @Override
23- public XElement deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
24- XElement value = new XElement();
25- switch (jsonParser.currentToken()) {
26- case VALUE_NULL:
27- break;
28- case VALUE_NUMBER_INT:
29- value.integerValue = jsonParser.readValueAs(Long.class);
30- break;
31- case VALUE_NUMBER_FLOAT:
32- value.doubleValue = jsonParser.readValueAs(Double.class);
33- break;
34- case VALUE_TRUE:
35- case VALUE_FALSE:
36- value.boolValue = jsonParser.readValueAs(Boolean.class);
37- break;
38- case VALUE_STRING:
39- String string = jsonParser.readValueAs(String.class);
40- value.stringValue = string;
41- break;
42- case START_ARRAY:
43- value.anythingArrayValue = jsonParser.readValueAs(new TypeReference<List<Object>>() {});
44- break;
45- case START_OBJECT:
46- value.xClassValue = jsonParser.readValueAs(XClass.class);
47- break;
48- default: throw new IOException("Cannot deserialize XElement");
49- }
50- return value;
51- }
52- }
53-
54- static class Serializer extends JsonSerializer<XElement> {
55- @Override
56- public void serialize(XElement obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
57- if (obj.doubleValue != null) {
58- jsonGenerator.writeObject(obj.doubleValue);
59- return;
60- }
61- if (obj.integerValue != null) {
62- jsonGenerator.writeObject(obj.integerValue);
63- return;
64- }
65- if (obj.boolValue != null) {
66- jsonGenerator.writeObject(obj.boolValue);
67- return;
68- }
69- if (obj.anythingArrayValue != null) {
70- jsonGenerator.writeObject(obj.anythingArrayValue);
71- return;
72- }
73- if (obj.xClassValue != null) {
74- jsonGenerator.writeObject(obj.xClassValue);
75- return;
76- }
77- if (obj.stringValue != null) {
78- jsonGenerator.writeObject(obj.stringValue);
79- return;
80- }
81- jsonGenerator.writeNull();
82- }
83- }
84-}
Aschema-javadefault / src / main / java / io / quicktype / A.java+14 −0
@@ -0,0 +1,14 @@
1+package io.quicktype;
2+
3+import com.fasterxml.jackson.annotation.*;
4+import java.util.List;
5+import java.util.Map;
6+
7+public class A {
8+ private PurpleTopLevel x;
9+
10+ @JsonProperty("x")
11+ public PurpleTopLevel getX() { return x; }
12+ @JsonProperty("x")
13+ public void setX(PurpleTopLevel value) { this.x = value; }
14+}
Aschema-javadefault / src / main / java / io / quicktype / PurpleTopLevel.java+85 −0
@@ -0,0 +1,85 @@
1+package io.quicktype;
2+
3+import java.io.IOException;
4+import java.io.IOException;
5+import com.fasterxml.jackson.core.*;
6+import com.fasterxml.jackson.databind.*;
7+import com.fasterxml.jackson.databind.annotation.*;
8+import com.fasterxml.jackson.core.type.*;
9+import java.util.List;
10+import java.util.Map;
11+
12+@JsonDeserialize(using = PurpleTopLevel.Deserializer.class)
13+@JsonSerialize(using = PurpleTopLevel.Serializer.class)
14+public class PurpleTopLevel {
15+ public Double doubleValue;
16+ public Long integerValue;
17+ public Boolean boolValue;
18+ public List<TopLevelElement> unionArrayValue;
19+ public Map<String, Object> anythingMapValue;
20+ public String stringValue;
21+
22+ static class Deserializer extends JsonDeserializer<PurpleTopLevel> {
23+ @Override
24+ public PurpleTopLevel deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
25+ PurpleTopLevel value = new PurpleTopLevel();
26+ switch (jsonParser.currentToken()) {
27+ case VALUE_NULL:
28+ break;
29+ case VALUE_NUMBER_INT:
30+ value.integerValue = jsonParser.readValueAs(Long.class);
31+ break;
32+ case VALUE_NUMBER_FLOAT:
33+ value.doubleValue = jsonParser.readValueAs(Double.class);
34+ break;
35+ case VALUE_TRUE:
36+ case VALUE_FALSE:
37+ value.boolValue = jsonParser.readValueAs(Boolean.class);
38+ break;
39+ case VALUE_STRING:
40+ String string = jsonParser.readValueAs(String.class);
41+ value.stringValue = string;
42+ break;
43+ case START_ARRAY:
44+ value.unionArrayValue = jsonParser.readValueAs(new TypeReference<List<TopLevelElement>>() {});
45+ break;
46+ case START_OBJECT:
47+ value.anythingMapValue = jsonParser.readValueAs(Map.class);
48+ break;
49+ default: throw new IOException("Cannot deserialize PurpleTopLevel");
50+ }
51+ return value;
52+ }
53+ }
54+
55+ static class Serializer extends JsonSerializer<PurpleTopLevel> {
56+ @Override
57+ public void serialize(PurpleTopLevel obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
58+ if (obj.doubleValue != null) {
59+ jsonGenerator.writeObject(obj.doubleValue);
60+ return;
61+ }
62+ if (obj.integerValue != null) {
63+ jsonGenerator.writeObject(obj.integerValue);
64+ return;
65+ }
66+ if (obj.boolValue != null) {
67+ jsonGenerator.writeObject(obj.boolValue);
68+ return;
69+ }
70+ if (obj.unionArrayValue != null) {
71+ jsonGenerator.writeObject(obj.unionArrayValue);
72+ return;
73+ }
74+ if (obj.anythingMapValue != null) {
75+ jsonGenerator.writeObject(obj.anythingMapValue);
76+ return;
77+ }
78+ if (obj.stringValue != null) {
79+ jsonGenerator.writeObject(obj.stringValue);
80+ return;
81+ }
82+ jsonGenerator.writeNull();
83+ }
84+ }
85+}
Dschema-javadefault / src / main / java / io / quicktype / TopLevelClass.java+0 −14
@@ -1,14 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-import java.util.List;
5-import java.util.Map;
6-
7-public class TopLevelClass {
8- private X x;
9-
10- @JsonProperty("x")
11- public X getX() { return x; }
12- @JsonProperty("x")
13- public void setX(X value) { this.x = value; }
14-}
Mschema-javadefault / src / main / java / io / quicktype / TopLevelElement.java+4 −4
@@ -15,7 +15,7 @@ public class TopLevelElement {
1515 public Long integerValue;
1616 public Boolean boolValue;
1717 public List<Object> anythingArrayValue;
18- public TopLevelClass topLevelClassValue;
18+ public A aValue;
1919 public String stringValue;
2020
2121 static class Deserializer extends JsonDeserializer<TopLevelElement> {
@@ -43,7 +43,7 @@ public class TopLevelElement {
4343 value.anythingArrayValue = jsonParser.readValueAs(new TypeReference<List<Object>>() {});
4444 break;
4545 case START_OBJECT:
46- value.topLevelClassValue = jsonParser.readValueAs(TopLevelClass.class);
46+ value.aValue = jsonParser.readValueAs(A.class);
4747 break;
4848 default: throw new IOException("Cannot deserialize TopLevelElement");
4949 }
@@ -70,8 +70,8 @@ public class TopLevelElement {
7070 jsonGenerator.writeObject(obj.anythingArrayValue);
7171 return;
7272 }
73- if (obj.topLevelClassValue != null) {
74- jsonGenerator.writeObject(obj.topLevelClassValue);
73+ if (obj.aValue != null) {
74+ jsonGenerator.writeObject(obj.aValue);
7575 return;
7676 }
7777 if (obj.stringValue != null) {
Dschema-javadefault / src / main / java / io / quicktype / X.java+0 −85
@@ -1,85 +0,0 @@
1-package io.quicktype;
2-
3-import java.io.IOException;
4-import java.io.IOException;
5-import com.fasterxml.jackson.core.*;
6-import com.fasterxml.jackson.databind.*;
7-import com.fasterxml.jackson.databind.annotation.*;
8-import com.fasterxml.jackson.core.type.*;
9-import java.util.List;
10-import java.util.Map;
11-
12-@JsonDeserialize(using = X.Deserializer.class)
13-@JsonSerialize(using = X.Serializer.class)
14-public class X {
15- public Double doubleValue;
16- public Long integerValue;
17- public Boolean boolValue;
18- public List<XElement> unionArrayValue;
19- public Map<String, Object> anythingMapValue;
20- public String stringValue;
21-
22- static class Deserializer extends JsonDeserializer<X> {
23- @Override
24- public X deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
25- X value = new X();
26- switch (jsonParser.currentToken()) {
27- case VALUE_NULL:
28- break;
29- case VALUE_NUMBER_INT:
30- value.integerValue = jsonParser.readValueAs(Long.class);
31- break;
32- case VALUE_NUMBER_FLOAT:
33- value.doubleValue = jsonParser.readValueAs(Double.class);
34- break;
35- case VALUE_TRUE:
36- case VALUE_FALSE:
37- value.boolValue = jsonParser.readValueAs(Boolean.class);
38- break;
39- case VALUE_STRING:
40- String string = jsonParser.readValueAs(String.class);
41- value.stringValue = string;
42- break;
43- case START_ARRAY:
44- value.unionArrayValue = jsonParser.readValueAs(new TypeReference<List<XElement>>() {});
45- break;
46- case START_OBJECT:
47- value.anythingMapValue = jsonParser.readValueAs(Map.class);
48- break;
49- default: throw new IOException("Cannot deserialize X");
50- }
51- return value;
52- }
53- }
54-
55- static class Serializer extends JsonSerializer<X> {
56- @Override
57- public void serialize(X obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
58- if (obj.doubleValue != null) {
59- jsonGenerator.writeObject(obj.doubleValue);
60- return;
61- }
62- if (obj.integerValue != null) {
63- jsonGenerator.writeObject(obj.integerValue);
64- return;
65- }
66- if (obj.boolValue != null) {
67- jsonGenerator.writeObject(obj.boolValue);
68- return;
69- }
70- if (obj.unionArrayValue != null) {
71- jsonGenerator.writeObject(obj.unionArrayValue);
72- return;
73- }
74- if (obj.anythingMapValue != null) {
75- jsonGenerator.writeObject(obj.anythingMapValue);
76- return;
77- }
78- if (obj.stringValue != null) {
79- jsonGenerator.writeObject(obj.stringValue);
80- return;
81- }
82- jsonGenerator.writeNull();
83- }
84- }
85-}
Dschema-javadefault / src / main / java / io / quicktype / XClass.java+0 −14
@@ -1,14 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-import java.util.List;
5-import java.util.Map;
6-
7-public class XClass {
8- private X x;
9-
10- @JsonProperty("x")
11- public X getX() { return x; }
12- @JsonProperty("x")
13- public void setX(X value) { this.x = value; }
14-}
Dschema-javadefault / src / main / java / io / quicktype / XElement.java+0 −84
@@ -1,84 +0,0 @@
1-package io.quicktype;
2-
3-import java.io.IOException;
4-import java.io.IOException;
5-import com.fasterxml.jackson.core.*;
6-import com.fasterxml.jackson.databind.*;
7-import com.fasterxml.jackson.databind.annotation.*;
8-import com.fasterxml.jackson.core.type.*;
9-import java.util.List;
10-
11-@JsonDeserialize(using = XElement.Deserializer.class)
12-@JsonSerialize(using = XElement.Serializer.class)
13-public class XElement {
14- public Double doubleValue;
15- public Long integerValue;
16- public Boolean boolValue;
17- public List<Object> anythingArrayValue;
18- public XClass xClassValue;
19- public String stringValue;
20-
21- static class Deserializer extends JsonDeserializer<XElement> {
22- @Override
23- public XElement deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
24- XElement value = new XElement();
25- switch (jsonParser.currentToken()) {
26- case VALUE_NULL:
27- break;
28- case VALUE_NUMBER_INT:
29- value.integerValue = jsonParser.readValueAs(Long.class);
30- break;
31- case VALUE_NUMBER_FLOAT:
32- value.doubleValue = jsonParser.readValueAs(Double.class);
33- break;
34- case VALUE_TRUE:
35- case VALUE_FALSE:
36- value.boolValue = jsonParser.readValueAs(Boolean.class);
37- break;
38- case VALUE_STRING:
39- String string = jsonParser.readValueAs(String.class);
40- value.stringValue = string;
41- break;
42- case START_ARRAY:
43- value.anythingArrayValue = jsonParser.readValueAs(new TypeReference<List<Object>>() {});
44- break;
45- case START_OBJECT:
46- value.xClassValue = jsonParser.readValueAs(XClass.class);
47- break;
48- default: throw new IOException("Cannot deserialize XElement");
49- }
50- return value;
51- }
52- }
53-
54- static class Serializer extends JsonSerializer<XElement> {
55- @Override
56- public void serialize(XElement obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
57- if (obj.doubleValue != null) {
58- jsonGenerator.writeObject(obj.doubleValue);
59- return;
60- }
61- if (obj.integerValue != null) {
62- jsonGenerator.writeObject(obj.integerValue);
63- return;
64- }
65- if (obj.boolValue != null) {
66- jsonGenerator.writeObject(obj.boolValue);
67- return;
68- }
69- if (obj.anythingArrayValue != null) {
70- jsonGenerator.writeObject(obj.anythingArrayValue);
71- return;
72- }
73- if (obj.xClassValue != null) {
74- jsonGenerator.writeObject(obj.xClassValue);
75- return;
76- }
77- if (obj.stringValue != null) {
78- jsonGenerator.writeObject(obj.stringValue);
79- return;
80- }
81- jsonGenerator.writeNull();
82- }
83- }
84-}
Mschema-javascriptdefault / TopLevel.js+4 −7
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), u(a(u(a("any"), true, 3.14, null, r("TopLevelObject"), "")), true, 3.14, 0, m("any"), null, ""));
13+ return cast(JSON.parse(json), u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, 0, m("any"), null, ""));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, u(a(u(a("any"), true, 3.14, null, r("TopLevelObject"), "")), true, 3.14, 0, m("any"), null, "")), null, 2);
17+ return JSON.stringify(uncast(value, u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, 0, m("any"), null, "")), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,11 +171,8 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelObject": o([
175- { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("XObject"), "")), true, 3.14, m("any"), null, "")) },
176- ], "any"),
177- "XObject": o([
178- { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("XObject"), "")), true, 3.14, m("any"), null, "")) },
174+ "A": o([
175+ { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, m("any"), null, "")) },
179176 ], "any"),
180177 };
Mschema-pikedefault / TopLevel.pmod+8 −34
@@ -18,34 +18,14 @@ TopLevel TopLevel_from_JSON(mixed json) {
1818 return json;
1919 }
2020
21-typedef array(mixed)|bool|float|string|TopLevelClass TopLevelElement;
21+typedef mapping(string:mixed)|bool|float|string|array(TopLevelElement) PurpleTopLevel;
2222
23-TopLevelElement TopLevelElement_from_JSON(mixed json) {
23+PurpleTopLevel PurpleTopLevel_from_JSON(mixed json) {
2424 return json;
2525 }
2626
27-class TopLevelClass {
28- X x; // json: "x"
29-
30- string encode_json() {
31- mapping(string:mixed) json = ([
32- "x" : x,
33- ]);
34-
35- return Standards.JSON.encode(json);
36- }
37-}
38-
39-TopLevelClass TopLevelClass_from_JSON(mixed json) {
40- TopLevelClass retval = TopLevelClass();
41-
42- retval.x = json["x"];
43-
44- return retval;
45-}
46-
47-class XClass {
48- X x; // json: "x"
27+class A {
28+ PurpleTopLevel x; // json: "x"
4929
5030 string encode_json() {
5131 mapping(string:mixed) json = ([
@@ -56,22 +36,16 @@ class XClass {
5636 }
5737 }
5838
59-XClass XClass_from_JSON(mixed json) {
60- XClass retval = XClass();
39+A A_from_JSON(mixed json) {
40+ A retval = A();
6141
6242 retval.x = json["x"];
6343
6444 return retval;
6545 }
6646
67-typedef array(mixed)|bool|float|string|XClass XElement;
47+typedef A|array(mixed)|bool|float|string TopLevelElement;
6848
69-XElement XElement_from_JSON(mixed json) {
70- return json;
71-}
72-
73-typedef mapping(string:mixed)|bool|float|string|array(XElement) X;
74-
75-X X_from_JSON(mixed json) {
49+TopLevelElement TopLevelElement_from_JSON(mixed json) {
7650 return json;
7751 }
Mschema-pythondefault / quicktype.py+10 −27
@@ -60,42 +60,25 @@ def to_class(c: Type[T], x: Any) -> dict:
6060
6161
6262 @dataclass
63-class XClass:
64- x: 'float | int | bool | list[float | int | bool | list[Any] | XClass | str | None] | dict[str, Any] | str | None' = None
63+class A:
64+ x: 'float | int | bool | list[float | int | bool | list[Any] | A | str | None] | dict[str, Any] | str | None' = None
6565
6666 @staticmethod
67- def from_dict(obj: Any) -> 'XClass':
67+ def from_dict(obj: Any) -> 'A':
6868 assert isinstance(obj, dict)
69- x = from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: x, x), XClass.from_dict, from_str], x), x), lambda x: from_dict(lambda x: x, x), from_str], obj.get("x"))
70- return XClass(x)
69+ x = from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: x, x), A.from_dict, from_str], x), x), lambda x: from_dict(lambda x: x, x), from_str], obj.get("x"))
70+ return A(x)
7171
7272 def to_dict(self) -> dict:
7373 result: dict = {}
7474 if self.x is not None:
75- result["x"] = from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: x, x), lambda x: to_class(XClass, x), from_str], x), x), lambda x: from_dict(lambda x: x, x), from_str], self.x)
75+ result["x"] = from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: x, x), lambda x: to_class(A, x), from_str], x), x), lambda x: from_dict(lambda x: x, x), from_str], self.x)
7676 return result
7777
7878
79-@dataclass
80-class TopLevelClass:
81- x: float | int | bool | list[float | int | bool | list[Any] | XClass | str | None] | dict[str, Any] | str | None = None
82-
83- @staticmethod
84- def from_dict(obj: Any) -> 'TopLevelClass':
85- assert isinstance(obj, dict)
86- x = from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: x, x), XClass.from_dict, from_str], x), x), lambda x: from_dict(lambda x: x, x), from_str], obj.get("x"))
87- return TopLevelClass(x)
88-
89- def to_dict(self) -> dict:
90- result: dict = {}
91- if self.x is not None:
92- result["x"] = from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: x, x), lambda x: to_class(XClass, x), from_str], x), x), lambda x: from_dict(lambda x: x, x), from_str], self.x)
93- return result
94-
95-
96-def top_level_from_dict(s: Any) -> float | int | bool | str | list[float | int | bool | list[Any] | TopLevelClass | str | None] | dict[str, Any] | None:
97- return from_union([from_none, from_int, from_float, from_bool, from_str, lambda x: from_list(lambda x: from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: x, x), TopLevelClass.from_dict, from_str], x), x), lambda x: from_dict(lambda x: x, x)], s)
79+def top_level_from_dict(s: Any) -> float | int | bool | str | list[float | int | bool | list[Any] | A | str | None] | dict[str, Any] | None:
80+ return from_union([from_none, from_int, from_float, from_bool, from_str, lambda x: from_list(lambda x: from_union([from_none, from_int, from_float, from_bool, lambda x: from_list(lambda x: x, x), A.from_dict, from_str], x), x), lambda x: from_dict(lambda x: x, x)], s)
9881
9982
100-def top_level_to_dict(x: float | int | bool | str | list[float | int | bool | list[Any] | TopLevelClass | str | None] | dict[str, Any] | None) -> Any:
101- return from_union([from_none, from_int, to_float, from_bool, from_str, lambda x: from_list(lambda x: from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: x, x), lambda x: to_class(TopLevelClass, x), from_str], x), x), lambda x: from_dict(lambda x: x, x)], x)
83+def top_level_to_dict(x: float | int | bool | str | list[float | int | bool | list[Any] | A | str | None] | dict[str, Any] | None) -> Any:
84+ return from_union([from_none, from_int, to_float, from_bool, from_str, lambda x: from_list(lambda x: from_union([from_none, from_int, to_float, from_bool, lambda x: from_list(lambda x: x, x), lambda x: to_class(A, x), from_str], x), x), lambda x: from_dict(lambda x: x, x)], x)
Mschema-rubydefault / TopLevel.rb+24 −108
@@ -24,15 +24,15 @@ module Types
2424 end
2525
2626 # (forward declaration)
27-class XClass < Dry::Struct; end
27+class A < Dry::Struct; end
2828
29-class X < Dry::Struct
29+class TopLevel1 < Dry::Struct
3030 attribute :anything_map, Types::Hash.meta(of: Types::Any).optional
3131 attribute :bool, Types::Bool.optional
3232 attribute :double, Types::Double.optional
3333 attribute :null, Types::Nil.optional
3434 attribute :string, Types::String.optional
35- attribute :union_array, Types.Array(Types.Instance(XElement)).optional
35+ attribute :union_array, Types.Array(Types.Instance(TopLevelElement)).optional
3636
3737 def self.from_dynamic!(d)
3838 begin
@@ -55,7 +55,7 @@ class X < Dry::Struct
5555 return new(string: d, union_array: nil, bool: nil, double: nil, anything_map: nil, null: nil)
5656 end
5757 begin
58- value = d.map { |x| XElement.from_dynamic!(x) }
58+ value = d.map { |x| TopLevelElement.from_dynamic!(x) }
5959 if schema[:union_array].right.valid? value
6060 return new(union_array: value, bool: nil, double: nil, anything_map: nil, null: nil, string: nil)
6161 end
@@ -89,36 +89,36 @@ class X < Dry::Struct
8989 end
9090 end
9191
92-class XElement < Dry::Struct
92+class TopLevelElement < Dry::Struct
93+ attribute :a, A.optional
9394 attribute :anything_array, Types.Array(Types::Any).optional
9495 attribute :bool, Types::Bool.optional
9596 attribute :double, Types::Double.optional
9697 attribute :null, Types::Nil.optional
9798 attribute :string, Types::String.optional
98- attribute :x_class, XClass.optional
9999
100100 def self.from_dynamic!(d)
101+ begin
102+ value = A.from_dynamic!(d)
103+ if schema[:a].right.valid? value
104+ return new(a: value, anything_array: nil, bool: nil, double: nil, null: nil, string: nil)
105+ end
106+ rescue
107+ end
101108 if schema[:anything_array].right.valid? d
102- return new(anything_array: d, bool: nil, x_class: nil, double: nil, null: nil, string: nil)
109+ return new(anything_array: d, bool: nil, a: nil, double: nil, null: nil, string: nil)
103110 end
104111 if schema[:bool].right.valid? d
105- return new(bool: d, anything_array: nil, x_class: nil, double: nil, null: nil, string: nil)
112+ return new(bool: d, anything_array: nil, a: nil, double: nil, null: nil, string: nil)
106113 end
107114 if schema[:double].right.valid? d
108- return new(double: d, anything_array: nil, bool: nil, x_class: nil, null: nil, string: nil)
115+ return new(double: d, anything_array: nil, bool: nil, a: nil, null: nil, string: nil)
109116 end
110117 if schema[:null].right.valid? d
111- return new(null: d, anything_array: nil, bool: nil, x_class: nil, double: nil, string: nil)
118+ return new(null: d, anything_array: nil, bool: nil, a: nil, double: nil, string: nil)
112119 end
113120 if schema[:string].right.valid? d
114- return new(string: d, anything_array: nil, bool: nil, x_class: nil, double: nil, null: nil)
115- end
116- begin
117- value = XClass.from_dynamic!(d)
118- if schema[:x_class].right.valid? value
119- return new(x_class: value, anything_array: nil, bool: nil, double: nil, null: nil, string: nil)
120- end
121- rescue
121+ return new(string: d, anything_array: nil, bool: nil, a: nil, double: nil, null: nil)
122122 end
123123 raise "Invalid union"
124124 end
@@ -128,7 +128,9 @@ class XElement < Dry::Struct
128128 end
129129
130130 def to_dynamic
131- if anything_array != nil
131+ if a != nil
132+ a.to_dynamic
133+ elsif anything_array != nil
132134 anything_array
133135 elsif bool != nil
134136 bool
@@ -136,8 +138,6 @@ class XElement < Dry::Struct
136138 double
137139 elsif string != nil
138140 string
139- elsif x_class != nil
140- x_class.to_dynamic
141141 else
142142 nil
143143 end
@@ -148,38 +148,13 @@ class XElement < Dry::Struct
148148 end
149149 end
150150
151-class XClass < Dry::Struct
152- attribute :x, Types.Instance(X).optional
153-
154- def self.from_dynamic!(d)
155- d = Types::Hash[d]
156- new(
157- x: d["x"] ? X.from_dynamic!(d["x"]) : nil,
158- )
159- end
160-
161- def self.from_json!(json)
162- from_dynamic!(JSON.parse(json))
163- end
164-
165- def to_dynamic
166- {
167- "x" => x&.to_dynamic,
168- }
169- end
170-
171- def to_json(options = nil)
172- JSON.generate(to_dynamic, options)
173- end
174-end
175-
176-class TopLevelClass < Dry::Struct
177- attribute :x, Types.Instance(X).optional
151+class A < Dry::Struct
152+ attribute :x, Types.Instance(TopLevel1).optional
178153
179154 def self.from_dynamic!(d)
180155 d = Types::Hash[d]
181156 new(
182- x: d["x"] ? X.from_dynamic!(d["x"]) : nil,
157+ x: d["x"] ? TopLevel1.from_dynamic!(d["x"]) : nil,
183158 )
184159 end
185160
@@ -198,65 +173,6 @@ class TopLevelClass < Dry::Struct
198173 end
199174 end
200175
201-class TopLevelElement < Dry::Struct
202- attribute :anything_array, Types.Array(Types::Any).optional
203- attribute :bool, Types::Bool.optional
204- attribute :double, Types::Double.optional
205- attribute :null, Types::Nil.optional
206- attribute :string, Types::String.optional
207- attribute :top_level_class, TopLevelClass.optional
208-
209- def self.from_dynamic!(d)
210- if schema[:anything_array].right.valid? d
211- return new(anything_array: d, bool: nil, top_level_class: nil, double: nil, null: nil, string: nil)
212- end
213- if schema[:bool].right.valid? d
214- return new(bool: d, anything_array: nil, top_level_class: nil, double: nil, null: nil, string: nil)
215- end
216- if schema[:double].right.valid? d
217- return new(double: d, anything_array: nil, bool: nil, top_level_class: nil, null: nil, string: nil)
218- end
219- if schema[:null].right.valid? d
220- return new(null: d, anything_array: nil, bool: nil, top_level_class: nil, double: nil, string: nil)
221- end
222- if schema[:string].right.valid? d
223- return new(string: d, anything_array: nil, bool: nil, top_level_class: nil, double: nil, null: nil)
224- end
225- begin
226- value = TopLevelClass.from_dynamic!(d)
227- if schema[:top_level_class].right.valid? value
228- return new(top_level_class: value, anything_array: nil, bool: nil, double: nil, null: nil, string: nil)
229- end
230- rescue
231- end
232- raise "Invalid union"
233- end
234-
235- def self.from_json!(json)
236- from_dynamic!(JSON.parse(json))
237- end
238-
239- def to_dynamic
240- if anything_array != nil
241- anything_array
242- elsif bool != nil
243- bool
244- elsif double != nil
245- double
246- elsif string != nil
247- string
248- elsif top_level_class != nil
249- top_level_class.to_dynamic
250- else
251- nil
252- end
253- end
254-
255- def to_json(options = nil)
256- JSON.generate(to_dynamic, options)
257- end
258-end
259-
260176 class TopLevel < Dry::Struct
261177 attribute :anything_map, Types::Hash.meta(of: Types::Any).optional
262178 attribute :bool, Types::Bool.optional
Mschema-rustdefault / module_under_test.rs+8 −27
@@ -32,8 +32,8 @@ pub enum TopLevel {
3232
3333 #[derive(Debug, Clone, Serialize, Deserialize)]
3434 #[serde(untagged)]
35-pub enum TopLevelElement {
36- AnythingArray(Vec<Option<serde_json::Value>>),
35+pub enum PurpleTopLevel {
36+ AnythingMap(HashMap<String, Option<serde_json::Value>>),
3737
3838 Bool(bool),
3939
@@ -41,43 +41,24 @@ pub enum TopLevelElement {
4141
4242 PurpleString(String),
4343
44- TopLevelClass(TopLevelClass),
45-}
46-
47-#[derive(Debug, Clone, Serialize, Deserialize)]
48-pub struct TopLevelClass {
49- pub x: Option<X>,
44+ UnionArray(Vec<Option<TopLevelElement>>),
5045 }
5146
5247 #[derive(Debug, Clone, Serialize, Deserialize)]
53-pub struct XClass {
54- pub x: Option<X>,
48+pub struct A {
49+ pub x: Option<PurpleTopLevel>,
5550 }
5651
5752 #[derive(Debug, Clone, Serialize, Deserialize)]
5853 #[serde(untagged)]
59-pub enum XElement {
60- AnythingArray(Vec<Option<serde_json::Value>>),
61-
62- Bool(bool),
63-
64- Double(f64),
65-
66- PurpleString(String),
67-
68- XClass(XClass),
69-}
54+pub enum TopLevelElement {
55+ A(A),
7056
71-#[derive(Debug, Clone, Serialize, Deserialize)]
72-#[serde(untagged)]
73-pub enum X {
74- AnythingMap(HashMap<String, Option<serde_json::Value>>),
57+ AnythingArray(Vec<Option<serde_json::Value>>),
7558
7659 Bool(bool),
7760
7861 Double(f64),
7962
8063 PurpleString(String),
81-
82- UnionArray(Vec<Option<XElement>>),
8364 }
Mschema-scala3-upickledefault / TopLevel.scala+8 −55
@@ -87,76 +87,29 @@ given unionWriterTopLevel: OptionPickler.Writer[TopLevel] = OptionPickler.writer
8787 case v: NullValue => OptionPickler.writeJs[NullValue](v)
8888 }
8989
90-type TopLevelElement = Seq[Option[ujson.Value]] | Boolean | Double | Long | String | TopLevelClass | NullValue
91-given unionReaderTopLevelElement: OptionPickler.Reader[TopLevelElement] = JsonExt.badMerge[TopLevelElement](
92- JsonExt.strictString,
93- JsonExt.strictBoolean,
94- JsonExt.strictLong,
95- JsonExt.strictDouble,
96- summon[OptionPickler.Reader[Seq[Option[ujson.Value]]]],
97- summon[OptionPickler.Reader[TopLevelClass]],
98- summon[OptionPickler.Reader[NullValue]],
99- )
100-
101-given unionWriterTopLevelElement: OptionPickler.Writer[TopLevelElement] = OptionPickler.writer[ujson.Value].comap[TopLevelElement]{ _v =>
102- (_v: @unchecked) match
103- case v: String => OptionPickler.writeJs[String](v)
104- case v: Boolean => OptionPickler.writeJs[Boolean](v)
105- case v: Long => OptionPickler.writeJs[Long](v)
106- case v: Double => OptionPickler.writeJs[Double](v)
107- case v: Seq[Option[ujson.Value]] => OptionPickler.writeJs[Seq[Option[ujson.Value]]](v)
108- case v: TopLevelClass => OptionPickler.writeJs[TopLevelClass](v)
109- case v: NullValue => OptionPickler.writeJs[NullValue](v)
110-}
111-
112-case class TopLevelClass (
113- val x : Option[X] = None
114-) derives OptionPickler.ReadWriter
115-
116-case class XClass (
117- val x : Option[X] = None
90+type PurpleTopLevel = Map[String, Option[ujson.Value]] | Boolean | Double | Long | String | Seq[TopLevelElement] | NullValue
91+case class A (
92+ val x : Option[PurpleTopLevel] = None
11893 ) derives OptionPickler.ReadWriter
11994
120-type XElement = Seq[Option[ujson.Value]] | Boolean | Double | Long | String | XClass | NullValue
121-given unionReaderXElement: OptionPickler.Reader[XElement] = JsonExt.badMerge[XElement](
95+type TopLevelElement = A | Seq[Option[ujson.Value]] | Boolean | Double | Long | String | NullValue
96+given unionReaderTopLevelElement: OptionPickler.Reader[TopLevelElement] = JsonExt.badMerge[TopLevelElement](
12297 JsonExt.strictString,
12398 JsonExt.strictBoolean,
12499 JsonExt.strictLong,
125100 JsonExt.strictDouble,
126101 summon[OptionPickler.Reader[Seq[Option[ujson.Value]]]],
127- summon[OptionPickler.Reader[XClass]],
102+ summon[OptionPickler.Reader[A]],
128103 summon[OptionPickler.Reader[NullValue]],
129104 )
130105
131-given unionWriterXElement: OptionPickler.Writer[XElement] = OptionPickler.writer[ujson.Value].comap[XElement]{ _v =>
106+given unionWriterTopLevelElement: OptionPickler.Writer[TopLevelElement] = OptionPickler.writer[ujson.Value].comap[TopLevelElement]{ _v =>
132107 (_v: @unchecked) match
133108 case v: String => OptionPickler.writeJs[String](v)
134109 case v: Boolean => OptionPickler.writeJs[Boolean](v)
135110 case v: Long => OptionPickler.writeJs[Long](v)
136111 case v: Double => OptionPickler.writeJs[Double](v)
137112 case v: Seq[Option[ujson.Value]] => OptionPickler.writeJs[Seq[Option[ujson.Value]]](v)
138- case v: XClass => OptionPickler.writeJs[XClass](v)
139- case v: NullValue => OptionPickler.writeJs[NullValue](v)
140-}
141-
142-type X = Map[String, Option[ujson.Value]] | Boolean | Double | Long | String | Seq[XElement] | NullValue
143-given unionReaderX: OptionPickler.Reader[X] = JsonExt.badMerge[X](
144- JsonExt.strictString,
145- JsonExt.strictBoolean,
146- JsonExt.strictLong,
147- JsonExt.strictDouble,
148- summon[OptionPickler.Reader[Seq[XElement]]],
149- summon[OptionPickler.Reader[Map[String, Option[ujson.Value]]]],
150- summon[OptionPickler.Reader[NullValue]],
151- )
152-
153-given unionWriterX: OptionPickler.Writer[X] = OptionPickler.writer[ujson.Value].comap[X]{ _v =>
154- (_v: @unchecked) match
155- case v: String => OptionPickler.writeJs[String](v)
156- case v: Boolean => OptionPickler.writeJs[Boolean](v)
157- case v: Long => OptionPickler.writeJs[Long](v)
158- case v: Double => OptionPickler.writeJs[Double](v)
159- case v: Seq[XElement] => OptionPickler.writeJs[Seq[XElement]](v)
160- case v: Map[String, Option[ujson.Value]] => OptionPickler.writeJs[Map[String, Option[ujson.Value]]](v)
113+ case v: A => OptionPickler.writeJs[A](v)
161114 case v: NullValue => OptionPickler.writeJs[NullValue](v)
162115 }
Mschema-scala3default / TopLevel.scala+8 −57
@@ -30,7 +30,12 @@ given Encoder[TopLevel] = Encoder.instance {
3030 case enc6 : NullValue => Encoder.encodeNone(enc6)
3131 }
3232
33-type TopLevelElement = Seq[Option[Json]] | Boolean | Double | Long | String | TopLevelClass | NullValue
33+type PurpleTopLevel = Map[String, Option[Json]] | Boolean | Double | Long | String | Seq[TopLevelElement] | NullValue
34+case class A (
35+ val x : Option[PurpleTopLevel] = None
36+) derives Encoder.AsObject, Decoder
37+
38+type TopLevelElement = A | Seq[Option[Json]] | Boolean | Double | Long | String | NullValue
3439 given Decoder[TopLevelElement] = {
3540 List[Decoder[TopLevelElement]](
3641 Decoder[String].widen,
@@ -38,7 +43,7 @@ given Decoder[TopLevelElement] = {
3843 Decoder[Long].widen,
3944 Decoder[Double].widen,
4045 Decoder[Seq[Option[Json]]].widen,
41- Decoder[TopLevelClass].widen,
46+ Decoder[A].widen,
4247 Decoder[NullValue].widen,
4348 ).reduceLeft(_ or _)
4449 }
@@ -49,60 +54,6 @@ given Encoder[TopLevelElement] = Encoder.instance {
4954 case enc2 : Long => Encoder.encodeLong(enc2)
5055 case enc3 : Double => Encoder.encodeDouble(enc3)
5156 case enc4 : Seq[Option[Json]] => Encoder.encodeSeq[Option[Json]].apply(enc4)
52- case enc5 : TopLevelClass => Encoder.AsObject[TopLevelClass].apply(enc5)
53- case enc6 : NullValue => Encoder.encodeNone(enc6)
54-}
55-
56-case class TopLevelClass (
57- val x : Option[X] = None
58-) derives Encoder.AsObject, Decoder
59-
60-case class XClass (
61- val x : Option[X] = None
62-) derives Encoder.AsObject, Decoder
63-
64-type XElement = Seq[Option[Json]] | Boolean | Double | Long | String | XClass | NullValue
65-given Decoder[XElement] = {
66- List[Decoder[XElement]](
67- Decoder[String].widen,
68- Decoder[Boolean].widen,
69- Decoder[Long].widen,
70- Decoder[Double].widen,
71- Decoder[Seq[Option[Json]]].widen,
72- Decoder[XClass].widen,
73- Decoder[NullValue].widen,
74- ).reduceLeft(_ or _)
75-}
76-
77-given Encoder[XElement] = Encoder.instance {
78- case enc0 : String => Encoder.encodeString(enc0)
79- case enc1 : Boolean => Encoder.encodeBoolean(enc1)
80- case enc2 : Long => Encoder.encodeLong(enc2)
81- case enc3 : Double => Encoder.encodeDouble(enc3)
82- case enc4 : Seq[Option[Json]] => Encoder.encodeSeq[Option[Json]].apply(enc4)
83- case enc5 : XClass => Encoder.AsObject[XClass].apply(enc5)
84- case enc6 : NullValue => Encoder.encodeNone(enc6)
85-}
86-
87-type X = Map[String, Option[Json]] | Boolean | Double | Long | String | Seq[XElement] | NullValue
88-given Decoder[X] = {
89- List[Decoder[X]](
90- Decoder[String].widen,
91- Decoder[Boolean].widen,
92- Decoder[Long].widen,
93- Decoder[Double].widen,
94- Decoder[Seq[XElement]].widen,
95- Decoder[Map[String, Option[Json]]].widen,
96- Decoder[NullValue].widen,
97- ).reduceLeft(_ or _)
98-}
99-
100-given Encoder[X] = Encoder.instance {
101- case enc0 : String => Encoder.encodeString(enc0)
102- case enc1 : Boolean => Encoder.encodeBoolean(enc1)
103- case enc2 : Long => Encoder.encodeLong(enc2)
104- case enc3 : Double => Encoder.encodeDouble(enc3)
105- case enc4 : Seq[XElement] => Encoder.encodeSeq[XElement].apply(enc4)
106- case enc5 : Map[String, Option[Json]] => Encoder.encodeMap[String,Option[Json]].apply(enc5)
57+ case enc5 : A => Encoder.AsObject[A].apply(enc5)
10758 case enc6 : NullValue => Encoder.encodeNone(enc6)
10859 }
Mschema-schemadefault / TopLevel.schema+14 −49
@@ -2,27 +2,16 @@
22 "$schema": "http://json-schema.org/draft-06/schema#",
33 "$ref": "#/definitions/TopLevel",
44 "definitions": {
5- "TopLevelObject": {
5+ "A": {
66 "type": "object",
77 "additionalProperties": {},
88 "properties": {
99 "x": {
10- "$ref": "#/definitions/X"
10+ "$ref": "#/definitions/PurpleTopLevel"
1111 }
1212 },
1313 "required": [],
14- "title": "TopLevelObject"
15- },
16- "XObject": {
17- "type": "object",
18- "additionalProperties": {},
19- "properties": {
20- "x": {
21- "$ref": "#/definitions/X"
22- }
23- },
24- "required": [],
25- "title": "XObject"
14+ "title": "A"
2615 },
2716 "TopLevel": {
2817 "anyOf": [
@@ -54,11 +43,13 @@
5443 ],
5544 "title": "TopLevel"
5645 },
57- "TopLevelElement": {
46+ "PurpleTopLevel": {
5847 "anyOf": [
5948 {
6049 "type": "array",
61- "items": {}
50+ "items": {
51+ "$ref": "#/definitions/TopLevelElement"
52+ }
6253 },
6354 {
6455 "type": "boolean"
@@ -67,18 +58,19 @@
6758 "type": "number"
6859 },
6960 {
70- "type": "null"
61+ "type": "object",
62+ "additionalProperties": {}
7163 },
7264 {
73- "$ref": "#/definitions/TopLevelObject"
65+ "type": "null"
7466 },
7567 {
7668 "type": "string"
7769 }
7870 ],
79- "title": "TopLevelElement"
71+ "title": "PurpleTopLevel"
8072 },
81- "XElement": {
73+ "TopLevelElement": {
8274 "anyOf": [
8375 {
8476 "type": "array",
@@ -94,40 +86,13 @@
9486 "type": "null"
9587 },
9688 {
97- "$ref": "#/definitions/XObject"
98- },
99- {
100- "type": "string"
101- }
102- ],
103- "title": "XElement"
104- },
105- "X": {
106- "anyOf": [
107- {
108- "type": "array",
109- "items": {
110- "$ref": "#/definitions/XElement"
111- }
112- },
113- {
114- "type": "boolean"
115- },
116- {
117- "type": "number"
118- },
119- {
120- "type": "object",
121- "additionalProperties": {}
122- },
123- {
124- "type": "null"
89+ "$ref": "#/definitions/A"
12590 },
12691 {
12792 "type": "string"
12893 }
12994 ],
130- "title": "X"
95+ "title": "TopLevelElement"
13196 }
13297 }
13398 }
Mschema-swiftdefault / quicktype.swift+28 −135
@@ -68,13 +68,13 @@ enum TopLevel: Codable {
6868 }
6969 }
7070
71-enum TopLevelElement: Codable {
72- case anythingArray([JSONAny])
71+enum PurpleTopLevel: Codable {
72+ case anythingMap([String: JSONAny])
7373 case bool(Bool)
7474 case double(Double)
7575 case integer(Int)
7676 case string(String)
77- case topLevelClass(TopLevelClass)
77+ case unionArray([TopLevelElement])
7878 case null
7979
8080 init(from decoder: Decoder) throws {
@@ -87,33 +87,33 @@ enum TopLevelElement: Codable {
8787 self = .integer(x)
8888 return
8989 }
90- if let x = try? container.decode([JSONAny].self) {
91- self = .anythingArray(x)
90+ if let x = try? container.decode([TopLevelElement].self) {
91+ self = .unionArray(x)
9292 return
9393 }
9494 if let x = try? container.decode(Double.self) {
9595 self = .double(x)
9696 return
9797 }
98- if let x = try? container.decode(String.self) {
99- self = .string(x)
98+ if let x = try? container.decode([String: JSONAny].self) {
99+ self = .anythingMap(x)
100100 return
101101 }
102- if let x = try? container.decode(TopLevelClass.self) {
103- self = .topLevelClass(x)
102+ if let x = try? container.decode(String.self) {
103+ self = .string(x)
104104 return
105105 }
106106 if container.decodeNil() {
107107 self = .null
108108 return
109109 }
110- throw DecodingError.typeMismatch(TopLevelElement.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for TopLevelElement"))
110+ throw DecodingError.typeMismatch(PurpleTopLevel.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for PurpleTopLevel"))
111111 }
112112
113113 func encode(to encoder: Encoder) throws {
114114 var container = encoder.singleValueContainer()
115115 switch self {
116- case .anythingArray(let x):
116+ case .anythingMap(let x):
117117 try container.encode(x)
118118 case .bool(let x):
119119 try container.encode(x)
@@ -123,7 +123,7 @@ enum TopLevelElement: Codable {
123123 try container.encode(x)
124124 case .string(let x):
125125 try container.encode(x)
126- case .topLevelClass(let x):
126+ case .unionArray(let x):
127127 try container.encode(x)
128128 case .null:
129129 try container.encodeNil()
@@ -131,64 +131,20 @@ enum TopLevelElement: Codable {
131131 }
132132 }
133133
134-// MARK: - TopLevelClass
135-struct TopLevelClass: Codable {
136- let x: X?
137-
138- enum CodingKeys: String, CodingKey {
139- case x = "x"
140- }
141-}
142-
143-// MARK: TopLevelClass convenience initializers and mutators
144-
145-extension TopLevelClass {
146- init(data: Data) throws {
147- self = try newJSONDecoder().decode(TopLevelClass.self, from: data)
148- }
149-
150- init(_ json: String, using encoding: String.Encoding = .utf8) throws {
151- guard let data = json.data(using: encoding) else {
152- throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
153- }
154- try self.init(data: data)
155- }
156-
157- init(fromURL url: URL) throws {
158- try self.init(data: try Data(contentsOf: url))
159- }
160-
161- func with(
162- x: X?? = nil
163- ) -> TopLevelClass {
164- return TopLevelClass(
165- x: x ?? self.x
166- )
167- }
168-
169- func jsonData() throws -> Data {
170- return try newJSONEncoder().encode(self)
171- }
172-
173- func jsonString(encoding: String.Encoding = .utf8) throws -> String? {
174- return String(data: try self.jsonData(), encoding: encoding)
175- }
176-}
177-
178-// MARK: - XClass
179-struct XClass: Codable {
180- let x: X?
134+// MARK: - A
135+struct A: Codable {
136+ let x: PurpleTopLevel?
181137
182138 enum CodingKeys: String, CodingKey {
183139 case x = "x"
184140 }
185141 }
186142
187-// MARK: XClass convenience initializers and mutators
143+// MARK: A convenience initializers and mutators
188144
189-extension XClass {
145+extension A {
190146 init(data: Data) throws {
191- self = try newJSONDecoder().decode(XClass.self, from: data)
147+ self = try newJSONDecoder().decode(A.self, from: data)
192148 }
193149
194150 init(_ json: String, using encoding: String.Encoding = .utf8) throws {
@@ -203,9 +159,9 @@ extension XClass {
203159 }
204160
205161 func with(
206- x: X?? = nil
207- ) -> XClass {
208- return XClass(
162+ x: PurpleTopLevel?? = nil
163+ ) -> A {
164+ return A(
209165 x: x ?? self.x
210166 )
211167 }
@@ -219,13 +175,13 @@ extension XClass {
219175 }
220176 }
221177
222-enum XElement: Codable {
178+enum TopLevelElement: Codable {
179+ case a(A)
223180 case anythingArray([JSONAny])
224181 case bool(Bool)
225182 case double(Double)
226183 case integer(Int)
227184 case string(String)
228- case xClass(XClass)
229185 case null
230186
231187 init(from decoder: Decoder) throws {
@@ -250,84 +206,23 @@ enum XElement: Codable {
250206 self = .string(x)
251207 return
252208 }
253- if let x = try? container.decode(XClass.self) {
254- self = .xClass(x)
209+ if let x = try? container.decode(A.self) {
210+ self = .a(x)
255211 return
256212 }
257213 if container.decodeNil() {
258214 self = .null
259215 return
260216 }
261- throw DecodingError.typeMismatch(XElement.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for XElement"))
217+ throw DecodingError.typeMismatch(TopLevelElement.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for TopLevelElement"))
262218 }
263219
264220 func encode(to encoder: Encoder) throws {
265221 var container = encoder.singleValueContainer()
266222 switch self {
267- case .anythingArray(let x):
268- try container.encode(x)
269- case .bool(let x):
223+ case .a(let x):
270224 try container.encode(x)
271- case .double(let x):
272- try container.encode(x)
273- case .integer(let x):
274- try container.encode(x)
275- case .string(let x):
276- try container.encode(x)
277- case .xClass(let x):
278- try container.encode(x)
279- case .null:
280- try container.encodeNil()
281- }
282- }
283-}
284-
285-enum X: Codable {
286- case anythingMap([String: JSONAny])
287- case bool(Bool)
288- case double(Double)
289- case integer(Int)
290- case string(String)
291- case unionArray([XElement])
292- case null
293-
294- init(from decoder: Decoder) throws {
295- let container = try decoder.singleValueContainer()
296- if let x = try? container.decode(Bool.self) {
297- self = .bool(x)
298- return
299- }
300- if let x = try? container.decode(Int.self) {
301- self = .integer(x)
302- return
303- }
304- if let x = try? container.decode([XElement].self) {
305- self = .unionArray(x)
306- return
307- }
308- if let x = try? container.decode(Double.self) {
309- self = .double(x)
310- return
311- }
312- if let x = try? container.decode([String: JSONAny].self) {
313- self = .anythingMap(x)
314- return
315- }
316- if let x = try? container.decode(String.self) {
317- self = .string(x)
318- return
319- }
320- if container.decodeNil() {
321- self = .null
322- return
323- }
324- throw DecodingError.typeMismatch(X.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for X"))
325- }
326-
327- func encode(to encoder: Encoder) throws {
328- var container = encoder.singleValueContainer()
329- switch self {
330- case .anythingMap(let x):
225+ case .anythingArray(let x):
331226 try container.encode(x)
332227 case .bool(let x):
333228 try container.encode(x)
@@ -337,8 +232,6 @@ enum X: Codable {
337232 try container.encode(x)
338233 case .string(let x):
339234 try container.encode(x)
340- case .unionArray(let x):
341- try container.encode(x)
342235 case .null:
343236 try container.encodeNil()
344237 }
Mschema-typescriptdefault / TopLevel.ts+8 −18
@@ -9,31 +9,24 @@
99
1010 export type TopLevel = TopLevelElement[] | boolean | number | number | { [key: string]: unknown } | null | string;
1111
12-export type TopLevelElement = unknown[] | boolean | number | null | TopLevelObject | string;
12+export type PurpleTopLevel = TopLevelElement[] | boolean | number | { [key: string]: unknown } | null | string;
1313
14-export interface TopLevelObject {
15- x?: X;
14+export interface A {
15+ x?: PurpleTopLevel;
1616 [property: string]: unknown;
1717 }
1818
19-export interface XObject {
20- x?: X;
21- [property: string]: unknown;
22-}
23-
24-export type XElement = unknown[] | boolean | number | null | XObject | string;
25-
26-export type X = XElement[] | boolean | number | { [key: string]: unknown } | null | string;
19+export type TopLevelElement = unknown[] | boolean | number | null | A | string;
2720
2821 // Converts JSON strings to/from your types
2922 // and asserts the results of JSON.parse at runtime
3023 export class Convert {
3124 public static toTopLevel(json: string): TopLevel {
32- return cast(JSON.parse(json), u(a(u(a("any"), true, 3.14, null, r("TopLevelObject"), "")), true, 3.14, 0, m("any"), null, ""));
25+ return cast(JSON.parse(json), u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, 0, m("any"), null, ""));
3326 }
3427
3528 public static topLevelToJson(value: TopLevel): string {
36- return JSON.stringify(uncast(value, u(a(u(a("any"), true, 3.14, null, r("TopLevelObject"), "")), true, 3.14, 0, m("any"), null, "")), null, 2);
29+ return JSON.stringify(uncast(value, u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, 0, m("any"), null, "")), null, 2);
3730 }
3831 }
3932
@@ -191,10 +184,7 @@ function r(name: string) {
191184 }
192185
193186 const typeMap: any = {
194- "TopLevelObject": o([
195- { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("XObject"), "")), true, 3.14, m("any"), null, "")) },
196- ], "any"),
197- "XObject": o([
198- { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("XObject"), "")), true, 3.14, m("any"), null, "")) },
187+ "A": o([
188+ { json: "x", js: "x", typ: u(undefined, u(a(u(a("any"), true, 3.14, null, r("A"), "")), true, 3.14, m("any"), null, "")) },
199189 ], "any"),
200190 };
Test case

test/inputs/schema/rust-cycle-breaker-union.schema

29 generated files · +223 −795
Mschema-cplusplusdefault / quicktype.hpp+10 −42
@@ -89,27 +89,9 @@ namespace quicktype {
8989 }
9090 #endif
9191
92- class Node;
92+ class TopLevel;
9393
94- using Next = std::shared_ptr<std::variant<std::shared_ptr<Node>, std::string>>;
95-
96- class Node {
97- public:
98- Node() = default;
99- virtual ~Node() = default;
100-
101- private:
102- Next next;
103- std::string value;
104-
105- public:
106- Next get_next() const { return next; }
107- void set_next(Next value) { this->next = value; }
108-
109- const std::string & get_value() const { return value; }
110- std::string & get_mutable_value() { return value; }
111- void set_value(const std::string & value) { this->value = value; }
112- };
94+ using Next = std::optional<std::variant<std::shared_ptr<TopLevel>, std::string>>;
11395
11496 class TopLevel {
11597 public:
@@ -131,33 +113,19 @@ namespace quicktype {
131113 }
132114
133115 namespace quicktype {
134-void from_json(const json & j, Node & x);
135-void to_json(json & j, const Node & x);
136-
137116 void from_json(const json & j, TopLevel & x);
138117 void to_json(json & j, const TopLevel & x);
139118 }
140119 namespace nlohmann {
141120 template <>
142-struct adl_serializer<std::variant<std::shared_ptr<quicktype::Node>, std::string>> {
143- static void from_json(const json & j, std::variant<std::shared_ptr<quicktype::Node>, std::string> & x);
144- static void to_json(json & j, const std::variant<std::shared_ptr<quicktype::Node>, std::string> & x);
121+struct adl_serializer<std::variant<std::shared_ptr<quicktype::TopLevel>, std::string>> {
122+ static void from_json(const json & j, std::variant<std::shared_ptr<quicktype::TopLevel>, std::string> & x);
123+ static void to_json(json & j, const std::variant<std::shared_ptr<quicktype::TopLevel>, std::string> & x);
145124 };
146125 }
147126 namespace quicktype {
148- inline void from_json(const json & j, Node& x) {
149- x.set_next(get_heap_optional<std::variant<std::shared_ptr<Node>, std::string>>(j, "next"));
150- x.set_value(j.at("value").get<std::string>());
151- }
152-
153- inline void to_json(json & j, const Node & x) {
154- j = json::object();
155- j["next"] = x.get_next();
156- j["value"] = x.get_value();
157- }
158-
159127 inline void from_json(const json & j, TopLevel& x) {
160- x.set_next(get_heap_optional<std::variant<std::shared_ptr<Node>, std::string>>(j, "next"));
128+ x.set_next(get_stack_optional<std::variant<std::shared_ptr<TopLevel>, std::string>>(j, "next"));
161129 x.set_value(j.at("value").get<std::string>());
162130 }
163131
@@ -168,18 +136,18 @@ namespace quicktype {
168136 }
169137 }
170138 namespace nlohmann {
171- inline void adl_serializer<std::variant<std::shared_ptr<quicktype::Node>, std::string>>::from_json(const json & j, std::variant<std::shared_ptr<quicktype::Node>, std::string> & x) {
139+ inline void adl_serializer<std::variant<std::shared_ptr<quicktype::TopLevel>, std::string>>::from_json(const json & j, std::variant<std::shared_ptr<quicktype::TopLevel>, std::string> & x) {
172140 if (j.is_string())
173141 x = j.get<std::string>();
174142 else if (j.is_object())
175- x = j.get<std::shared_ptr<quicktype::Node>>();
143+ x = j.get<std::shared_ptr<quicktype::TopLevel>>();
176144 else throw std::runtime_error("Could not deserialise!");
177145 }
178146
179- inline void adl_serializer<std::variant<std::shared_ptr<quicktype::Node>, std::string>>::to_json(json & j, const std::variant<std::shared_ptr<quicktype::Node>, std::string> & x) {
147+ inline void adl_serializer<std::variant<std::shared_ptr<quicktype::TopLevel>, std::string>>::to_json(json & j, const std::variant<std::shared_ptr<quicktype::TopLevel>, std::string> & x) {
180148 switch (x.index()) {
181149 case 0:
182- j = std::get<std::shared_ptr<quicktype::Node>>(x);
150+ j = std::get<std::shared_ptr<quicktype::TopLevel>>(x);
183151 break;
184152 case 1:
185153 j = std::get<std::string>(x);
Mschema-csharp-recordsdefault / QuickType.cs+7 −16
@@ -32,23 +32,14 @@ namespace QuickType
3232 public string Value { get; set; }
3333 }
3434
35- public partial record Node
36- {
37- [JsonProperty("next")]
38- public Next? Next { get; set; }
39-
40- [JsonProperty("value", Required = Required.Always)]
41- public string Value { get; set; }
42- }
43-
4435 public partial struct Next
4536 {
46- public Node? Node;
4737 public string? String;
38+ public TopLevel? TopLevel;
4839
49- public static implicit operator Next(Node Node) => new Next { Node = Node };
5040 public static implicit operator Next(string String) => new Next { String = String };
51- public bool IsNull => Node == null && String == null;
41+ public static implicit operator Next(TopLevel TopLevel) => new Next { TopLevel = TopLevel };
42+ public bool IsNull => TopLevel == null && String == null;
5243 }
5344
5445 public partial record TopLevel
@@ -90,8 +81,8 @@ namespace QuickType
9081 var stringValue = serializer.Deserialize<string>(reader);
9182 return new Next { String = stringValue };
9283 case JsonToken.StartObject:
93- var objectValue = serializer.Deserialize<Node>(reader);
94- return new Next { Node = objectValue };
84+ var objectValue = serializer.Deserialize<TopLevel>(reader);
85+ return new Next { TopLevel = objectValue };
9586 }
9687 throw new Exception("Cannot unmarshal type Next");
9788 }
@@ -109,9 +100,9 @@ namespace QuickType
109100 serializer.Serialize(writer, value.String);
110101 return;
111102 }
112- if (value.Node != null)
103+ if (value.TopLevel != null)
113104 {
114- serializer.Serialize(writer, value.Node);
105+ serializer.Serialize(writer, value.TopLevel);
115106 return;
116107 }
117108 throw new Exception("Cannot marshal type Next");
Mschema-csharp-SystemTextJsondefault / QuickType.cs+7 −17
@@ -30,24 +30,14 @@ namespace QuickType
3030 public string Value { get; set; }
3131 }
3232
33- public partial class Node
34- {
35- [JsonPropertyName("next")]
36- public Next? Next { get; set; }
37-
38- [JsonRequired]
39- [JsonPropertyName("value")]
40- public string Value { get; set; }
41- }
42-
4333 public partial struct Next
4434 {
45- public Node? Node;
4635 public string? String;
36+ public TopLevel? TopLevel;
4737
48- public static implicit operator Next(Node Node) => new Next { Node = Node };
4938 public static implicit operator Next(string String) => new Next { String = String };
50- public bool IsNull => Node == null && String == null;
39+ public static implicit operator Next(TopLevel TopLevel) => new Next { TopLevel = TopLevel };
40+ public bool IsNull => TopLevel == null && String == null;
5141 }
5242
5343 public partial class TopLevel
@@ -88,8 +78,8 @@ namespace QuickType
8878 var stringValue = reader.GetString();
8979 return new Next { String = stringValue };
9080 case JsonTokenType.StartObject:
91- var objectValue = JsonSerializer.Deserialize<Node>(ref reader, options);
92- return new Next { Node = objectValue };
81+ var objectValue = JsonSerializer.Deserialize<TopLevel>(ref reader, options);
82+ return new Next { TopLevel = objectValue };
9383 }
9484 throw new JsonException("Cannot unmarshal type Next");
9585 }
@@ -106,9 +96,9 @@ namespace QuickType
10696 JsonSerializer.Serialize(writer, value.String, options);
10797 return;
10898 }
109- if (value.Node != null)
99+ if (value.TopLevel != null)
110100 {
111- JsonSerializer.Serialize(writer, value.Node, options);
101+ JsonSerializer.Serialize(writer, value.TopLevel, options);
112102 return;
113103 }
114104 throw new NotSupportedException("Cannot marshal type Next");
Mschema-csharpdefault / QuickType.cs+7 −16
@@ -32,23 +32,14 @@ namespace QuickType
3232 public string Value { get; set; }
3333 }
3434
35- public partial class Node
36- {
37- [JsonProperty("next")]
38- public Next? Next { get; set; }
39-
40- [JsonProperty("value", Required = Required.Always)]
41- public string Value { get; set; }
42- }
43-
4435 public partial struct Next
4536 {
46- public Node? Node;
4737 public string? String;
38+ public TopLevel? TopLevel;
4839
49- public static implicit operator Next(Node Node) => new Next { Node = Node };
5040 public static implicit operator Next(string String) => new Next { String = String };
51- public bool IsNull => Node == null && String == null;
41+ public static implicit operator Next(TopLevel TopLevel) => new Next { TopLevel = TopLevel };
42+ public bool IsNull => TopLevel == null && String == null;
5243 }
5344
5445 public partial class TopLevel
@@ -90,8 +81,8 @@ namespace QuickType
9081 var stringValue = serializer.Deserialize<string>(reader);
9182 return new Next { String = stringValue };
9283 case JsonToken.StartObject:
93- var objectValue = serializer.Deserialize<Node>(reader);
94- return new Next { Node = objectValue };
84+ var objectValue = serializer.Deserialize<TopLevel>(reader);
85+ return new Next { TopLevel = objectValue };
9586 }
9687 throw new Exception("Cannot unmarshal type Next");
9788 }
@@ -109,9 +100,9 @@ namespace QuickType
109100 serializer.Serialize(writer, value.String);
110101 return;
111102 }
112- if (value.Node != null)
103+ if (value.TopLevel != null)
113104 {
114- serializer.Serialize(writer, value.Node);
105+ serializer.Serialize(writer, value.TopLevel);
115106 return;
116107 }
117108 throw new Exception("Cannot marshal type Next");
Mschema-dartdefault / TopLevel.dart+0 −20
@@ -27,23 +27,3 @@ class TopLevel {
2727 "value": value,
2828 };
2929 }
30-
31-class Node {
32- final dynamic next;
33- final String value;
34-
35- Node({
36- this.next,
37- required this.value,
38- });
39-
40- factory Node.fromJson(Map<String, dynamic> json) => Node(
41- next: json["next"],
42- value: json["value"],
43- );
44-
45- Map<String, dynamic> toJson() => {
46- "next": next,
47- "value": value,
48- };
49-}
Mschema-elixirdefault / QuickType.ex+3 −49
@@ -5,67 +5,21 @@
55 # Decode a JSON string: TopLevel.from_json(data)
66 # Encode into a JSON string: TopLevel.to_json(struct)
77
8-defmodule NodeClass do
9- @enforce_keys [:value]
10- defstruct [:next, :value]
11-
12- @type t :: %__MODULE__{
13- next: NodeClass.t() | nil | String.t() | nil,
14- value: String.t()
15- }
16-
17- def decode_next(%{"value" => _,} = value), do: NodeClass.from_map(value)
18- def decode_next(value) when is_nil(value), do: value
19- def decode_next(value) when is_binary(value), do: value
20- def decode_next(_), do: {:error, "Unexpected type when decoding NodeClass.next"}
21-
22- def encode_next(%NodeClass{} = value), do: NodeClass.to_map(value)
23- def encode_next(value) when is_nil(value), do: value
24- def encode_next(value) when is_binary(value), do: value
25- def encode_next(_), do: {:error, "Unexpected type when encoding NodeClass.next"}
26-
27- def from_map(m) do
28- %NodeClass{
29- next: decode_next(m["next"]),
30- value: m["value"],
31- }
32- end
33-
34- def from_json(json) do
35- json
36- |> Jason.decode!()
37- |> from_map()
38- end
39-
40- def to_map(struct) do
41- %{
42- "next" => encode_next(struct.next),
43- "value" => struct.value,
44- }
45- end
46-
47- def to_json(struct) do
48- struct
49- |> to_map()
50- |> Jason.encode!()
51- end
52-end
53-
548 defmodule TopLevel do
559 @enforce_keys [:value]
5610 defstruct [:next, :value]
5711
5812 @type t :: %__MODULE__{
59- next: NodeClass.t() | nil | String.t() | nil,
13+ next: TopLevel.t() | nil | String.t() | nil,
6014 value: String.t()
6115 }
6216
63- def decode_next(%{"value" => _,} = value), do: NodeClass.from_map(value)
17+ def decode_next(%{"value" => _,} = value), do: TopLevel.from_map(value)
6418 def decode_next(value) when is_nil(value), do: value
6519 def decode_next(value) when is_binary(value), do: value
6620 def decode_next(_), do: {:error, "Unexpected type when decoding TopLevel.next"}
6721
68- def encode_next(%NodeClass{} = value), do: NodeClass.to_map(value)
22+ def encode_next(%TopLevel{} = value), do: TopLevel.to_map(value)
6923 def encode_next(value) when is_nil(value), do: value
7024 def encode_next(value) when is_binary(value), do: value
7125 def encode_next(_), do: {:error, "Unexpected type when encoding TopLevel.next"}
Mschema-flowdefault / TopLevel.js+3 −13
@@ -9,20 +9,14 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
13- next?: Next;
14- value: string;
15- [property: string]: mixed;
16-};
12+export type Next = null | TopLevel | string;
1713
18-export type Node = {
14+export type TopLevel = {
1915 next?: Next;
2016 value: string;
2117 [property: string]: mixed;
2218 };
2319
24-export type Next = null | Node | string;
25-
2620 // Converts JSON strings to/from your types
2721 // and asserts the results of JSON.parse at runtime
2822 function toTopLevel(json: string): TopLevel {
@@ -188,11 +182,7 @@ function r(name: string) {
188182
189183 const typeMap: any = {
190184 "TopLevel": o([
191- { json: "next", js: "next", typ: u(undefined, u(null, r("Node"), "")) },
192- { json: "value", js: "value", typ: "" },
193- ], "any"),
194- "Node": o([
195- { json: "next", js: "next", typ: u(undefined, u(null, r("Node"), "")) },
185+ { json: "next", js: "next", typ: u(undefined, u(null, r("TopLevel"), "")) },
196186 { json: "value", js: "value", typ: "" },
197187 ], "any"),
198188 };
Mschema-golangdefault / quicktype.go+6 −11
@@ -26,31 +26,26 @@ type TopLevel struct {
2626 Value string `json:"value"`
2727 }
2828
29-type Node struct {
30- Next *Next `json:"next"`
31- Value string `json:"value"`
32-}
33-
3429 type Next struct {
35- Node *Node
36- String *string
30+ String *string
31+ TopLevel *TopLevel
3732 }
3833
3934 func (x *Next) UnmarshalJSON(data []byte) error {
40- x.Node = nil
41- var c Node
35+ x.TopLevel = nil
36+ var c TopLevel
4237 object, err := unmarshalUnion(data, nil, nil, nil, &x.String, false, nil, true, &c, false, nil, false, nil, true)
4338 if err != nil {
4439 return err
4540 }
4641 if object {
47- x.Node = &c
42+ x.TopLevel = &c
4843 }
4944 return nil
5045 }
5146
5247 func (x *Next) MarshalJSON() ([]byte, error) {
53- return marshalUnion(nil, nil, nil, x.String, false, nil, x.Node != nil, x.Node, false, nil, false, nil, true)
48+ return marshalUnion(nil, nil, nil, x.String, false, nil, x.TopLevel != nil, x.TopLevel, false, nil, false, nil, true)
5449 }
5550
5651 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) {
Mschema-haskelldefault / QuickType.hs+16 −34
@@ -3,7 +3,6 @@
33
44 module QuickType
55 ( QuickType (..)
6- , Node (..)
76 , Next (..)
87 , decodeTopLevel
98 ) where
@@ -14,25 +13,30 @@ import Data.ByteString.Lazy (ByteString)
1413 import Data.HashMap.Strict (HashMap)
1514 import Data.Text (Text)
1615
16+data Next
17+ = NullInNext
18+ | QuickTypeInNext QuickType
19+ | StringInNext Text
20+ deriving (Show)
21+
1722 data QuickType = QuickType
1823 { nextQuickType :: Maybe Next
1924 , valueQuickType :: Text
2025 } deriving (Show)
2126
22-data Node = Node
23- { nextNode :: Maybe Next
24- , valueNode :: Text
25- } deriving (Show)
26-
27-data Next
28- = NodeInNext Node
29- | NullInNext
30- | StringInNext Text
31- deriving (Show)
32-
3327 decodeTopLevel :: ByteString -> Maybe QuickType
3428 decodeTopLevel = decode
3529
30+instance ToJSON Next where
31+ toJSON NullInNext = Null
32+ toJSON (QuickTypeInNext x) = toJSON x
33+ toJSON (StringInNext x) = toJSON x
34+
35+instance FromJSON Next where
36+ parseJSON Null = return NullInNext
37+ parseJSON xs@(Object _) = (fmap QuickTypeInNext . parseJSON) xs
38+ parseJSON xs@(String _) = (fmap StringInNext . parseJSON) xs
39+
3640 instance ToJSON QuickType where
3741 toJSON (QuickType nextQuickType valueQuickType) =
3842 object
@@ -44,25 +48,3 @@ instance FromJSON QuickType where
4448 parseJSON (Object v) = QuickType
4549 <$> v .:? "next"
4650 <*> v .: "value"
47-
48-instance ToJSON Node where
49- toJSON (Node nextNode valueNode) =
50- object
51- [ "next" .= nextNode
52- , "value" .= valueNode
53- ]
54-
55-instance FromJSON Node where
56- parseJSON (Object v) = Node
57- <$> v .:? "next"
58- <*> v .: "value"
59-
60-instance ToJSON Next where
61- toJSON (NodeInNext x) = toJSON x
62- toJSON NullInNext = Null
63- toJSON (StringInNext x) = toJSON x
64-
65-instance FromJSON Next where
66- parseJSON xs@(Object _) = (fmap NodeInNext . parseJSON) xs
67- parseJSON Null = return NullInNext
68- parseJSON xs@(String _) = (fmap StringInNext . parseJSON) xs
Mschema-java-datetime-legacydefault / src / main / java / io / quicktype / Next.java+4 −4
@@ -10,7 +10,7 @@ import com.fasterxml.jackson.core.type.*;
1010 @JsonDeserialize(using = Next.Deserializer.class)
1111 @JsonSerialize(using = Next.Serializer.class)
1212 public class Next {
13- public Node nodeValue;
13+ public TopLevel topLevelValue;
1414 public String stringValue;
1515
1616 static class Deserializer extends JsonDeserializer<Next> {
@@ -25,7 +25,7 @@ public class Next {
2525 value.stringValue = string;
2626 break;
2727 case START_OBJECT:
28- value.nodeValue = jsonParser.readValueAs(Node.class);
28+ value.topLevelValue = jsonParser.readValueAs(TopLevel.class);
2929 break;
3030 default: throw new IOException("Cannot deserialize Next");
3131 }
@@ -36,8 +36,8 @@ public class Next {
3636 static class Serializer extends JsonSerializer<Next> {
3737 @Override
3838 public void serialize(Next obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
39- if (obj.nodeValue != null) {
40- jsonGenerator.writeObject(obj.nodeValue);
39+ if (obj.topLevelValue != null) {
40+ jsonGenerator.writeObject(obj.topLevelValue);
4141 return;
4242 }
4343 if (obj.stringValue != null) {
Dschema-java-datetime-legacydefault / src / main / java / io / quicktype / Node.java+0 −18
@@ -1,18 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-
5-public class Node {
6- private Next next;
7- private String value;
8-
9- @JsonProperty("next")
10- public Next getNext() { return next; }
11- @JsonProperty("next")
12- public void setNext(Next value) { this.next = value; }
13-
14- @JsonProperty("value")
15- public String getValue() { return value; }
16- @JsonProperty("value")
17- public void setValue(String value) { this.value = value; }
18-}
Mschema-java-lombokdefault / src / main / java / io / quicktype / Next.java+4 −4
@@ -10,7 +10,7 @@ import com.fasterxml.jackson.core.type.*;
1010 @JsonDeserialize(using = Next.Deserializer.class)
1111 @JsonSerialize(using = Next.Serializer.class)
1212 public class Next {
13- public Node nodeValue;
13+ public TopLevel topLevelValue;
1414 public String stringValue;
1515
1616 static class Deserializer extends JsonDeserializer<Next> {
@@ -25,7 +25,7 @@ public class Next {
2525 value.stringValue = string;
2626 break;
2727 case START_OBJECT:
28- value.nodeValue = jsonParser.readValueAs(Node.class);
28+ value.topLevelValue = jsonParser.readValueAs(TopLevel.class);
2929 break;
3030 default: throw new IOException("Cannot deserialize Next");
3131 }
@@ -36,8 +36,8 @@ public class Next {
3636 static class Serializer extends JsonSerializer<Next> {
3737 @Override
3838 public void serialize(Next obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
39- if (obj.nodeValue != null) {
40- jsonGenerator.writeObject(obj.nodeValue);
39+ if (obj.topLevelValue != null) {
40+ jsonGenerator.writeObject(obj.topLevelValue);
4141 return;
4242 }
4343 if (obj.stringValue != null) {
Dschema-java-lombokdefault / src / main / java / io / quicktype / Node.java+0 −18
@@ -1,18 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-
5-public class Node {
6- private Next next;
7- private String value;
8-
9- @JsonProperty("next")
10- public Next getNext() { return next; }
11- @JsonProperty("next")
12- public void setNext(Next value) { this.next = value; }
13-
14- @JsonProperty("value")
15- public String getValue() { return value; }
16- @JsonProperty("value")
17- public void setValue(String value) { this.value = value; }
18-}
Mschema-javadefault / src / main / java / io / quicktype / Next.java+4 −4
@@ -10,7 +10,7 @@ import com.fasterxml.jackson.core.type.*;
1010 @JsonDeserialize(using = Next.Deserializer.class)
1111 @JsonSerialize(using = Next.Serializer.class)
1212 public class Next {
13- public Node nodeValue;
13+ public TopLevel topLevelValue;
1414 public String stringValue;
1515
1616 static class Deserializer extends JsonDeserializer<Next> {
@@ -25,7 +25,7 @@ public class Next {
2525 value.stringValue = string;
2626 break;
2727 case START_OBJECT:
28- value.nodeValue = jsonParser.readValueAs(Node.class);
28+ value.topLevelValue = jsonParser.readValueAs(TopLevel.class);
2929 break;
3030 default: throw new IOException("Cannot deserialize Next");
3131 }
@@ -36,8 +36,8 @@ public class Next {
3636 static class Serializer extends JsonSerializer<Next> {
3737 @Override
3838 public void serialize(Next obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
39- if (obj.nodeValue != null) {
40- jsonGenerator.writeObject(obj.nodeValue);
39+ if (obj.topLevelValue != null) {
40+ jsonGenerator.writeObject(obj.topLevelValue);
4141 return;
4242 }
4343 if (obj.stringValue != null) {
Dschema-javadefault / src / main / java / io / quicktype / Node.java+0 −18
@@ -1,18 +0,0 @@
1-package io.quicktype;
2-
3-import com.fasterxml.jackson.annotation.*;
4-
5-public class Node {
6- private Next next;
7- private String value;
8-
9- @JsonProperty("next")
10- public Next getNext() { return next; }
11- @JsonProperty("next")
12- public void setNext(Next value) { this.next = value; }
13-
14- @JsonProperty("value")
15- public String getValue() { return value; }
16- @JsonProperty("value")
17- public void setValue(String value) { this.value = value; }
18-}
Mschema-javascriptdefault / TopLevel.js+1 −5
@@ -172,11 +172,7 @@ function r(name) {
172172
173173 const typeMap = {
174174 "TopLevel": o([
175- { json: "next", js: "next", typ: u(undefined, u(null, r("Node"), "")) },
176- { json: "value", js: "value", typ: "" },
177- ], "any"),
178- "Node": o([
179- { json: "next", js: "next", typ: u(undefined, u(null, r("Node"), "")) },
175+ { json: "next", js: "next", typ: u(undefined, u(null, r("TopLevel"), "")) },
180176 { json: "value", js: "value", typ: "" },
181177 ], "any"),
182178 };
Mschema-kotlin-jacksondefault / TopLevel.kt+19 −26
@@ -30,43 +30,36 @@ val mapper = jacksonObjectMapper().apply {
3030 convert(Next::class, { Next.fromJson(it) }, { it.toJson() }, true)
3131 }
3232
33-data class TopLevel (
34- val next: Next? = null,
33+sealed class Next {
34+ class StringValue(val value: String) : Next()
35+ class TopLevelValue(val value: TopLevel) : Next()
36+ class NullValue() : Next()
3537
36- @get:JsonProperty(required=true)@field:JsonProperty(required=true)
37- val value: String
38-) {
39- fun toJson() = mapper.writeValueAsString(this)
38+ fun toJson(): String = mapper.writeValueAsString(when (this) {
39+ is StringValue -> this.value
40+ is TopLevelValue -> this.value
41+ is NullValue -> "null"
42+ })
4043
4144 companion object {
42- fun fromJson(json: String) = mapper.readValue<TopLevel>(json)
45+ fun fromJson(jn: JsonNode): Next = when (jn) {
46+ is TextNode -> StringValue(mapper.treeToValue(jn))
47+ is ObjectNode -> TopLevelValue(mapper.treeToValue(jn))
48+ null -> NullValue()
49+ else -> throw IllegalArgumentException()
50+ }
4351 }
4452 }
4553
46-data class Node (
54+data class TopLevel (
4755 val next: Next? = null,
4856
4957 @get:JsonProperty(required=true)@field:JsonProperty(required=true)
5058 val value: String
51-)
52-
53-sealed class Next {
54- class NodeValue(val value: Node) : Next()
55- class StringValue(val value: String) : Next()
56- class NullValue() : Next()
57-
58- fun toJson(): String = mapper.writeValueAsString(when (this) {
59- is NodeValue -> this.value
60- is StringValue -> this.value
61- is NullValue -> "null"
62- })
59+) {
60+ fun toJson() = mapper.writeValueAsString(this)
6361
6462 companion object {
65- fun fromJson(jn: JsonNode): Next = when (jn) {
66- is ObjectNode -> NodeValue(mapper.treeToValue(jn))
67- is TextNode -> StringValue(mapper.treeToValue(jn))
68- null -> NullValue()
69- else -> throw IllegalArgumentException()
70- }
63+ fun fromJson(json: String) = mapper.readValue<TopLevel>(json)
7164 }
7265 }
Mschema-kotlindefault / TopLevel.kt+18 −23
@@ -17,39 +17,34 @@ private fun <T> Klaxon.convert(k: kotlin.reflect.KClass<*>, fromJson: (JsonValue
1717 private val klaxon = Klaxon()
1818 .convert(Next::class, { Next.fromJson(it) }, { it.toJson() }, true)
1919
20-data class TopLevel (
21- val next: Next? = null,
22- val value: String
23-) {
24- public fun toJson() = klaxon.toJsonString(this)
25-
26- companion object {
27- public fun fromJson(json: String) = klaxon.parse<TopLevel>(json)
28- }
29-}
30-
31-data class Node (
32- val next: Next? = null,
33- val value: String
34-)
35-
3620 sealed class Next {
37- class NodeValue(val value: Node) : Next()
38- class StringValue(val value: String) : Next()
39- class NullValue() : Next()
21+ class StringValue(val value: String) : Next()
22+ class TopLevelValue(val value: TopLevel) : Next()
23+ class NullValue() : Next()
4024
4125 public fun toJson(): String = klaxon.toJsonString(when (this) {
42- is NodeValue -> this.value
43- is StringValue -> this.value
44- is NullValue -> "null"
26+ is StringValue -> this.value
27+ is TopLevelValue -> this.value
28+ is NullValue -> "null"
4529 })
4630
4731 companion object {
4832 public fun fromJson(jv: JsonValue): Next = when (jv.inside) {
49- is JsonObject -> NodeValue(jv.obj?.let { klaxon.parseFromJsonObject<Node>(it) }!!)
5033 is String -> StringValue(jv.string!!)
34+ is JsonObject -> TopLevelValue(jv.obj?.let { klaxon.parseFromJsonObject<TopLevel>(it) }!!)
5135 null -> NullValue()
5236 else -> throw IllegalArgumentException()
5337 }
5438 }
5539 }
40+
41+data class TopLevel (
42+ val next: Next? = null,
43+ val value: String
44+) {
45+ public fun toJson() = klaxon.toJsonString(this)
46+
47+ companion object {
48+ public fun fromJson(json: String) = klaxon.parse<TopLevel>(json)
49+ }
50+}
Mschema-phpdefault / TopLevel.php+15 −196
@@ -4,14 +4,14 @@ declare(strict_types=1);
44 // This is an autogenerated file:TopLevel
55
66 class TopLevel {
7- private Node|string|null $next; // json:next Optional
7+ private TopLevel|string|null $next; // json:next Optional
88 private string $value; // json:value Required
99
1010 /**
11- * @param Node|string|null $next
11+ * @param TopLevel|string|null $next
1212 * @param string $value
1313 */
14- public function __construct(Node|string|null $next, string $value) {
14+ public function __construct(TopLevel|string|null $next, string $value) {
1515 $this->next = $next;
1616 $this->value = $value;
1717 }
@@ -19,13 +19,13 @@ class TopLevel {
1919 /**
2020 * @param stdClass|string|null $value
2121 * @throws Exception
22- * @return Node|string|null
22+ * @return TopLevel|string|null
2323 */
24- public static function fromNext(stdClass|string|null $value): Node|string|null {
24+ public static function fromNext(stdClass|string|null $value): TopLevel|string|null {
2525 if (is_null($value)) {
2626 return $value; /*null*/
2727 } elseif (is_object($value)) {
28- return Node::from($value); /*class*/
28+ return TopLevel::from($value); /*class*/
2929 } elseif (is_string($value)) {
3030 return $value; /*string*/
3131 } else {
@@ -41,7 +41,7 @@ class TopLevel {
4141 if (TopLevel::validateNext($this->next)) {
4242 if (is_null($this->next)) {
4343 return $this->next; /*null*/
44- } elseif ($this->next instanceof Node) {
44+ } elseif ($this->next instanceof TopLevel) {
4545 return $this->next->to(); /*class*/
4646 } elseif (is_string($this->next)) {
4747 return $this->next; /*string*/
@@ -53,16 +53,16 @@ class TopLevel {
5353 }
5454
5555 /**
56- * @param Node|string|null
56+ * @param TopLevel|string|null
5757 * @return bool
5858 * @throws Exception
5959 */
60- public static function validateNext(Node|string|null $value): bool {
60+ public static function validateNext(TopLevel|string|null $value): bool {
6161 if (is_null($value)) {
6262 if (!is_null($value)) {
6363 throw new Exception("Attribute Error:TopLevel::next");
6464 }
65- } elseif ($value instanceof Node) {
65+ } elseif ($value instanceof TopLevel) {
6666 $value->validate();
6767 } elseif (is_string($value)) {
6868 if (!is_string($value)) {
@@ -76,9 +76,9 @@ class TopLevel {
7676
7777 /**
7878 * @throws Exception
79- * @return Node|string|null
79+ * @return TopLevel|string|null
8080 */
81- public function getNext(): Node|string|null {
81+ public function getNext(): TopLevel|string|null {
8282 if (TopLevel::validateNext($this->next)) {
8383 return $this->next;
8484 }
@@ -86,10 +86,10 @@ class TopLevel {
8686 }
8787
8888 /**
89- * @return Node|string|null
89+ * @return TopLevel|string|null
9090 */
91- public static function sampleNext(): Node|string|null {
92- return Node::sample(); /*31:next*/
91+ public static function sampleNext(): TopLevel|string|null {
92+ return TopLevel::sample(); /*31:next*/
9393 }
9494
9595 /**
@@ -181,184 +181,3 @@ class TopLevel {
181181 );
182182 }
183183 }
184-
185-// This is an autogenerated file:Node
186-
187-class Node {
188- private Node|string|null $next; // json:next Optional
189- private string $value; // json:value Required
190-
191- /**
192- * @param Node|string|null $next
193- * @param string $value
194- */
195- public function __construct(Node|string|null $next, string $value) {
196- $this->next = $next;
197- $this->value = $value;
198- }
199-
200- /**
201- * @param stdClass|string|null $value
202- * @throws Exception
203- * @return Node|string|null
204- */
205- public static function fromNext(stdClass|string|null $value): Node|string|null {
206- if (is_null($value)) {
207- return $value; /*null*/
208- } elseif (is_object($value)) {
209- return Node::from($value); /*class*/
210- } elseif (is_string($value)) {
211- return $value; /*string*/
212- } else {
213- throw new Exception('Cannot deserialize union value in Node');
214- }
215- }
216-
217- /**
218- * @throws Exception
219- * @return stdClass|string|null
220- */
221- public function toNext(): stdClass|string|null {
222- if (Node::validateNext($this->next)) {
223- if (is_null($this->next)) {
224- return $this->next; /*null*/
225- } elseif ($this->next instanceof Node) {
226- return $this->next->to(); /*class*/
227- } elseif (is_string($this->next)) {
228- return $this->next; /*string*/
229- } else {
230- throw new Exception('Union value has no matching member in Node');
231- }
232- }
233- throw new Exception('never get to this Node::next');
234- }
235-
236- /**
237- * @param Node|string|null
238- * @return bool
239- * @throws Exception
240- */
241- public static function validateNext(Node|string|null $value): bool {
242- if (is_null($value)) {
243- if (!is_null($value)) {
244- throw new Exception("Attribute Error:Node::next");
245- }
246- } elseif ($value instanceof Node) {
247- $value->validate();
248- } elseif (is_string($value)) {
249- if (!is_string($value)) {
250- throw new Exception("Attribute Error:Node::next");
251- }
252- } else {
253- throw new Exception("Attribute Error:Node::next");
254- }
255- return true;
256- }
257-
258- /**
259- * @throws Exception
260- * @return Node|string|null
261- */
262- public function getNext(): Node|string|null {
263- if (Node::validateNext($this->next)) {
264- return $this->next;
265- }
266- throw new Exception('never get to getNext Node::next');
267- }
268-
269- /**
270- * @return Node|string|null
271- */
272- public static function sampleNext(): Node|string|null {
273- return Node::sample(); /*31:next*/
274- }
275-
276- /**
277- * @param string $value
278- * @throws Exception
279- * @return string
280- */
281- public static function fromValue(string $value): string {
282- return $value; /*string*/
283- }
284-
285- /**
286- * @throws Exception
287- * @return string
288- */
289- public function toValue(): string {
290- if (Node::validateValue($this->value)) {
291- return $this->value; /*string*/
292- }
293- throw new Exception('never get to this Node::value');
294- }
295-
296- /**
297- * @param string
298- * @return bool
299- * @throws Exception
300- */
301- public static function validateValue(string $value): bool {
302- return true;
303- }
304-
305- /**
306- * @throws Exception
307- * @return string
308- */
309- public function getValue(): string {
310- if (Node::validateValue($this->value)) {
311- return $this->value;
312- }
313- throw new Exception('never get to getValue Node::value');
314- }
315-
316- /**
317- * @return string
318- */
319- public static function sampleValue(): string {
320- return 'Node::value::32'; /*32:value*/
321- }
322-
323- /**
324- * @throws Exception
325- * @return bool
326- */
327- public function validate(): bool {
328- return Node::validateNext($this->next)
329- || Node::validateValue($this->value);
330- }
331-
332- /**
333- * @return stdClass
334- * @throws Exception
335- */
336- public function to(): stdClass {
337- $out = new stdClass();
338- $out->{'next'} = $this->toNext();
339- $out->{'value'} = $this->toValue();
340- return $out;
341- }
342-
343- /**
344- * @param stdClass $obj
345- * @return Node
346- * @throws Exception
347- */
348- public static function from(stdClass $obj): Node {
349- return new Node(
350- Node::fromNext($obj->{'next'})
351- ,Node::fromValue($obj->{'value'})
352- );
353- }
354-
355- /**
356- * @return Node
357- */
358- public static function sample(): Node {
359- return new Node(
360- Node::sampleNext()
361- ,Node::sampleValue()
362- );
363- }
364-}
Mschema-pikedefault / TopLevel.pmod+6 −29
@@ -12,30 +12,13 @@
1212 // and will likely throw an error, if the JSON string does not
1313 // match the expected interface, even if the JSON itself is valid.
1414
15-class TopLevel {
16- Next next; // json: "next"
17- string value; // json: "value"
18-
19- string encode_json() {
20- mapping(string:mixed) json = ([
21- "next" : next,
22- "value" : value,
23- ]);
24-
25- return Standards.JSON.encode(json);
26- }
27-}
28-
29-TopLevel TopLevel_from_JSON(mixed json) {
30- TopLevel retval = TopLevel();
31-
32- retval.next = json["next"];
33- retval.value = json["value"];
15+typedef string|TopLevel Next;
3416
35- return retval;
17+Next Next_from_JSON(mixed json) {
18+ return json;
3619 }
3720
38-class Node {
21+class TopLevel {
3922 Next next; // json: "next"
4023 string value; // json: "value"
4124
@@ -49,17 +32,11 @@ class Node {
4932 }
5033 }
5134
52-Node Node_from_JSON(mixed json) {
53- Node retval = Node();
35+TopLevel TopLevel_from_JSON(mixed json) {
36+ TopLevel retval = TopLevel();
5437
5538 retval.next = json["next"];
5639 retval.value = json["value"];
5740
5841 return retval;
5942 }
60-
61-typedef Node|string Next;
62-
63-Next Next_from_JSON(mixed json) {
64- return json;
65-}
Mschema-pythondefault / quicktype.py+3 −23
@@ -29,43 +29,23 @@ def to_class(c: Type[T], x: Any) -> dict:
2929 return cast(Any, x).to_dict()
3030
3131
32-@dataclass
33-class Node:
34- value: str
35- next: 'Node | str | None' = None
36-
37- @staticmethod
38- def from_dict(obj: Any) -> 'Node':
39- assert isinstance(obj, dict)
40- value = from_str(obj.get("value"))
41- next = from_union([Node.from_dict, from_none, from_str], obj.get("next"))
42- return Node(value, next)
43-
44- def to_dict(self) -> dict:
45- result: dict = {}
46- result["value"] = from_str(self.value)
47- if self.next is not None:
48- result["next"] = from_union([lambda x: to_class(Node, x), from_none, from_str], self.next)
49- return result
50-
51-
5232 @dataclass
5333 class TopLevel:
5434 value: str
55- next: Node | str | None = None
35+ next: 'TopLevel | str | None' = None
5636
5737 @staticmethod
5838 def from_dict(obj: Any) -> 'TopLevel':
5939 assert isinstance(obj, dict)
6040 value = from_str(obj.get("value"))
61- next = from_union([Node.from_dict, from_none, from_str], obj.get("next"))
41+ next = from_union([TopLevel.from_dict, from_none, from_str], obj.get("next"))
6242 return TopLevel(value, next)
6343
6444 def to_dict(self) -> dict:
6545 result: dict = {}
6646 result["value"] = from_str(self.value)
6747 if self.next is not None:
68- result["next"] = from_union([lambda x: to_class(Node, x), from_none, from_str], self.next)
48+ result["next"] = from_union([lambda x: to_class(TopLevel, x), from_none, from_str], self.next)
6949 return result
Mschema-rubydefault / TopLevel.rb+16 −44
@@ -21,26 +21,26 @@ module Types
2121 end
2222
2323 # (forward declaration)
24-class Node < Dry::Struct; end
24+class TopLevel < Dry::Struct; end
2525
2626 class Next < Dry::Struct
27- attribute :node, Node.optional
28- attribute :null, Types::Nil.optional
29- attribute :string, Types::String.optional
27+ attribute :null, Types::Nil.optional
28+ attribute :string, Types::String.optional
29+ attribute :top_level, TopLevel.optional
3030
3131 def self.from_dynamic!(d)
32- begin
33- value = Node.from_dynamic!(d)
34- if schema[:node].right.valid? value
35- return new(node: value, null: nil, string: nil)
36- end
37- rescue
38- end
3932 if schema[:null].right.valid? d
40- return new(null: d, node: nil, string: nil)
33+ return new(null: d, top_level: nil, string: nil)
4134 end
4235 if schema[:string].right.valid? d
43- return new(string: d, node: nil, null: nil)
36+ return new(string: d, top_level: nil, null: nil)
37+ end
38+ begin
39+ value = TopLevel.from_dynamic!(d)
40+ if schema[:top_level].right.valid? value
41+ return new(top_level: value, null: nil, string: nil)
42+ end
43+ rescue
4444 end
4545 raise "Invalid union"
4646 end
@@ -50,10 +50,10 @@ class Next < Dry::Struct
5050 end
5151
5252 def to_dynamic
53- if node != nil
54- node.to_dynamic
55- elsif string != nil
53+ if string != nil
5654 string
55+ elsif top_level != nil
56+ top_level.to_dynamic
5757 else
5858 nil
5959 end
@@ -64,34 +64,6 @@ class Next < Dry::Struct
6464 end
6565 end
6666
67-class Node < Dry::Struct
68- attribute :node_next, Types.Instance(Next).optional
69- attribute :value, Types::String
70-
71- def self.from_dynamic!(d)
72- d = Types::Hash[d]
73- new(
74- node_next: d["next"] ? Next.from_dynamic!(d["next"]) : nil,
75- value: d.fetch("value"),
76- )
77- end
78-
79- def self.from_json!(json)
80- from_dynamic!(JSON.parse(json))
81- end
82-
83- def to_dynamic
84- {
85- "next" => node_next&.to_dynamic,
86- "value" => value,
87- }
88- end
89-
90- def to_json(options = nil)
91- JSON.generate(to_dynamic, options)
92- end
93-end
94-
9567 class TopLevel < Dry::Struct
9668 attribute :top_level_next, Types.Instance(Next).optional
9769 attribute :value, Types::String
Mschema-rustdefault / module_under_test.rs+6 −13
@@ -14,23 +14,16 @@
1414 use serde::{Serialize, Deserialize};
1515
1616 #[derive(Debug, Clone, Serialize, Deserialize)]
17-pub struct TopLevel {
18- pub next: Option<Box<Next>>,
17+#[serde(untagged)]
18+pub enum Next {
19+ PurpleString(String),
1920
20- pub value: String,
21+ TopLevel(Box<TopLevel>),
2122 }
2223
2324 #[derive(Debug, Clone, Serialize, Deserialize)]
24-pub struct Node {
25- pub next: Option<Box<Next>>,
25+pub struct TopLevel {
26+ pub next: Option<Next>,
2627
2728 pub value: String,
2829 }
29-
30-#[derive(Debug, Clone, Serialize, Deserialize)]
31-#[serde(untagged)]
32-pub enum Next {
33- Node(Node),
34-
35- PurpleString(String),
36-}
Mschema-scala3-upickledefault / TopLevel.scala+8 −13
@@ -65,26 +65,21 @@ object JsonExt:
6565 end JsonExt
6666
6767
68-case class TopLevel (
69- val next : Option[Next] = None,
70- val value : String
71-) derives OptionPickler.ReadWriter
72-
73-case class Node (
74- val next : Option[Next] = None,
75- val value : String
76-) derives OptionPickler.ReadWriter
77-
78-type Next = Node | String | NullValue
68+type Next = String | TopLevel | NullValue
7969 given unionReaderNext: OptionPickler.Reader[Next] = JsonExt.badMerge[Next](
8070 JsonExt.strictString,
81- summon[OptionPickler.Reader[Node]],
71+ summon[OptionPickler.Reader[TopLevel]],
8272 summon[OptionPickler.Reader[NullValue]],
8373 )
8474
8575 given unionWriterNext: OptionPickler.Writer[Next] = OptionPickler.writer[ujson.Value].comap[Next]{ _v =>
8676 (_v: @unchecked) match
8777 case v: String => OptionPickler.writeJs[String](v)
88- case v: Node => OptionPickler.writeJs[Node](v)
78+ case v: TopLevel => OptionPickler.writeJs[TopLevel](v)
8979 case v: NullValue => OptionPickler.writeJs[NullValue](v)
9080 }
81+
82+case class TopLevel (
83+ val next : Option[Next] = None,
84+ val value : String
85+) derives OptionPickler.ReadWriter
Mschema-scala3default / TopLevel.scala+8 −13
@@ -7,27 +7,22 @@ import cats.syntax.functor._
77 // If a union has a null in, then we'll need this too...
88 type NullValue = None.type
99
10-case class TopLevel (
11- val next : Option[Next] = None,
12- val value : String
13-) derives Encoder.AsObject, Decoder
14-
15-case class Node (
16- val next : Option[Next] = None,
17- val value : String
18-) derives Encoder.AsObject, Decoder
19-
20-type Next = Node | String | NullValue
10+type Next = String | TopLevel | NullValue
2111 given Decoder[Next] = {
2212 List[Decoder[Next]](
2313 Decoder[String].widen,
24- Decoder[Node].widen,
14+ Decoder[TopLevel].widen,
2515 Decoder[NullValue].widen,
2616 ).reduceLeft(_ or _)
2717 }
2818
2919 given Encoder[Next] = Encoder.instance {
3020 case enc0 : String => Encoder.encodeString(enc0)
31- case enc1 : Node => Encoder.AsObject[Node].apply(enc1)
21+ case enc1 : TopLevel => Encoder.AsObject[TopLevel].apply(enc1)
3222 case enc2 : NullValue => Encoder.encodeNone(enc2)
3323 }
24+
25+case class TopLevel (
26+ val next : Option[Next] = None,
27+ val value : String
28+) derives Encoder.AsObject, Decoder
Mschema-schemadefault / TopLevel.schema+1 −17
@@ -18,29 +18,13 @@
1818 ],
1919 "title": "TopLevel"
2020 },
21- "Node": {
22- "type": "object",
23- "additionalProperties": {},
24- "properties": {
25- "next": {
26- "$ref": "#/definitions/Next"
27- },
28- "value": {
29- "type": "string"
30- }
31- },
32- "required": [
33- "value"
34- ],
35- "title": "Node"
36- },
3721 "Next": {
3822 "anyOf": [
3923 {
4024 "type": "null"
4125 },
4226 {
43- "$ref": "#/definitions/Node"
27+ "$ref": "#/definitions/TopLevel"
4428 },
4529 {
4630 "type": "string"
Mschema-swiftdefault / quicktype.swift+44 −86
@@ -5,56 +5,43 @@
55
66 import Foundation
77
8-// MARK: - TopLevel
9-struct TopLevel: Codable {
10- let next: Next?
11- let value: String
12-
13- enum CodingKeys: String, CodingKey {
14- case next = "next"
15- case value = "value"
16- }
17-}
18-
19-// MARK: TopLevel convenience initializers and mutators
20-
21-extension TopLevel {
22- init(data: Data) throws {
23- self = try newJSONDecoder().decode(TopLevel.self, from: data)
24- }
8+enum Next: Codable {
9+ case string(String)
10+ case topLevel(TopLevel)
11+ case null
2512
26- init(_ json: String, using encoding: String.Encoding = .utf8) throws {
27- guard let data = json.data(using: encoding) else {
28- throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
13+ init(from decoder: Decoder) throws {
14+ let container = try decoder.singleValueContainer()
15+ if let x = try? container.decode(String.self) {
16+ self = .string(x)
17+ return
2918 }
30- try self.init(data: data)
31- }
32-
33- init(fromURL url: URL) throws {
34- try self.init(data: try Data(contentsOf: url))
35- }
36-
37- func with(
38- next: Next?? = nil,
39- value: String? = nil
40- ) -> TopLevel {
41- return TopLevel(
42- next: next ?? self.next,
43- value: value ?? self.value
44- )
45- }
46-
47- func jsonData() throws -> Data {
48- return try newJSONEncoder().encode(self)
19+ if let x = try? container.decode(TopLevel.self) {
20+ self = .topLevel(x)
21+ return
22+ }
23+ if container.decodeNil() {
24+ self = .null
25+ return
26+ }
27+ throw DecodingError.typeMismatch(Next.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for Next"))
4928 }
5029
51- func jsonString(encoding: String.Encoding = .utf8) throws -> String? {
52- return String(data: try self.jsonData(), encoding: encoding)
30+ func encode(to encoder: Encoder) throws {
31+ var container = encoder.singleValueContainer()
32+ switch self {
33+ case .string(let x):
34+ try container.encode(x)
35+ case .topLevel(let x):
36+ try container.encode(x)
37+ case .null:
38+ try container.encodeNil()
39+ }
5340 }
5441 }
5542
56-// MARK: - Node
57-struct Node: Codable {
43+// MARK: - TopLevel
44+class TopLevel: Codable {
5845 let next: Next?
5946 let value: String
6047
@@ -62,31 +49,37 @@ struct Node: Codable {
6249 case next = "next"
6350 case value = "value"
6451 }
52+
53+ init(next: Next?, value: String) {
54+ self.next = next
55+ self.value = value
56+ }
6557 }
6658
67-// MARK: Node convenience initializers and mutators
59+// MARK: TopLevel convenience initializers and mutators
6860
69-extension Node {
70- init(data: Data) throws {
71- self = try newJSONDecoder().decode(Node.self, from: data)
61+extension TopLevel {
62+ convenience init(data: Data) throws {
63+ let me = try newJSONDecoder().decode(TopLevel.self, from: data)
64+ self.init(next: me.next, value: me.value)
7265 }
7366
74- init(_ json: String, using encoding: String.Encoding = .utf8) throws {
67+ convenience init(_ json: String, using encoding: String.Encoding = .utf8) throws {
7568 guard let data = json.data(using: encoding) else {
7669 throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
7770 }
7871 try self.init(data: data)
7972 }
8073
81- init(fromURL url: URL) throws {
74+ convenience init(fromURL url: URL) throws {
8275 try self.init(data: try Data(contentsOf: url))
8376 }
8477
8578 func with(
8679 next: Next?? = nil,
8780 value: String? = nil
88- ) -> Node {
89- return Node(
81+ ) -> TopLevel {
82+ return TopLevel(
9083 next: next ?? self.next,
9184 value: value ?? self.value
9285 )
@@ -101,41 +94,6 @@ extension Node {
10194 }
10295 }
10396
104-indirect enum Next: Codable {
105- case node(Node)
106- case string(String)
107- case null
108-
109- init(from decoder: Decoder) throws {
110- let container = try decoder.singleValueContainer()
111- if let x = try? container.decode(String.self) {
112- self = .string(x)
113- return
114- }
115- if let x = try? container.decode(Node.self) {
116- self = .node(x)
117- return
118- }
119- if container.decodeNil() {
120- self = .null
121- return
122- }
123- throw DecodingError.typeMismatch(Next.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for Next"))
124- }
125-
126- func encode(to encoder: Encoder) throws {
127- var container = encoder.singleValueContainer()
128- switch self {
129- case .node(let x):
130- try container.encode(x)
131- case .string(let x):
132- try container.encode(x)
133- case .null:
134- try container.encodeNil()
135- }
136- }
137-}
138-
13997 // MARK: - Helper functions for creating encoders and decoders
14098
14199 func newJSONDecoder() -> JSONDecoder {
Mschema-typescript-zoddefault / TopLevel.ts+4 −10
@@ -1,19 +1,13 @@
11 import * as z from "zod";
22
33
4-export type Node = {
5- "next"?: Node | null | string;
4+export type TopLevel = {
5+ "next"?: TopLevel | null | string;
66 "value": string;
77 };
8-export const NodeSchema: z.ZodType<Node> = z.lazy(() =>
8+export const TopLevelSchema: z.ZodType<TopLevel> = z.lazy(() =>
99 z.object({
10- "next": z.union([z.null(), NodeSchema, z.string()]).optional(),
10+ "next": z.union([z.null(), TopLevelSchema, z.string()]).optional(),
1111 "value": z.string(),
1212 })
1313 );
14-
15-export const TopLevelSchema = z.object({
16- "next": z.union([z.null(), NodeSchema, z.string()]).optional(),
17- "value": z.string(),
18-});
19-export type TopLevel = z.infer<typeof TopLevelSchema>;
Mschema-typescriptdefault / TopLevel.ts+3 −13
@@ -7,20 +7,14 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
11- next?: Next;
12- value: string;
13- [property: string]: unknown;
14-}
10+export type Next = null | TopLevel | string;
1511
16-export interface Node {
12+export interface TopLevel {
1713 next?: Next;
1814 value: string;
1915 [property: string]: unknown;
2016 }
2117
22-export type Next = null | Node | string;
23-
2418 // Converts JSON strings to/from your types
2519 // and asserts the results of JSON.parse at runtime
2620 export class Convert {
@@ -188,11 +182,7 @@ function r(name: string) {
188182
189183 const typeMap: any = {
190184 "TopLevel": o([
191- { json: "next", js: "next", typ: u(undefined, u(null, r("Node"), "")) },
192- { json: "value", js: "value", typ: "" },
193- ], "any"),
194- "Node": o([
195- { json: "next", js: "next", typ: u(undefined, u(null, r("Node"), "")) },
185+ { json: "next", js: "next", typ: u(undefined, u(null, r("TopLevel"), "")) },
196186 { json: "value", js: "value", typ: "" },
197187 ], "any"),
198188 };
No generated files match these filters.