Skip to content

Commit 12dcc74

Browse files
committed
Put together notes on OpenAPI 3.1
This is an attempt to try catalogue the changes that are needed - the most substantial of which seem to be in the Schema object.
1 parent 82a5a86 commit 12dcc74

4 files changed

Lines changed: 196 additions & 0 deletions

File tree

TODO.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ For OpenAPI 3.1
4949
- [ ] Support the switch to a fixed schema dialect
5050
- [x] Support summary field on Info node
5151
- [ ] Create a maxi OpenAPI 3.1 integration test to collate all the known changes
52+
- [ ] jsonSchemaDialect should default to OAS one
53+
- [ ] Allow summary and description in Reference objects
54+
- [ ] Add identifier to License node, make mutually exclusive with URL
55+
- [ ] ServerVariable enum must not be empty
56+
- [ ] Add pathItems to components
57+
- [ ] Callbacks can now reference a PathItem - previously required them
58+
- [ ] Check out whether pathItem references match the rules for relative resolution
59+
- [ ] Parameter object can have space delimited or pipeDelimited styles
60+
- [ ] Discriminator object can be extended
61+
- [ ] mutualTLS as a security scheme
62+
- [ ] I think strictness of Security Requirement rules has changed
63+

json-schema-for-3.1.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# JSON schema with 3.1
2+
3+
Temporary document to be removed with the merge of support for OpenAPI 3.1
4+
5+
Things have got complex with schemas in OpenAPI 3.1
6+
7+
How things might work:
8+
9+
- when a schema factory is created, it determines whether the dialect is suported
10+
- it then creates a factory based on the dialect
11+
- if there is a reference in it this is resolved
12+
- there could be complexities in the resolving process because of the id field - does it become relative to this?
13+
- skip dynamicAnchor and dynamicRef for now - they are quite complex: https://stackoverflow.com/questions/69728686/explanation-of-dynamicref-dynamicanchor-in-json-schema-as-opposed-to-ref-and
14+
- lets allow extra properties for schema since it's complex
15+
- there's all the $defs stuff but this might just work as being a type of reference - presumably not used in OpenAPI anyway really
16+
17+
So how might we start:
18+
19+
- Perhaps add a class method to Schema which can identify which Schema factory is used: a OAS 3.1 one, an optionally referenced OAS 3.0 one, or non optional reference (if such a need exists), based on context. Error if given an unexpected dialect
20+
- Learn whether you have to care about $id for resolving
21+
- Create a node factory for OAS 3.1 Schema:
22+
- allow arbitrary fields perhaps? Probably not needed, just a pain to keep up with JsonSchema
23+
- load a merged reference
24+
- perhaps have context support a merge concept for source location
25+
- Think about dealing with recursive defined as "#"
26+
27+
Dealing with the new JSON Schema approach for OpenAPI 3.1.
28+
29+
There is some meta fields:
30+
31+
$ref
32+
$dynamicRef
33+
$defs
34+
$schema
35+
$id
36+
$comment
37+
$anchor
38+
$dynamicAnchor
39+
40+
Then a ton of fields:
41+
42+
type: string
43+
enum: array
44+
const: any type
45+
multipleOf: number
46+
maximum: number
47+
exclusiveMaximum: number
48+
minimum: number
49+
exclusiveMinimum: number
50+
maxLength: integer >= 0
51+
minLength: integer >= 0
52+
pattern: string
53+
maxItems: integer >= 0
54+
minItems: integer >= 0
55+
uniqueItems: boolean
56+
maxContains: integer >= 0
57+
minContains: integer >= 0
58+
maxProperties: integer >= 0
59+
minProperties: integer >= 0
60+
required: array, strings, unique
61+
dependentRequired: something complex
62+
contentEncoding: string
63+
contentMediaType: string / media type
64+
contentSchema: schema
65+
title: string
66+
description: string
67+
default: any
68+
deprecated: boolean (default false)
69+
readOnly: boolean (default false)
70+
writeOnly: boolean (default false)
71+
examples: array
72+
73+
74+
allOf - non empty array of schemas
75+
anyOf - non empty array of schemas
76+
oneOf - non empty array of schemas
77+
not - schema
78+
79+
if - single schema
80+
then - single schema
81+
else - single schema
82+
83+
prefixItems: schema
84+
items: schema
85+
contains: schema
86+
87+
properties: object, each value json schema
88+
patternProperties: object each value JSON schema
89+
additionalProperties: single json schema
90+
91+
unevaluatedItems - single schema
92+
unevaluatedProperties: single schema

spec/integration/open_v3.1_examples_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@
3232
expect(document.openapi).to eq "3.1.0"
3333
end
3434
end
35+
36+
context "when using the schema I created to demonstrate changes" do
37+
let(:path) { File.join(__dir__, "..", "support", "examples", "v3.1", "changes.yaml") }
38+
39+
xit "is a valid document" do
40+
expect(document).to be_valid
41+
end
42+
43+
xit "can access the version" do
44+
expect(document.openapi).to eq "3.1.0"
45+
end
46+
end
3547
end
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Examples of changes in OpenAPI 3.1
4+
summary: 3.1 introduced a summary field to the Info node
5+
version: 1.0.0
6+
# license:
7+
# name: Apache 2.0
8+
# identifier: Apache-2.0
9+
# jsonSchemaDialect: https://spec.openapis.org/oas/3.1/dialect/base
10+
components:
11+
schemas:
12+
BasicSchema:
13+
description: "My basic schema"
14+
required:
15+
- id
16+
- name
17+
properties:
18+
id:
19+
type: integer
20+
format: int64
21+
name:
22+
type: string
23+
tag:
24+
type: string
25+
ReferencedSchema:
26+
description: "My referenced schema"
27+
$ref: "#/components/schemas/BasicSchema"
28+
DoubleReferencedSchema:
29+
description: "My double referenced schema"
30+
$ref: "#/components/schemas/ReferencedSchema"
31+
AnotherSchema:
32+
$ref: "#/components/schemas/DoubleReferencedSchema"
33+
AndAnotherSchema:
34+
$ref: "#/components/schemas/AnotherSchema"
35+
SelfReferencingSchema:
36+
type: object
37+
properties:
38+
recursive_item:
39+
$ref: "#/components/schemas/SelfReferencingSchema"
40+
# WithDialect:
41+
# $schema: https://spec.openapis.org/oas/3.1/dialect/base
42+
# type: string
43+
# Const:
44+
# const: "test"
45+
# MultipleTypes:
46+
# type:
47+
# - string
48+
# - null
49+
# Number:
50+
# type: integer
51+
# multipleOf: 5
52+
# maximum: 110
53+
# exclusiveMaximum: 111
54+
# minimum: 10
55+
# exclusiveMinimum: 9
56+
# String:
57+
# type: string
58+
# maxLength: 10
59+
# minLength: 5
60+
# pattern: "[a-z]*"
61+
# Array:
62+
# type: array
63+
# maxItems: 10
64+
# minItems: 1
65+
# uniqueItems: true
66+
# contains:
67+
# const: "test"
68+
# minContains: 1
69+
# maxContains: 1
70+
# prefixItems:
71+
# - const: "item"
72+
# type: string
73+
# items:
74+
# type: string
75+
# unevaluatedItems:
76+
# type: string
77+
# Add object
78+
# Add content types
79+
# Add $ref usage (plain, merged, defs)
80+
# Add compound things: anyOf, oneOf, not, if, then, else

0 commit comments

Comments
 (0)