glideapps / glideapps/quicktype

Typescript doesn't generate correct types when root element is an array of objects

Open
#1,309 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

When using this JSON Schema as a source:
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "pr.json",
"$ref": "#/definitions/GetResp",
"definitions": {
"GetResp": {
"title": "GetResp",
"type": "array",
"items": {
"$ref": "#/definitions/SomeObject"
}
},
"SomeObject": {
"title": "SomeObject",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
}
}
}
```

When I generate Golang types, I get expected result:

```go
type GetResp []SomeObject

type SomeObject struct {
Name string `json:"name"`
}
```

While TypeScript output is:

```typescript
export interface GetResp {
name: string;
}
```

I expect it to generate:

```typescript
export interface SomeObject {
name: string;
}

export type GetResp = SomeObject[]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.