Skip to content

RFC: BigInt support #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rand0m-cloud opened this issue Nov 14, 2023 · 3 comments
Closed

RFC: BigInt support #1439

rand0m-cloud opened this issue Nov 14, 2023 · 3 comments
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!

Comments

@rand0m-cloud
Copy link

Description
In the OpenAPI spec for qdrant, we have this definition for an ID:

{
  "ExtendedPointId": {
    "description": "Type, used for specifying point ID in user interface",
    "anyOf": [
      {
        "type": "integer",
        "format": "uint64",
        "minimum": 0
      },
      {
        "type": "string",
        "format": "uuid"
      }
    ]
  }
}

This is causing issues in the JS REST client when the backend sends back a large number for an ID that is lost when converted to JS's number. I'm not sure how best to solve this issue because it feels like a breaking change. Currently, a number field is generated for number and integer fields in the OpenAPI spec.

Proposal
Generate a BigInt field when parsing a integer field in the OpenAPI spec.

@rand0m-cloud rand0m-cloud added enhancement New feature or request PRs welcome PRs are welcome to solve this issue! openapi-ts Relevant to the openapi-typescript library labels Nov 14, 2023
@marcomuser
Copy link
Contributor

I think you could use the transform option to generate BigInts for integers. See: https://github.com/drwpow/openapi-typescript/blob/main/docs/src/content/docs/v6/node.md#transform--posttransform

@drwpow
Copy link
Contributor

drwpow commented Nov 16, 2023

As @marcomuser said, the transform() option is the preferred way to handle this. Remember that openapi-typescript has no runtime, and BigInt is not JSON-serializable. So how you instantiate that from your API is up to you (there is no singular, straightforward way to do this because you’re going to be overriding basic JSON deserialization), and openapi-typescript has no bearing on how that happens. So however you decide to solve that problem in your runtime code, just update openapi-typescript’s via transform() to match.

@drwpow
Copy link
Contributor

drwpow commented Nov 21, 2023

Closed this issue because this is outside the scope of this library, however, I definitely think this should:

  1. Be added to the docs examples (because others may have this problem)
  2. Figure out a good solution for openapi-fetch to use this since it does have a runtime component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

3 participants