Skip to content

Commit

Permalink
3.1 Schema: Extend schema to use OAS base vocabulary
Browse files Browse the repository at this point in the history
The main schema no longer validates schemas other than verifying that
they are either a schema or an object.
  • Loading branch information
jdesrosiers committed Mar 3, 2021
1 parent f7ef3c9 commit eccada9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
6 changes: 6 additions & 0 deletions schemas/v3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ 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:
Expand Down
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'
7 changes: 5 additions & 2 deletions schemas/v3.1/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ properties:
info:
$ref: '#/$defs/info'
jsonSchemaDialect:
type: string
$ref: '#/$defs/uri'
default: 'https://spec.openapis.org/oas/3.1/dialect/base'
servers:
$ref: '#/$defs/server'
paths:
Expand Down Expand Up @@ -681,7 +682,9 @@ $defs:

schema:
$dynamicAnchor: meta
$ref: 'https://spec.openapis.org/oas/3.1/dialect/base'
type:
- object
- boolean

security-scheme:
type: object
Expand Down
3 changes: 2 additions & 1 deletion schemas/v3.1/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ before(async () => {
JsonSchema.add(dialect);
JsonSchema.add(vocabulary);
JsonSchema.add(yaml.parse(fs.readFileSync(`${__dirname}/schema.yaml`, "utf8"), { prettyErrors: true }));
metaSchema = await JsonSchema.get("https://spec.openapis.org/oas/3.1/schema/2021-03-02");
JsonSchema.add(yaml.parse(fs.readFileSync(`${__dirname}/schema-base.yaml`, "utf8"), { prettyErrors: true }));
metaSchema = await JsonSchema.get("https://spec.openapis.org/oas/3.1/schema-base/2021-03-02");
});

describe("Pass", () => {
Expand Down

0 comments on commit eccada9

Please sign in to comment.