Skip to content

Large integers inside style=deepObject struct mashaled as floats #28

New issue

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

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

Already on GitHub? # to your account

Open
mgabeler-lee-6rs opened this issue Jan 9, 2024 · 1 comment · May be fixed by #29
Open

Large integers inside style=deepObject struct mashaled as floats #28

mgabeler-lee-6rs opened this issue Jan 9, 2024 · 1 comment · May be fixed by #29

Comments

@mgabeler-lee-6rs
Copy link

mgabeler-lee-6rs commented Jan 9, 2024

Given a parameter like this:

        - name: foo
          in: query
          style: deepObject
          schema:
            type: object
            properties:
              min:
                type: integer
                format: int64
              max:
                type: integer
                format: int64

The generated client code:

  1. Marshals the struct to JSON
  2. Parses the JSON back as a map[string]any, resulting in the numbers being converted to float64 -- already not great her I think
  3. Constructs the query parameter values using fmt.Sprintf("=%v, ...) resulting in the integer parameter using floating point "e" notation if it's greater than ~ 100000
  4. The generated server then refuses to parse values like 1.23454678e9 as not valid string representations of integers

Item 2 happens in MarshalDeepObject:

err = json.Unmarshal(buf, &i2)

Item 3 happens just above in marshalDeepObject:

prefix + fmt.Sprintf("=%v", t),

I think that, if it has to go through the unfortunate JSON loop, it should use a json.Decoder with UseNumber() applied so that numbers are retained at full fidelity. This is what styleStruct does for other styles:

runtime/styleparam.go

Lines 235 to 236 in 35e8035

e := json.NewDecoder(bytes.NewReader(buf))
e.UseNumber()

mgabeler-lee-6rs added a commit to mgabeler-lee-6rs/runtime that referenced this issue Jan 9, 2024
mgabeler-lee-6rs added a commit to mgabeler-lee-6rs/runtime that referenced this issue Jan 9, 2024
@mgabeler-lee-6rs
Copy link
Author

Submitted #29 which fixes the issue for me locally, using the UseNumber path noted above

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant