glideapps / glideapps/quicktype
Duplicate types when using several schemas and references
- Dominant language
- TypeScript
- Stars
- 13.9k
- Forks
- 1.2k
- Avg merge
- 8h 53m
- Merged PRs (30d)
- 369
Description
I'm currently trying to generate interfaces for several schema files, that reference each other. By doing that, the parser duplicates some interfaces, which leads to dead interfaces in typescript.
I produced a quick example to demonstrate the problem:
a.json
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/schemas/a",
"type": "object",
"title": "A",
"properties": {
"name": {
"type": "string"
},
"in": {
"type": "array",
"items": {
"$ref": "/schemas/c"
}
}
},
"required": ["name", "in"]
}
```
b.json
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/schemas/b",
"type": "object",
"title": "B",
"properties": {
"name": {
"type": "string"
},
"out": {
"type": "array",
"items": {
"$ref": "/schemas/c"
}
}
},
"required": ["name", "out"]
}
```
c.json
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/schemas/c",
"type": "object",
"title": "C",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
}
```
Compiling these schemas with the following command:
```
quicktype --src-lang schema --out test.ts --just-types .\a.json .\b.json .\c.json
```
Results in the following typescript file:
```typescript
export interface A {
in: InElement[];
name: string;
}
export interface InElement {
name: string;
}
export interface B {
name: string;
out: InElement[];
}
export interface C {
name: string;
}
```
I would have expected the following file:
```typescript
export interface A {
in: C[];
name: string;
}
export interface B {
name: string;
out: C[];
}
export interface C {
name: string;
}
```
Am I doing something wrong, or is there something else I'm forgetting?
Contributor guide
Assessment
This issue has not been assessed yet.