Skip to content

openapi: raw preservation routes numbers through float64, corrupting extensions and preserved keywords #32

Description

@OmarAlJarrah

Summary

nodeToRaw decodes a YAML node into any and re-marshals it as JSON. yaml.v3 decodes out-of-int64 integers and all decimals into float64, so every path that promises verbatim preservation silently rounds numbers:

  • x-* extensions (extensionsFrom),
  • oneOf/anyOf sibling preservation,
  • the §4.7 carve-out (not/if-then-else/dependentSchemas/contains/unevaluated*),
  • tuple items-after-prefix.

This defeats exactly the documented "preserved verbatim in Extensions" guarantee. #23 fixed the Value/BigVal channel; the raw-preservation channel has the same class of bug.

Reproduction

openapi: 3.1.0
info: {title: t, version: '1'}
paths: {}
components:
  schemas:
    S:
      type: object
      x-big: 12345678901234567890123
      x-frac: 1.000000000000000000001

Result: Extensions["openapi:x-big"] == 1.2345678901234568e+22, Extensions["openapi:x-frac"] == 1.

Root cause

compilers/openapi/schema.go:866-881node.Decode(&any) + json.Marshal instead of a number-preserving conversion.

Expected

Raw preservation must be number-safe: either serialize from the yaml.Node tree directly (rendering scalar numbers from their source text) or decode with a number-preserving representation (e.g. json.Number semantics). "Preserved verbatim" should mean byte-faithful for every scalar the source can express.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions