Skip to content

Conversation

@RobbertDM
Copy link

@RobbertDM RobbertDM commented Jan 12, 2026

Further fork from https://github.com/chanceattoast/kin-openapi-fork/tree/issue-230-add-openapi-3.1-support
But I didn't receive feedback for 2 weeks, so opening a PR directly into getkin/kin-openapi.

Attempts to solve #230
Builds on #1102

Chance Kirsch and others added 9 commits October 2, 2025 08:46
The implementation provides complete OpenAPI 3.1 specification compliance while maintaining 100% backward compatibility with OpenAPI 3.0.

## What Was Implemented

### 1. Schema Object Extensions (openapi3/schema.go)

Added full JSON Schema 2020-12 support with new fields:

- **`Const`** - Constant value validation
- **`Examples`** - Array of examples (replaces singular `example`)
- **`PrefixItems`** - Tuple validation for arrays
- **`Contains`, `MinContains`, `MaxContains`** - Array containment validation
- **`PatternProperties`** - Pattern-based property matching
- **`DependentSchemas`** - Conditional schema dependencies
- **`PropertyNames`** - Property name validation
- **`UnevaluatedItems`, `UnevaluatedProperties`** - Unevaluated keyword support
- **Type arrays** - Support for `["string", "null"]` notation

### 2. Document-Level Features (openapi3/openapi3.go)

- **`Webhooks`** - New field for defining webhook callbacks (OpenAPI 3.1)
- **`JSONSchemaDialect`** - Specifies default JSON Schema dialect
- **Version detection methods**:
  - `IsOpenAPI3_0()` - Returns true for 3.0.x documents
  - `IsOpenAPI3_1()` - Returns true for 3.1.x documents
  - `Version()` - Returns major.minor version string

### 3. License Object (openapi3/license.go)

- **`Identifier`** - SPDX license expression (alternative to URL)

### 4. Info Object (openapi3/info.go)

- **`Summary`** - Short summary of the API (OpenAPI 3.1)

### 5. Types Helper Methods (openapi3/schema.go)

New methods for working with type arrays:

- `IncludesNull()` - Checks if null type is included
- `IsMultiple()` - Detects type arrays (OpenAPI 3.1 feature)
- `IsSingle()` - Checks for single type
- `IsEmpty()` - Checks for unspecified types

### 6. JSON Schema 2020-12 Validator (openapi3/schema_jsonschema_validator.go)

A new opt-in validator using [santhosh-tekuri/jsonschema/v6](https://github.com/santhosh-tekuri/jsonschema):

- Full JSON Schema Draft 2020-12 compliance
- Automatic OpenAPI → JSON Schema transformation
- Converts OpenAPI 3.0 `nullable` to type arrays
- Handles `exclusiveMinimum`/`exclusiveMaximum` conversion
- Comprehensive error formatting
- Fallback to built-in validator on compilation errors
…d formatting and correcting the version logic
@StevenACoffman
Copy link

@RobbertDM Looks like the test failure is just that the openapi3.txt golden needs to be updated:

diff --git a/.github/docs/openapi3.txt b/.github/docs/openapi3.txt
index 72b573e..6af3d12 100644
--- a/.github/docs/openapi3.txt
+++ b/.github/docs/openapi3.txt
@@ -2401,6 +2401,11 @@ func EnableExamplesValidation() ValidationOption
     EnableExamplesValidation does the opposite of DisableExamplesValidation.
     By default, all schema examples are validated.
 
+func EnableJSONSchema2020Validation() ValidationOption
+    EnableJSONSchema2020Validation enables JSON Schema 2020-12 compliant
+    validation for OpenAPI 3.1 documents. This option should be used with
+    doc.Validate().
+
 func EnableSchemaDefaultsValidation() ValidationOption
     EnableSchemaDefaultsValidation does the opposite of
     DisableSchemaDefaultsValidation. By default, schema default values are
Error: Process completed with exit code 1.

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.

4 participants