Skip to content

JSON Schema serialize BigInt to string  #491

Closed
@tzelon-cypator

Description

@tzelon-cypator

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the regression has not already been reported

Last working version

4.1.0

Stopped working in version

4.2.0

Node.js version

16

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.3.1

💥 Regression Report

Before version 4.2.0 response schema with property type string, format int64, and pattern ^[0-9]*$ would be able to serialize BigInt to string.
version 4.2.0 return an error "Do not know how to serialize a BigInt"

Removing the format solves the issue.

Steps to Reproduce

codesandbox demo https://codesandbox.io/s/bigint-serialize-jqn5uu

app.get(
    "/",
    {
      schema: {
        response: {
          200: {
            type: "object",
            properties: {
              hello: {
                type: "string",
                format: "int64",
                pattern: "^[0-9]*$"
              }
            }
          }
        }
      }
    },
    async (request, reply) => {
      return { hello: 123n };
    }
  );

Expected Behavior

I'm not sure if the problem is in v4.2.0 or previous versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerssemver-minorIssue or PR that should land as semver minor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions