Skip to content

openapi: unquoted YAML date literals drop defaults and destroy enum values #30

Description

@OmarAlJarrah

Summary

YAML resolves plain scalars like 2021-01-01 to the !!timestamp tag. scalarValue has no case for that tag and errors with "unsupported scalar tag", and the failure cascades differently by position:

  • default: — dropped with a warning diagnostic.
  • example:/examples: — dropped silently (conversion errors are discarded).
  • enum: — worst case: one unconvertible member makes enumMembers bail, the enum falls to enumAsUnion, and every date member is re-converted via valueOrNull into a null literal. The actual enum values are destroyed, not preserved: enum: [2021-01-01, 2022-02-02] becomes a union of two literals whose values are both ValueNull.

Dates in defaults/enums are routine spec content, and YAML does not require quoting them.

Reproduction

openapi: 3.1.0
info: {title: t, version: '1'}
paths: {}
components:
  schemas:
    D:
      type: string
      format: date
      default: 2021-01-01
      enum: [2021-01-01, 2022-02-02]

Result: Default=nil; a Union of two Literals both kind=null; diagnostics default: openapi: unsupported scalar tag "!!timestamp" and heterogeneous or non-scalar enum lowered as a union of literals.

Root cause

compilers/openapi/value.go:48-88 (no !!timestamp case in scalarValue); enum destruction via compose.go:379-399 + 437-445 (enumAsUnion + valueOrNull mapping conversion failure to a null literal); silent example drop at schema.go:556-569.

Expected

!!timestamp scalars should be captured as their string spelling (ValueStr) — the schema declares type: string; the tag is a YAML parsing artifact, not source semantics. Independently: a failed value conversion must never silently become a null literal, and example-conversion errors must not be discarded.

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