Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
70 changes: 70 additions & 0 deletions schemas/v1.1/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
$id: https://spec.openapis.org/overlay/1.1/schema/WORK-IN-PROGRESS
$schema: https://json-schema.org/draft/2020-12/schema
description: The description of Overlay v1.1.x documents
type: object
properties:
overlay:
type: string
pattern: ^1\.1\.\d+$
info:
$ref: "#/$defs/info-object"
extends:
type: string
format: uri-reference
actions:
type: array
minItems: 1
uniqueItems: true
items:
$ref: "#/$defs/action-object"
required:
- overlay
- info
- actions
$ref: "#/$defs/specification-extensions"
unevaluatedProperties: false
$defs:
info-object:
type: object
properties:
title:
type: string
version:
type: string
required:
- title
- version
$ref: "#/$defs/specification-extensions"
unevaluatedProperties: false
action-object:
properties:
target:
type: string
pattern: ^\$
description:
type: string
oneOf:
- properties:
update:
type:
- string
- boolean
- object
- array
- number
- "null"
required:
- update
- properties:
remove:
type: boolean
default: false
required:
- remove
required:
- target
$ref: "#/$defs/specification-extensions"
unevaluatedProperties: false
specification-extensions:
patternProperties:
^x-: true
3 changes: 2 additions & 1 deletion scripts/validate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ const args = process.argv.reduce((acc, arg) => {

const schemaType = args.schema || "schema";
const outputFormat = args.format || defaultOutputFormat;
const version = args.version || "1.0";

// Config
setMetaSchemaOutputFormat(outputFormat);

// Compile / meta-validate
const validateOverlay = await validate(`./schemas/v1.0/${schemaType}.yaml`);
const validateOverlay = await validate(`./schemas/v${version}/${schemaType}.yaml`);

// Validate instance
const instanceYaml = await readFile(`${process.argv[process.argv.length - 1]}`, "utf8");
Expand Down
52 changes: 26 additions & 26 deletions tests/v1.0/schema.test.mjs → tests/schema.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,38 @@ const parseYamlFromFile = (filePath) => {
return YAML.parse(schemaYaml, { prettyErrors: true });
};

const runTestSuite = (version, validateOverlay, suite = "pass") => {
readdirSync(`./tests/v${version}/${suite}`, { withFileTypes: true })
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
.forEach((entry) => {
test(entry.name, () => {
const instance = parseYamlFromFile(`./tests/v${version}/${suite}/${entry.name}`);
const output = validateOverlay(instance, BASIC);
if (suite === "pass")
expect(output).to.deep.equal({ valid: true });
else
expect(output.valid).to.equal(false);
});
});
}

setMetaSchemaOutputFormat(BASIC);

let validateOverlay;
try {
validateOverlay = await validate("./schemas/v1.0/schema.yaml");
} catch (error) {
console.error(error.output);
process.exit(1);
}
const versions = ["1.0", "1.1"];

describe("v1.0", () => {
describe.each(versions)("v%s", async (version) => {
let validateOverlay;
try {
validateOverlay = await validate(`./schemas/v${version}/schema.yaml`);
} catch (error) {
console.error(error.output);
process.exit(1);
}
describe("Pass", () => {
readdirSync(`./tests/v1.0/pass`, { withFileTypes: true })
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
.forEach((entry) => {
test(entry.name, () => {
const instance = parseYamlFromFile(`./tests/v1.0/pass/${entry.name}`);
const output = validateOverlay(instance, BASIC);
expect(output).to.deep.equal({ valid: true });
});
});
runTestSuite(version, validateOverlay);
});

describe("Fail", () => {
readdirSync(`./tests/v1.0/fail`, { withFileTypes: true })
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
.forEach((entry) => {
test(entry.name, () => {
const instance = parseYamlFromFile(`./tests/v1.0/fail/${entry.name}`);
const output = validateOverlay(instance, BASIC);
expect(output.valid).to.equal(false);
});
});
runTestSuite(version, validateOverlay, "fail");
});
});
1 change: 1 addition & 0 deletions tests/v1.0/pass/actions-description.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ info:
actions:
- target: '$' # Root of document
description: this is an action description
update: {}
1 change: 1 addition & 0 deletions tests/v1.0/pass/actions-extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ info:
actions:
- target: '$' # Root of document
x-myActionsExtension: {}
update: {}
1 change: 1 addition & 0 deletions tests/v1.0/pass/info-extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ info:
x-myInfoExtension: {}
actions:
- target: '$' # Root of document
update: {}
1 change: 1 addition & 0 deletions tests/v1.0/pass/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ info:
version: 1.0.0
actions:
- target: '$' # Root of document
update: {}
1 change: 1 addition & 0 deletions tests/v1.0/pass/root-extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ info:
version: 1.0.0
actions:
- target: '$' # Root of document
update: {}
x-myExtension: {}
7 changes: 7 additions & 0 deletions tests/v1.1/fail/actions-invalid-description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overlay: 1.1.0
info:
title: Actions invalid description
version: 1.0.0
actions:
- target: '$' # Root of document
description: 10
7 changes: 7 additions & 0 deletions tests/v1.1/fail/actions-invalid-target.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overlay: 1.1.0
info:
title: Invalid `target`, must begin with `$`
version: 1.0.0
actions:
- target: info.description
update: An updated description
5 changes: 5 additions & 0 deletions tests/v1.1/fail/actions-minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
overlay: 1.1.0
info:
title: Minimal actions
version: 1.0.0
actions: []
6 changes: 6 additions & 0 deletions tests/v1.1/fail/actions-missing-target.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
overlay: 1.1.0
info:
title: Missing actions `target`
version: 1.0.0
actions:
- update: my description
5 changes: 5 additions & 0 deletions tests/v1.1/fail/actions-missing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
overlay: 1.1.0
info:
title: Missing `actions`
version: 1.0.0
extends: '/openapi.yaml'
9 changes: 9 additions & 0 deletions tests/v1.1/fail/actions-not-unique.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
overlay: 1.1.0
info:
title: Actions not unique
version: 1.0.0
actions:
- target: '$.info.title'
update: 'My New title'
- target: '$.info.title'
update: 'My New title'
7 changes: 7 additions & 0 deletions tests/v1.1/fail/extends-invalid-type.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overlay: 1.1.0
info:
title: Invalid `extends` type
version: 1.0.0
extends: {}
actions:
- target: '$' # Root of document
5 changes: 5 additions & 0 deletions tests/v1.1/fail/info-missing-title.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
overlay: 1.1.0
info:
version: 1.0.0
actions:
- target: '$' # Root of document
5 changes: 5 additions & 0 deletions tests/v1.1/fail/info-missing-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
overlay: 1.1.0
info:
title: Missing Info version
actions:
- target: '$' # Root of document
6 changes: 6 additions & 0 deletions tests/v1.1/fail/invalid-overlay-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
overlay: 2
info:
title: Invalid Overlay version
version: 1.0.0
actions:
- target: '$' # Root of document
5 changes: 5 additions & 0 deletions tests/v1.1/fail/not-an-object.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- root
- must
- be
- an
- object
10 changes: 10 additions & 0 deletions tests/v1.1/fail/not-update-with-remove.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
overlay: 1.1.0
info:
title: Update many objects at once
version: 1.0.0
actions:
- target: $.paths.*.get
update:
x-safe: true
remove: true
description: This test could technically be in 1.0 but I'm not sure whether we can edit the schema at this point.
11 changes: 11 additions & 0 deletions tests/v1.1/pass/actions-array-modification-example-remove.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
overlay: 1.1.0
info:
title: Add an array element
version: 1.0.0
actions:
- target: $.paths.*.get.parameters
update:
name: newParam
in: query
schema:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overlay: 1.1.0
info:
title: Remove a array element
version: 1.0.0
actions:
- target: $.paths.*.get.parameters[[email protected] == 'dummy']
remove: true
8 changes: 8 additions & 0 deletions tests/v1.1/pass/actions-description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
overlay: 1.1.0
info:
title: Actions Description
version: 1.0.0
actions:
- target: '$' # Root of document
description: this is an action description
update: {}
8 changes: 8 additions & 0 deletions tests/v1.1/pass/actions-extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
overlay: 1.1.0
info:
title: Actions Extensions
version: 1.0.0
actions:
- target: '$' # Root of document
x-myActionsExtension: {}
update: {}
22 changes: 22 additions & 0 deletions tests/v1.1/pass/actions-structured-overlay-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
overlay: 1.1.0
info:
title: Structured Overlay
version: 1.0.0
extends: '/openapi.yaml'
actions:
- target: '$' # Root of document
update:
info:
x-overlay-applied: structured-overlay
paths:
'/':
summary: 'The root resource'
get:
summary: 'Retrieve the root resource'
x-rate-limit: 100
'/pets':
get:
summary: 'Retrieve a list of pets'
x-rate-limit: 100
components:
tags: []
16 changes: 16 additions & 0 deletions tests/v1.1/pass/actions-targeted-overlay-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
overlay: 1.1.0
info:
title: Targeted Overlay
version: 1.0.0
actions:
- target: $.paths['/foo'].get
update:
description: This is the new description
- target: $.paths['/bar'].get
update:
description: This is the updated description
- target: $.paths['/bar']
update:
post:
description: This is an updated description of a child object
x-safe: false
14 changes: 14 additions & 0 deletions tests/v1.1/pass/actions-traits-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
overlay: 1.1.0
info:
title: Apply Traits
version: 1.0.0
actions:
- target: $.paths.*.get[[email protected]]
update:
parameters:
- name: top
in: query
# ...
- name: skip
in: query
# ...
12 changes: 12 additions & 0 deletions tests/v1.1/pass/actions-wildcard-overlay-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
overlay: 1.1.0
info:
title: Update many objects at once
version: 1.0.0
actions:
- target: $.paths.*.get
update:
x-safe: true
- target: $.paths.*.get.parameters[[email protected]=='filter' && @.in=='query']
update:
schema:
$ref: '#/components/schemas/filterSchema'
8 changes: 8 additions & 0 deletions tests/v1.1/pass/info-extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
overlay: 1.1.0
info:
title: Info Extensions
version: 1.0.0
x-myInfoExtension: {}
actions:
- target: '$' # Root of document
update: {}
7 changes: 7 additions & 0 deletions tests/v1.1/pass/minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overlay: 1.1.0
info:
title: Minimal
version: 1.0.0
actions:
- target: '$' # Root of document
update: {}
8 changes: 8 additions & 0 deletions tests/v1.1/pass/root-extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
overlay: 1.1.0
info:
title: Root Extensions
version: 1.0.0
actions:
- target: '$' # Root of document
update: {}
x-myExtension: {}