Skip to content

Commit 0f9d3ec

Browse files
authored
Merge pull request #2489 from jdesrosiers/oas31-schema-2
Add schemas for 3.1
2 parents 42a9e3d + 1ce46a0 commit 0f9d3ec

25 files changed

+2727
-0
lines changed

.gitmodules

Whitespace-only changes.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
],
2020
"dependencies": {},
2121
"devDependencies": {
22+
"@hyperjump/json-schema": "^0.17.0",
23+
"chai": "^4.3.1",
2224
"mdv": "^1.0.7",
25+
"mocha": "^8.3.0",
2326
"yaml": "^1.8.3"
2427
},
2528
"keywords": [

schemas/v3.1/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# OpenAPI 3.1.X JSON Schema
2+
3+
Here you can find the JSON Schema for validating OpenAPI definitions of versions
4+
3.1.X.
5+
6+
As a reminder, the JSON Schema is not the source of truth for the Specification.
7+
In cases of conflicts between the Specification itself and the JSON Schema, the
8+
Specification wins. Also, some Specification constraints cannot be represented
9+
with the JSON Schema so it's highly recommended to employ other methods to
10+
ensure compliance.
11+
12+
The iteration version of the JSON Schema can be found in the `$id` field. For
13+
example, the value of `$id: https://spec.openapis.org/oas/3.1/schema/2021-03-02`
14+
means this iteration was created on March 2nd, 2021.
15+
16+
The `schema.yaml` schema doesn't validate the JSON Schemas in your OpenAPI
17+
document because 3.1 allows you to use any JSON Schema dialect you choose. We
18+
have also included `schema-base.yaml` that extends the main schema to validate
19+
that all schemas use the default OAS base vocabulary.
20+
21+
## Contributing
22+
To submit improvements to the schema, modify the schema.yaml file only.
23+
24+
The TSC will then:
25+
- Run tests on the updated schema
26+
- Update the iteration version
27+
- Convert the schema.yaml to schema.json
28+
- Publish the new version
29+
30+
## Tests
31+
The test suite is included as a git submodule of https://github.com/Mermade/openapi3-examples.
32+
33+
```bash
34+
npx mocha --recursive tests
35+
```
36+
37+
You can also validate a document individually.
38+
39+
```bash
40+
scripts/validate.js path/to/document/to/validate.yaml
41+
```

schemas/v3.1/dialect/base.schema.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$id": "https://spec.openapis.org/oas/3.1/dialect/base",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"$vocabulary": {
5+
"https://json-schema.org/draft/2020-12/vocab/core": true,
6+
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
7+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
8+
"https://json-schema.org/draft/2020-12/vocab/validation": true,
9+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
10+
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
11+
"https://json-schema.org/draft/2020-12/vocab/content": true,
12+
"https://spec.openapis.org/oas/3.1/vocab/base": false
13+
},
14+
"$dynamicAnchor": "meta",
15+
16+
"title": "OpenAPI 3.1 Schema Object Dialect",
17+
"allOf": [
18+
{ "$ref": "https://json-schema.org/draft/2020-12/schema" },
19+
{ "$ref": "https://spec.openapis.org/oas/3.1/meta/base" }
20+
]
21+
}

schemas/v3.1/meta/base.schema.json

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"$id": "https://spec.openapis.org/oas/3.1/meta/base",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"$vocabulary": {
5+
"https://spec.openapis.org/oas/3.1/vocab/base": true
6+
},
7+
"$dynamicAnchor": "meta",
8+
"title": "OAS Base vocabulary",
9+
10+
"type": ["object", "boolean"],
11+
"properties": {
12+
"example": true,
13+
"discriminator": { "$ref": "#/$defs/discriminator" },
14+
"externalDocs": { "$ref": "#/$defs/external-docs" },
15+
"xml": { "$ref": "#/$defs/xml" }
16+
},
17+
"$defs": {
18+
"extensible": {
19+
"patternProperties": {
20+
"^x-": true
21+
}
22+
},
23+
"discriminator": {
24+
"$ref": "#/$defs/extensible",
25+
"type": "object",
26+
"properties": {
27+
"propertyName": {
28+
"type": "string"
29+
},
30+
"mapping": {
31+
"type": "object",
32+
"additionalProperties": {
33+
"type": "string"
34+
}
35+
}
36+
},
37+
"required": ["propertyName"],
38+
"unevaluatedProperties": false
39+
},
40+
"external-docs": {
41+
"$ref": "#/$defs/extensible",
42+
"type": "object",
43+
"properties": {
44+
"url": {
45+
"type": "string",
46+
"format": "uri-reference"
47+
},
48+
"description": {
49+
"type": "string"
50+
}
51+
},
52+
"required": ["url"],
53+
"unevaluatedProperties": false
54+
},
55+
"xml": {
56+
"$ref": "#/$defs/extensible",
57+
"type": "object",
58+
"properties": {
59+
"name": {
60+
"type": "string"
61+
},
62+
"namespace": {
63+
"type": "string",
64+
"format": "uri"
65+
},
66+
"prefix": {
67+
"type": "string"
68+
},
69+
"attribute": {
70+
"type": "boolean"
71+
},
72+
"wrapped": {
73+
"type": "boolean"
74+
}
75+
},
76+
"unevaluatedProperties": false
77+
}
78+
}
79+
}

schemas/v3.1/schema-base.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$id": "https://spec.openapis.org/oas/3.1/schema-base/2021-03-02",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"$ref": "https://spec.openapis.org/oas/3.1/schema/2021-03-02",
5+
"properties": {
6+
"jsonSchemaDialect": {
7+
"$ref": "#/$defs/dialect"
8+
}
9+
},
10+
"$defs": {
11+
"dialect": {
12+
"const": "https://spec.openapis.org/oas/3.1/dialect/base"
13+
},
14+
"schema": {
15+
"$dynamicAnchor": "meta",
16+
"$ref\"": "https://spec.openapis.org/oas/3.1/dialect/base",
17+
"properties": {
18+
"$schema": {
19+
"$ref": "#/$defs/dialect"
20+
}
21+
}
22+
}
23+
}
24+
}

schemas/v3.1/schema-base.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
$id: 'https://spec.openapis.org/oas/3.1/schema-base/2021-03-02'
2+
$schema: 'https://json-schema.org/draft/2020-12/schema'
3+
4+
$ref: 'https://spec.openapis.org/oas/3.1/schema/2021-03-02'
5+
properties:
6+
jsonSchemaDialect:
7+
$ref: '#/$defs/dialect'
8+
9+
$defs:
10+
dialect:
11+
const: 'https://spec.openapis.org/oas/3.1/dialect/base'
12+
schema:
13+
$dynamicAnchor: meta
14+
$ref": 'https://spec.openapis.org/oas/3.1/dialect/base'
15+
properties:
16+
$schema:
17+
$ref: '#/$defs/dialect'

0 commit comments

Comments
 (0)