Skip to content

Validate with opis/json-schema, which supports OpenAPI 3.1 - #81

Merged
DerManoMann merged 1 commit into
mainfrom
feat/opis-engine
Oct 13, 2026
Merged

DerManoMann merged 1 commit into
mainfrom
feat/opis-engine

Conversation

@DerManoMann

Copy link
Copy Markdown
Owner

Fourth part of the new shape for 3.0. justinrainbow/json-schema does not support JSON Schema 2020-12, which is what OpenAPI 3.1 uses, so bodies are now validated with opis/json-schema.

  • 3.0 documents are translated to 2020-12 first. nullable adds null to the type (and the enum), or wraps a schema without a type in an anyOf. The boolean exclusiveMinimum/exclusiveMaximum take the bound's value. This replaces fixNullable(), which rewrote every document, 3.1 included. swagger-php's 3.0 null branch from fix(Schema): 3.0 output keeps nullable only beside a type zircote/swagger-php#2251 verifies as well.
  • Errors: a mismatch carries Schema\SchemaErrors (pointer, keyword, message) rather than the engine's own arrays, so changing the engine again changes nothing for users. Messages are opis's now, for example "The required properties (name) are missing".
  • Other engines: the verifier takes an optional Schema\SchemaValidator. It gets each schema as the document writes it, together with the document's OpenAPI version, and translates what it needs. Schema\OpenApi30Translator is there for engines that only know JSON Schema. The loader no longer rewrites anything, and getResponseSchemaUrlFor() is gone, since its data:// URL only existed for justinrainbow.

The test fixture's references were not JSON pointers: #components/schemas/user, without the / after #. justinrainbow resolved them anyway, opis does not. They are fixed in the fixture and the specs regenerated. A document with the same typo will report an unresolved reference after upgrading, which belongs in the upgrade notes.

Twenty new cases cover the 3.0 translation and 3.1 documents, plus a custom validator and the loaded specification staying untouched. Checked locally with highest and lowest dependencies, opis 2.4 included.

Bodies are validated against JSON Schema 2020-12, and OpenAPI 3.0 documents are
translated first: `nullable` and the boolean `exclusiveMinimum` and
`exclusiveMaximum`. A mismatch carries `Schema\SchemaError`s rather than the
engine's own arrays, so changing the engine again changes nothing for users.
Validators get the document's OpenAPI version and translate what they need.
@DerManoMann
DerManoMann merged commit abf5b87 into main Oct 13, 2026
21 checks passed
@DerManoMann
DerManoMann deleted the feat/opis-engine branch October 13, 2026 04:17
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