Skip to content

Commit 5517ebc

Browse files
committed
feat(test): add schema tests and schema
1 parent 413fe0d commit 5517ebc

23 files changed

+207
-2
lines changed

schemas/v1.0/readme.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# OpenAPI Overlay 1.0.x JSON Schema
2+
3+
Here you can find the JSON Schema for validating Overlays of versions 1.0.x.
4+
5+
As a reminder, the JSON Schema is not the source of truth for the Specification.
6+
In cases of conflicts between the Specification itself and the JSON Schema, the
7+
Specification wins. Also, some Specification constraints cannot be represented
8+
with the JSON Schema so it's highly recommended to employ other methods to
9+
ensure compliance.
10+
11+
The iteration version of the JSON Schema can be found in the `$id` field.
12+
For example, the value of `$id: https://spec.openapis.org/overlay/1.0/schema/2024-10-17` means this iteration was created on October 17, 2024.
13+
14+
## Contributing
15+
16+
To submit improvements to the schema, modify the `schema.yaml` and add test cases for your changes.
17+
18+
The TSC will then:
19+
- Run tests on the updated schema
20+
- Update the iteration version
21+
- Publish the new version
22+
23+
## Tests
24+
25+
The [test suite](../../tests/v1.0) is part of this package.
26+
27+
```bash
28+
npm install
29+
npm test
30+
```
31+
32+
You can also validate a document individually.
33+
34+
```bash
35+
node scripts/validate.mjs path/to/document/to/validate.yaml
36+
```

schemas/v1.0/schema.yaml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,74 @@
11
$id: https://spec.openapis.org/overlay/1.0/schema/WORK-IN-PROGRESS
22
$schema: https://json-schema.org/draft/2020-12/schema
33
description: The description of Overlay v1.0.x documents
4-
54
type: object
5+
properties:
6+
overlay:
7+
type: string
8+
pattern: ^1\.0\.\d+$
9+
info:
10+
$ref: "#/$defs/info-object"
11+
extends:
12+
type: string
13+
format: uri-reference
14+
actions:
15+
type: array
16+
minItems: 1
17+
uniqueItems: true
18+
items:
19+
$ref: "#/$defs/action-object"
20+
required:
21+
- overlay
22+
- info
23+
- actions
24+
$ref: "#/$defs/specification-extensions"
25+
unevaluatedProperties: false
26+
$defs:
27+
info-object:
28+
type: object
29+
properties:
30+
title:
31+
type: string
32+
version:
33+
type: string
34+
required:
35+
- title
36+
- version
37+
$ref: "#/$defs/specification-extensions"
38+
unevaluatedProperties: false
39+
action-object:
40+
properties:
41+
target:
42+
type: string
43+
pattern: ^\$
44+
description:
45+
type: string
46+
update:
47+
type:
48+
- string
49+
- boolean
50+
- object
51+
- array
52+
- number
53+
- "null"
54+
remove:
55+
type: boolean
56+
default: false
57+
allOf:
58+
- if:
59+
properties:
60+
remove:
61+
const: true
62+
required:
63+
- remove
64+
then:
65+
not:
66+
required:
67+
- update
68+
required:
69+
- target
70+
$ref: "#/$defs/specification-extensions"
71+
unevaluatedProperties: false
72+
specification-extensions:
73+
patternProperties:
74+
^x-: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Actions invalid description
4+
version: 1.0.0
5+
actions:
6+
- target: '$' # Root of document
7+
description: 10
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Invalid `target`, must begin with `$`
4+
version: 1.0.0
5+
actions:
6+
- target: info.description
7+
update: An updated description
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Minimal actions
4+
version: 1.0.0
5+
actions: []
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Missing actions `target`
4+
version: 1.0.0
5+
actions:
6+
- update: my description
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Missing `actions`
4+
version: 1.0.0
5+
extends: '/openapi.yaml'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
overlay: 1.0.0
2+
info:
3+
title: No `update` with `remove`
4+
version: 1.0.0
5+
actions:
6+
- target: $.info
7+
update:
8+
description: An updated description
9+
remove: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Actions not unique
4+
version: 1.0.0
5+
actions:
6+
- target: '$.info.title'
7+
update: 'My New title'
8+
- target: '$.info.title'
9+
update: 'My New title'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Invalid `extends` type
4+
version: 1.0.0
5+
extends: {}
6+
actions:
7+
- target: '$.' # Root of document

0 commit comments

Comments
 (0)