Skip to content

openapi: one classifier for YAML scalars, shared by value lowering and raw preservation #784

Closed

Description

@OmarAlJarrah

Problem

Deciding what kind of value a YAML scalar is happens in two parallel switches over the resolved tag:

  • value.scalarValue (compilers/openapi/internal/value/value.go) lowers a scalar to an ir.Value.
  • rawConv.scalar (compilers/openapi/internal/annotation/rawjson.go) renders a scalar as canonical JSON for Unmodeled and other raw payloads.

They have already diverged on one input (#783), and each re-derives rules that must agree: which tags are numbers, how a !!int base prefix and _ separators are read (value.NumericLiteral, which rawConv calls), what an unquoted !!str that is a decimal literal means, and what a !!timestamp or !!binary keeps. A rule added to one is invisible to the other, and nothing compares them.

Some differences are deliberate and must survive: a !!binary is decoded to bytes in ir.Value and kept as its source spelling in a raw payload (#242). The disagreement that matters is classification, not rendering.

Other sites read tags for narrower purposes (load/load.go, load/mappings.go, detect.go) and are in scope only where they classify a scalar rather than test for one tag.

Proposed direction

Split classification from rendering. One function in compilers/openapi/internal decides the kind of a scalar node (null, bool, number with its ir.BigVal, string, timestamp, binary, unresolved tag) and returns it. value and annotation each render from that, keeping their own output forms.

It stays inside compilers/openapi/internal. Promotion into compilers/compile needs evidence from all three compilers (docs/micro-compiler-design.md §3), and the GraphQL and Protobuf drafts parse SDL and .proto rather than YAML, so they offer none.

Acceptance

Activity

  1. added
    priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formats
    on Oct 19, 2026
  2. OmarAlJarrah commented on Oct 20, 2026

    @OmarAlJarrah
    MemberAuthor

    #1016 moves two of these tag tests. At 83ab508 load/mappings.go is deleted. Its ScalarNode && Tag == "!!bool" test is now bind.schemaShaped, and the !!null test on a $ref's value moved from bind/bind.go to bind.docs.refOf, both in compilers/openapi/internal/bind/documents.go. No new classifier was added.

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

    priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatstype:choreRefactor or cleanup, no behavior change

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions