zijianhuang / openapiclientgen

Generate strongly typed C# and TypeScript client codes from Open API / Swagger definitions supporting jQuery, Angular, AXIOS, Fetch API, Aurelia and Angular Strictly Typed Forms
MIT License
64 stars 13 forks source link

Fix ArrayAs for arrayRank = 1 #33

Closed Kim-SSi closed 3 years ago

Kim-SSi commented 3 years ago

ArrayAs setting was being ignored for arrayRank = 1.

zijianhuang commented 3 years ago

manually merged.

zijianhuang commented 3 years ago

v1.10.1 released.

Kim-SSi commented 3 years ago

It might be worth setting the ArrayAsIEnumerableDerived enum values explicitly. That would make it easier to figure out what we should set ArrayAs to like ActionNameStrategy.

zijianhuang commented 3 years ago

Array is preferred as the default, since this looks more consistent with what in TS codes. Though Microsoft recommends IEnumerable in general , however, in data serialization with DTO on the client side, IEnumerable does not seem to provide advantage over array.

ArrayAs

/// <summary>
/// By default, array type will be array in generated C#. You may generated IEnumerable and some of its derived types.
/// </summary>
public ArrayAsIEnumerableDerived ArrayAs { get; set; }
    public enum ArrayAsIEnumerableDerived
    {
        Array,

        IEnumerable,
        IList,
        ICollection,
        IReadOnlyList,
        IReadOnlyCollection,

        List,
        Collection,
        ReadOnlyCollection,
    }

Microsoft best practices often recommend using IEnumerable. The preference of using Array in OpenApiClientGen and WebApiClientGen is more in line with what could be possibly generated for TypeScript. Depending on your own contexts, you may choose other forms of data collection.

Kim-SSi commented 3 years ago

Sorry that I was not clear enough. I meant explicitly setting the enum values. That way any additional values added in the future do no easily alter the value use in the setting.json.

    public enum ArrayAsIEnumerableDerived
    {
        Array = 0,

        IEnumerable = 1,
        IList = 2,
        ICollection = 3,
        IReadOnlyList = 4,
        IReadOnlyCollection = 5,

        List = 6,
        Collection = 7,
        ReadOnlyCollection = 8,
    }
zijianhuang commented 3 years ago

I see. Thanks. Fixed that and the other one.