cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Problem with `items: $ref:` for array model. #4

Closed gilsdav closed 5 years ago

gilsdav commented 5 years ago

Source

https://gist.githubusercontent.com/kinlane/43934f44fd591a6ee59a45267d9e3066/raw/47f6d7115dd17749c408c55861638ffc22d995f4/sample-openapi-30.yaml

Expected

pets.ts :

/* tslint:disable */
import { Pet } from './pet';
export type Pets = Pet[];

Got

pets.ts :

/* tslint:disable */
import { Pet } from './pet';
export type Pets = ; <--- missing value
gilsdav commented 5 years ago

@luisfpg As you can see in https://www.w3schools.com/js/js_arrays.asp Array is deprecated, can you use export type Pets = Pet[]; instead of export type Pets = Array<Pet>; ? Thank you

luisfpg commented 5 years ago

@gilsdav Why? Actually, that page says to avoid the Array constructor. But as a TypeScript type definition, Array<string> and string[] are the same. Quoted from https://www.typescriptlang.org/docs/handbook/basic-types.html:

TypeScript, like JavaScript, allows you to work with arrays of values. Array types can be written in one of two ways. In the first, you use the type of the elements followed by [] to denote an array of that element type: let list: number[] = [1, 2, 3]; The second way uses a generic array type, Array: let list: Array<number> = [1, 2, 3];

Note that neither use new Array.

gilsdav commented 5 years ago

@luisfpg You are right but I think it can be confusing because this javascript type exist just like String. But in that case String is deferent than string. This is why I never use Array. What do you think about ?