Skip to content

openapi: infer no kind from an items or additionalProperties schema that writes only a comment #2082

In progress

Description

@OmarAlJarrah

Problem

With #1996 (at 6630476), a schema naming no type lowers by the keywords giving its instances a type, and items or additionalProperties count only where they hold "a schema that writes a keyword" (docs/compilers/openapi.md#shape-applicator: true and {} state nothing, as Core 2020-12 §10.3.1.2 and §10.3.2.3 say). A schema object holding only a comment counts as one that writes a keyword, though a comment says nothing of the instance:

openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    Comment: {items: {$comment: c}}
    Empty: {items: {}}
$ morphic compile --diag-limit 0 spec.yaml | jq -c '.types | to_entries[] | select(.key | test("schemas/(Comment|Empty)$")) | {id: (.key | split("/") | last), kind: .value.kind, inferred: (.value.provenance.inferred // null), unmodeled: ((.value.unmodeled // {}) | keys)}'

with a binary built from origin/main (38da05c), and from #1996 (6630476):

main : {"id":"Comment","kind":"scalar","inferred":null,"unmodeled":["openapi:items"]}
       {"id":"Empty","kind":"scalar","inferred":null,"unmodeled":["openapi:items"]}
#1996: {"id":"Comment","kind":"list","inferred":"kind-inference","unmodeled":[]}
       {"id":"Empty","kind":"scalar","inferred":null,"unmodeled":["openapi:items"]}

Comment and Empty state the same thing, and main lowers them alike. additionalProperties: {$comment: c} is a MapT marked kind-inference, additionalProperties: {} the top type; $anchor and $defs in place of the comment do the same. A $comment in the items of an allOf entry stays the top type ({allOf: [{items: {$comment: c}}]}), so the two spellings of one schema part as well.

Cause

Three predicates decide "this schema says nothing", and they disagree on a schema whose keys are all silent (statement.ReadBeside drops comments, anchors and $defs):

  • statesNothing (compilers/openapi/internal/schema/refinement.go): true, unwritten, or no key ReadBeside reads. {$comment: c} states nothing.
  • typesInstances (schema/schema.go): stated, with any key. {$comment: c} types its instances. This is the one that infers the List and the MapT.
  • the closure statesNothing inside refusesNothing (schema/admissions.go, which shadows the function above): true, or stated with no keys. {$comment: c} states something.

Direction

A draft. One predicate for "this schema says nothing", statement.Schema.Silent() read over ReadBeside, used by all three, so Comment lowers as Empty does and the closure in refusesNothing no longer shadows. Whether a note that carries documentation (description, title) is silent is a separate question: ReadBeside does not drop them, and {items: {description: d}} is a List on #1996; this issue leaves that as it is.

A conformance case for the pair, Comment beside Empty and the allOf spelling, so the oracles hold them together.

Out of scope

Whether an items holding a schema that writes a keyword should infer a kind at all (shape-applicator's decision). The lowering of prefixItems: [{}], which infers a Tuple because the keyword lists a position.

Related: #1996, #1991

Priority: P3, rule 3 (a valid construct the golden spec does not use: jq '[.. | objects | select(has("$comment"))] | length' openapi.json → 0 and items or additionalProperties holding a schema of nothing but silent keys → 0, cloudflare/api-schemas@17d9fe00). It changes what a document compiles to on #1996 against main, which keeps all of these verbatim under openapi:items or openapi:additionalProperties.

Activity

  1. added
    type:bug
    priority:P3
    on Nov 18, 2026
  2. OmarAlJarrah commented on Nov 30, 2026

    @OmarAlJarrah
    MemberAuthor

    Fixed in #2354 at acf4512, which closes this on merge. One predicate, WritesOnlyIdentifierAndMetaKeywords, says a schema writing only identifier and meta keywords states nothing, and both readers ask it. Comment: {items: {$comment: c}} lowers as Empty: {items: {}} does, to the top type keeping openapi:items, and so do {additionalProperties: {$comment: c}} and {allOf: [{items: {$comment: c}}]}. {items: {description: d}} stays a List, as this issue left it. The conformance case silent-applicator.yaml holds the pair.

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:P3type:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions