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
68 stars 13 forks source link

Use Guid for format:uuid in C# #38

Closed codertimu closed 2 years ago

codertimu commented 2 years ago

It would be nice if the generator would produce Guid for the format:uuid type instead of string. Example:

Order:
  type: object
  properties:
    order_id:
      type: string
      nullable: true
    order_uuid:
      type: string
      format: uuid
      nullable: true
    created_date:
      type: string
      format: date-time
      nullable: true
public class Order
{
    [System.Text.Json.Serialization.JsonPropertyName("order_id")]
    public string OrderId { get; set; }

    [System.Text.Json.Serialization.JsonPropertyName("order_uuid")]
    public string OrderUuid { get; set; } // the type should be Guid

    [System.Text.Json.Serialization.JsonPropertyName("created_date")]
    public System.DateTimeOffset? CreatedDate { get; set; }
}
zijianhuang commented 2 years ago

According to https://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid, such mapping is better to be an option, since the other end may not actually use GUID. How about UuidToGuid?

codertimu commented 2 years ago

Made it optional

zijianhuang commented 2 years ago

Merged with the master branch. And next time when making similar changes, please make a variant of OpenApi definition file for new test cases, otherwise, some existing test cases using the same file but changed are broken.

codertimu commented 2 years ago

Merged with the master branch. And next time when making similar changes, please make a variant of OpenApi definition file for new test cases, otherwise, some existing test cases using the same file but changed are broken.

I'll keep that in mind. thanks.