acacode / acacode/swagger-typescript-api

Option for handle object without $ref (nested objects)

Aberta
#639 1 comentário 2 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
4.1k
Forks
436
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

When generating the client, we pass the swagger. A swagger can include complex objects. Such objects usually have nested objects. So, if we want to access this nested object from code, then we can only get it if it is described inside the swagger using "$ref".
Example object in schema (without $ref)
```json
"work_day": {
"type": "object",
"description": "Workday state",
"properties": {
"uuid": {
"type": "string",
"description": "Workday uuid",
"example": "6e8242b9-adea-4d0a-ba74-07dc2cf6f459"
}
}
}
```

We generate some schema and result is:

```typescript
export interface Generated {
name?: string;
work_day?: {
uuid?: string;
};
}
```

But now, let use $ref inside our schema

```json
"work_day": {
"schema": {
"$ref": "#/components/schemas/Workday"
}
}
```

Result in TypeScript:

```typescript

export interface Generated {
name?: string;
work_day?: GeneratedWorkDay;
}

export interface GeneratedWorkDay {
uuid?: string;
}
```

It is possible to handle object without $ref?

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.