Skip to content

When the maximum type is float64, using json.Unmarshal(raw, &spec.Swagger{}) will lose precision #201

Open

Description

@O3cheng

When the maximum type is float64, using json.Unmarshal(raw, &spec.Swagger{}) will lose precision

definitions:
  TestResponse:
    description: test
    type: object
    properties:
      test_1:
        description: test_1
        type: long
        format: int64
        **maximum: 9223372036854775807**
        minimum: 0

because

type SchemaProps struct {
	Maximum              *float64         `json:"maximum,omitempty"`
}

Activity

  1. fredbi commented on Mar 13, 2025

    @fredbi
    Member

    @O3cheng yes you're correct: mapping numbers as float64 is not truly JSON compliant (in the sense there is no support for arbitrarily large numbers). On the other hand, we didn't want to manipulate a big.Rat type everywhere we had some numerical input. Trade off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址