swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

BigInt type for format: int64 types in swagger

Open mr-tron opened this issue 1 year ago • 1 comments

Can I make (maybe using --custom or --templates) with this generator types BigInt for and only for

type: integer
format: int64

? For example i have structure

pet:
  type: object
  properties:
    age:
      type: integer
    unique_big_id:
      type: integer
      format: int64

Can i get generated type

export interface Pet {
  age: number;
  unique_big_id: BigInt;
}

and marshal response from response from server { "unique_big_id" : 9223372036854775807, "age": 123 } to Pet without losing precision to 9223372036854775000?

mr-tron avatar Feb 29 '24 11:02 mr-tron

I was able to generate integer types with format int64 to bigint using the generateApi method:

generateApi({
  // ...
  codeGenConstructs: (struct) => ({
    Keyword: {
      ...struct.Keyword,
      Bigint: "bigint",
    },
  }),
  primitiveTypesConstructs: () => {
    return {
       integer: {
         $default: () => 'number',
         // Here is where it translates integer type with format int64 to bigint
         int64: () => 'bigint',
       },
    };
  }
});

raychengy avatar Jul 09 '24 15:07 raychengy

This should be the default behavior since 64 bit ints can be larger than Number.MAX_SAFE_INTEGER.

sylphrena0 avatar Apr 08 '25 19:04 sylphrena0