Skip to content
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
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions schemas/v1.1/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$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
update:
type:
- string
- boolean
- object
- array
- number
- "null"
remove:
type: boolean
default: false
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
10 changes: 5 additions & 5 deletions tests/v1.0/schema.test.mjs → tests/schema.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const parseYamlFromFile = (filePath) => {
};

function runTestSuite(version, suite) {
const schema = `./schemas/${version}/schema.yaml`;
const schema = `./schemas/v${version}/schema.yaml`;
describe(suite, () => {
readdirSync(`./tests/${version}/${suite}`, { withFileTypes: true })
readdirSync(`./tests/v${version}/${suite}`, { withFileTypes: true })
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
.forEach((entry) => {
test(entry.name, async () => {
const instance = parseYamlFromFile(`./tests/${version}/${suite}/${entry.name}`);
const instance = parseYamlFromFile(`./tests/v${version}/${suite}/${entry.name}`);
if (suite === "pass") {
await expect(instance).to.matchJsonSchema(schema);
} else {
Expand All @@ -25,9 +25,9 @@ function runTestSuite(version, suite) {
});
}

const version = "v1.0";
const versions = ["1.0", "1.1"];

describe(version, () => {
describe.each(versions)("v%s", (version) => {
runTestSuite(version, "pass");
runTestSuite(version, "fail");
});
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
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: {}