-
Notifications
You must be signed in to change notification settings - Fork 30
Add schema stub and schema tests #86
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6b2c56b
Add schema stub and schema tests
ralfhandl 10303f2
Examples from specification
ralfhandl 7c1e278
Create validate.mjs
ralfhandl cdccabb
Workflow for schema-tests
ralfhandl 0eaf7b2
Update schema-tests.yaml
ralfhandl 55f7d52
Update wildcard-overlay-example.yaml
ralfhandl 413fe0d
Update schema-tests.yaml
ralfhandl 1792a20
OpenAPI -> Overlay
ralfhandl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { readFile } from "node:fs/promises"; | ||
| import YAML from "yaml"; | ||
| import { setMetaSchemaOutputFormat, validate } from "@hyperjump/json-schema/draft-2020-12"; | ||
| import { BASIC } from "@hyperjump/json-schema/experimental"; | ||
|
|
||
| import contentTypeParser from "content-type"; | ||
| import { addMediaTypePlugin } from "@hyperjump/browser"; | ||
| import { buildSchemaDocument } from "@hyperjump/json-schema/experimental"; | ||
|
|
||
| addMediaTypePlugin("application/schema+yaml", { | ||
| parse: async (response) => { | ||
| const contentType = contentTypeParser.parse(response.headers.get("content-type") ?? ""); | ||
| const contextDialectId = contentType.parameters.schema ?? contentType.parameters.profile; | ||
|
|
||
| const foo = YAML.parse(await response.text()); | ||
| return buildSchemaDocument(foo, response.url, contextDialectId); | ||
| }, | ||
| fileMatcher: (path) => path.endsWith(".yaml") | ||
| }); | ||
|
|
||
| const defaultOutputFormat = BASIC; | ||
|
|
||
| if (process.argv.length < 3) { | ||
| console.log(`Usage: validate [--schema=schema] [--format=${defaultOutputFormat}] path-to-file.yaml`); | ||
| console.log("\t--schema: (schema (default) | schema-base) The name of the schema file to use"); | ||
| console.log(`\t--format: (Default: ${defaultOutputFormat}) The JSON Schema output format to use. Options: FLAG, BASIC, DETAILED, VERBOSE`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const args = process.argv.reduce((acc, arg) => { | ||
| if (!arg.startsWith("--")) return acc; | ||
|
|
||
| const [argName, argValue] = arg.substring(2).split("=", 2); | ||
| return { ...acc, [argName]: argValue }; | ||
| }, {}); | ||
|
|
||
| const schemaType = args.schema || "schema"; | ||
| const outputFormat = args.format || defaultOutputFormat; | ||
|
|
||
| // Config | ||
| setMetaSchemaOutputFormat(outputFormat); | ||
|
|
||
| // Compile / meta-validate | ||
| const validateOpenApi = await validate(`./schemas/v1.0/${schemaType}.yaml`); | ||
|
|
||
| // Validate instance | ||
| const instanceYaml = await readFile(`${process.argv[process.argv.length - 1]}`, "utf8"); | ||
| const instance = YAML.parse(instanceYaml); | ||
| const results = validateOpenApi(instance, outputFormat); | ||
| console.log(JSON.stringify(results, null, " ")); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| overlay: 1.0.0 | ||
| info: | ||
| title: Add an array element | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get.parameters | ||
| update: | ||
| name: newParam | ||
| in: query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| overlay: 1.0.0 | ||
| info: | ||
| title: Remove a array element | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get.parameters[[email protected] == 'dummy'] | ||
| remove: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| overlay: 1.0.0 | ||
| info: | ||
| title: Structured Overlay | ||
| version: 1.0.0 | ||
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| overlay: 1.0.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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| overlay: 1.0.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 | ||
| # ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| overlay: 1.0.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' | ||
ralfhandl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.