Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schemas for 3.1 #2489

Merged
merged 7 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitmodules
Empty file.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
],
"dependencies": {},
"devDependencies": {
"@hyperjump/json-schema": "^0.17.0",
"chai": "^4.3.1",
"mdv": "^1.0.7",
"mocha": "^8.3.0",
"yaml": "^1.8.3"
},
"keywords": [
Expand Down
41 changes: 41 additions & 0 deletions schemas/v3.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# OpenAPI 3.1.X JSON Schema

Here you can find the JSON Schema for validating OpenAPI definitions of versions
3.1.X.

As a reminder, the JSON Schema is not the source of truth for the Specification.
In cases of conflicts between the Specification itself and the JSON Schema, the
Specification wins. Also, some Specification constraints cannot be represented
with the JSON Schema so it's highly recommended to employ other methods to
ensure compliance.

The iteration version of the JSON Schema can be found in the `$id` field. For
example, the value of `$id: https://spec.openapis.org/oas/3.1/schema/2021-03-02`
means this iteration was created on March 2nd, 2021.

The `schema.yaml` schema doesn't validate the JSON Schemas in your OpenAPI
document because 3.1 allows you to use any JSON Schema dialect you choose. We
have also included `schema-base.yaml` that extends the main schema to validate
that all schemas use the default OAS base vocabulary.

## Contributing
To submit improvements to the schema, modify the schema.yaml file only.

The TSC will then:
- Run tests on the updated schema
- Update the iteration version
- Convert the schema.yaml to schema.json
- Publish the new version

## Tests
The test suite is included as a git submodule of https://github.com/Mermade/openapi3-examples.

```bash
npx mocha --recursive tests
```

You can also validate a document individually.

```bash
scripts/validate.js path/to/document/to/validate.yaml
```
21 changes: 21 additions & 0 deletions schemas/v3.1/dialect/base.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$id": "https://spec.openapis.org/oas/3.1/dialect/base",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
"https://json-schema.org/draft/2020-12/vocab/validation": true,
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
"https://json-schema.org/draft/2020-12/vocab/content": true,
"https://spec.openapis.org/oas/3.1/vocab/base": false
},
"$dynamicAnchor": "meta",

"title": "OpenAPI 3.1 Schema Object Dialect",
"allOf": [
{ "$ref": "https://json-schema.org/draft/2020-12/schema" },
{ "$ref": "https://spec.openapis.org/oas/3.1/meta/base" }
]
}
79 changes: 79 additions & 0 deletions schemas/v3.1/meta/base.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$id": "https://spec.openapis.org/oas/3.1/meta/base",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$vocabulary": {
"https://spec.openapis.org/oas/3.1/vocab/base": true
},
"$dynamicAnchor": "meta",
"title": "OAS Base vocabulary",

"type": ["object", "boolean"],
"properties": {
"example": true,
"discriminator": { "$ref": "#/$defs/discriminator" },
"externalDocs": { "$ref": "#/$defs/external-docs" },
"xml": { "$ref": "#/$defs/xml" }
},
"$defs": {
"extensible": {
"patternProperties": {
"^x-": true
}
},
"discriminator": {
"$ref": "#/$defs/extensible",
"type": "object",
"properties": {
"propertyName": {
"type": "string"
},
"mapping": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"required": ["propertyName"],
"unevaluatedProperties": false
},
"external-docs": {
"$ref": "#/$defs/extensible",
"type": "object",
"properties": {
"url": {
"type": "string",
"format": "uri-reference"
},
"description": {
"type": "string"
}
},
"required": ["url"],
"unevaluatedProperties": false
},
"xml": {
"$ref": "#/$defs/extensible",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"namespace": {
"type": "string",
"format": "uri"
},
"prefix": {
"type": "string"
},
"attribute": {
"type": "boolean"
},
"wrapped": {
"type": "boolean"
}
},
"unevaluatedProperties": false
}
}
}
24 changes: 24 additions & 0 deletions schemas/v3.1/schema-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$id": "https://spec.openapis.org/oas/3.1/schema-base/2021-03-02",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "https://spec.openapis.org/oas/3.1/schema/2021-03-02",
"properties": {
"jsonSchemaDialect": {
"$ref": "#/$defs/dialect"
}
},
"$defs": {
"dialect": {
"const": "https://spec.openapis.org/oas/3.1/dialect/base"
},
"schema": {
"$dynamicAnchor": "meta",
"$ref\"": "https://spec.openapis.org/oas/3.1/dialect/base",
"properties": {
"$schema": {
"$ref": "#/$defs/dialect"
}
}
}
}
}
17 changes: 17 additions & 0 deletions schemas/v3.1/schema-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$id: 'https://spec.openapis.org/oas/3.1/schema-base/2021-03-02'
$schema: 'https://json-schema.org/draft/2020-12/schema'

$ref: 'https://spec.openapis.org/oas/3.1/schema/2021-03-02'
properties:
jsonSchemaDialect:
$ref: '#/$defs/dialect'

$defs:
dialect:
const: 'https://spec.openapis.org/oas/3.1/dialect/base'
schema:
$dynamicAnchor: meta
$ref": 'https://spec.openapis.org/oas/3.1/dialect/base'
properties:
$schema:
$ref: '#/$defs/dialect'
Loading