-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Issue Type
Quicktype's output when given a JSON schema for a recursive object (for example, a tree node) includes additional output where the type that's recursive is duplicated, which can result in huge redundant outputs.
Context (Environment, Version, Language)
Input Format: JSON schema
Output Language: C# and TypeScript tested, but seems to be present in all of them
app.quicktype.io
Description
I have a type that represents a tree node which I have a JSON schema for using $ref
. However when Quicktype generated C# code, it ended up generating significant amounts of redundant code - because the tree node contains many complex types in the "data" field, all of these types ended up being duplicated with prefixes such as "Fluffy" or "Purple".
Input Data
This is a minimal example of a tree node with just an ID:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "T2",
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"children": {
"type": "array",
"items": {
"$ref": "T2"
}
}
}
}
Expected Behaviour / Output
C#
public partial class Tree
{
public Tree[] Children { get; set; }
public TreeData Data { get; set; }
}
public partial class TreeData
{
public string Id { get; set; }
}
TypeScript
export interface Tree {
children?: Tree[];
data?: TreeData;
}
export interface TreeData {
id?: string;
}
Current Behaviour / Output
C#
public partial class Tree
{
public Tre[] Children { get; set; }
public TreeData Data { get; set; }
}
public partial class Tre
{
public Tre[] Children { get; set; }
public ChildData Data { get; set; }
}
public partial class ChildData
{
public string Id { get; set; }
}
public partial class TreeData
{
public string Id { get; set; }
}
TypeScript
export interface Tree {
children?: Tre[];
data?: TreeData;
[property: string]: any;
}
export interface Tre {
children?: Tre[];
data?: ChildData;
[property: string]: any;
}
export interface ChildData {
id?: string;
[property: string]: any;
}
export interface TreeData {
id?: string;
[property: string]: any;
}