-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added validation for _info.yaml (#281)
DRY'ed JSON schema validation logic Signed-off-by: Theo Truong <[email protected]>
- Loading branch information
Showing
19 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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,44 @@ | ||
$schema: http://json-schema.org/draft-07/schema# | ||
|
||
type: object | ||
properties: | ||
title: | ||
type: string | ||
summary: | ||
type: string | ||
description: | ||
type: string | ||
termsOfService: | ||
type: string | ||
format: uri | ||
contact: | ||
$comment: https://spec.openapis.org/oas/v3.1.0#contact-object | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
url: | ||
type: string | ||
format: uri | ||
email: | ||
type: string | ||
format: email | ||
license: | ||
$comment: https://spec.openapis.org/oas/v3.1.0#license-object | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
identifier: | ||
type: string | ||
url: | ||
type: string | ||
format: uri | ||
required: | ||
- name | ||
version: | ||
type: string | ||
required: | ||
- title | ||
- version | ||
- $schema |
1 change: 1 addition & 0 deletions
1
json_schemas/_superseded_operations.yaml → ...chemas/_superseded_operations.schema.yaml
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
$schema: http://json-schema.org/draft-07/schema# | ||
|
||
type: object | ||
patternProperties: | ||
^\$schema$: | ||
|
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
title: OpenSearch API | ||
description: OpenSearch API | ||
$schema: ../json_schemas/_info.schema.yaml | ||
|
||
title: OpenSearch API Specification | ||
version: 1.0.0 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,5 @@ | ||
import FileValidator from './base/FileValidator' | ||
|
||
export default class InfoFile extends FileValidator { | ||
has_json_schema = true | ||
} |
This file contains 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 |
---|---|---|
@@ -1,22 +1,5 @@ | ||
import FileValidator from './base/FileValidator' | ||
import ajv from 'ajv' | ||
import { type ValidationError } from '../../types' | ||
import { read_yaml } from '../../helpers' | ||
|
||
export default class SupersededOperationsFile extends FileValidator { | ||
readonly JSON_SCHEMA_PATH = '../json_schemas/_superseded_operations.yaml' | ||
|
||
validate (): ValidationError[] { | ||
return [ | ||
this.validate_json_schema() | ||
].filter(e => e) as ValidationError[] | ||
} | ||
|
||
validate_json_schema (): ValidationError | undefined { | ||
const schema = read_yaml(this.JSON_SCHEMA_PATH) | ||
const validator = (new ajv()).compile(schema) | ||
if (!validator(this.spec())) { | ||
return this.error(`File content does not match JSON schema found in '${this.JSON_SCHEMA_PATH}':\n ${JSON.stringify(validator.errors, null, 2)}`) | ||
} | ||
} | ||
has_json_schema = true | ||
} |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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 @@ | ||
import InfoFile from '../../linter/components/InfoFile' | ||
|
||
test('validate()', () => { | ||
const validator = new InfoFile('./test/linter/fixtures/_info.yaml') | ||
expect(validator.validate()).toEqual([ | ||
{ | ||
file: 'fixtures/_info.yaml', | ||
location: '$schema', | ||
message: 'JSON Schema is required but not found in this file.' | ||
} | ||
]) | ||
}) |
This file contains 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
This file contains 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,2 @@ | ||
title: OpenSearch API Specification | ||
version: 1.0.0 |
This file contains 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
This file contains 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,4 @@ | ||
$schema: ../json_schemas/_info.schema.yaml | ||
|
||
title: '' | ||
version: '' |
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
$schema: ../../../../../json_schemas/_superseded_operations.yaml | ||
$schema: ../json_schemas/_superseded_operations.schema.yaml |
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
$schema: should-be-ignored | ||
|
||
title: OpenSearch API | ||
description: OpenSearch API | ||
version: 1.0.0 |