Skip to content

feat(Parser): read an OpenAPI 3.1 document into a Specification - #2387

Merged
DerManoMann merged 4 commits into
zircote:masterfrom
DerManoMann:feat/parser
Nov 12, 2026
Merged

DerManoMann merged 4 commits into
zircote:masterfrom
DerManoMann:feat/parser

Conversation

@DerManoMann

@DerManoMann DerManoMann commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Adds a parser that reads an OpenAPI 3.1 document back into a Specification, the reverse of what the 3.1 compiler writes, and Builder::withDocument() to add a hand-written document to what the attributes describe. Also two small compiler changes: an empty path is written as an empty path item, and a compiler supports any patch release of its minor version.

Summary

  • A document, from a JSON or YAML file or an already decoded array, is read by the parser matching its openapi field. Only 3.1 has a parser so far. Any other version, or none, is read as 3.1, with a warning.
  • Components keep their names, operations are filed by path or webhook and method, and references are kept as written, so they resolve the same way as references from scanned attributes. x- extensions are kept, and so is a summary beside a $ref.
  • Anything the model has no place for (for example $defs or jsonSchemaDialect) is left out with a warning that names its location in the document. A value of the wrong type is also left out with a warning, except a number where a string belongs, which is read as that string (YAML reads version: 1.0 as a number).
  • A file that does not parse throws an OpenApiException.
  • Every 3.1 example in the repository reads back and compiles to the same content as the original file. Key order follows the compiler, not the original file.
  • Builder::withDocument() adds a hand-written 3.1 document to a spec or hybrid build, for example webhooks with no PHP code behind them. A $ref can point from the document to a schema built from a class, and the other way round. Where both describe the same thing, the attributes win: info, servers, security and externalDocs come from the document only where the attributes have none, and the mergers keep the attribute's path, operation, component or tag. Plugins get the same hook. Classic mode does not read documents and logs a warning.
  • Documented in the Builder reference and as a cookbook recipe.
  • Compiler: a path with no operations and no fields is now written as an empty path item. Before, it was left out.
  • Compiler: any patch release of a supported minor version compiles, so a version like 3.1.3 no longer fails with "no compiler".

`Parser` reads a document, from a file or an array, with the parser for the version in its
`openapi` field. `Compiler\OpenApi31Parser` is the inverse of `OpenApi31Compiler`. Components
are filed by name, operations by path or webhook and method, and `$ref` stays a string. A
keyword the model cannot hold, or a value of the wrong type, is left out with a warning naming
its location.

Also `compilePaths()` writes an empty path item as `{}` rather than dropping the path.
A compiler now supports a version by its minor (`3.1.`), so a new patch release
needs no change to a list.
Every Reference Object that takes a summary keeps it now, not only an
example's.
Parses an OpenAPI 3.1 document and adds it after assembly. The
attributes win: info, servers, security and externalDocs come from the
document only where they are unset, and its paths, operations,
components and tags go first, so the mergers keep the attribute's.
@DerManoMann
DerManoMann merged commit 0b5a3c6 into zircote:master Nov 12, 2026
20 checks passed
@DerManoMann
DerManoMann deleted the feat/parser branch November 12, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant