-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into security-api-spec
- Loading branch information
Showing
28 changed files
with
376 additions
and
51 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
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
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,44 @@ | ||
import type NamespacesFolder from './components/NamespacesFolder' | ||
import type SchemasFolder from './components/SchemasFolder' | ||
import { type ValidationError } from '../types' | ||
import { SchemaVisitor } from './utils/SpecificationVisitor' | ||
import { is_ref, type MaybeRef, SpecificationContext } from './utils' | ||
import { type OpenAPIV3 } from 'openapi-types' | ||
|
||
export default class InlineObjectSchemaValidator { | ||
private readonly _namespaces_folder: NamespacesFolder | ||
private readonly _schemas_folder: SchemasFolder | ||
|
||
constructor (namespaces_folder: NamespacesFolder, schemas_folder: SchemasFolder) { | ||
this._namespaces_folder = namespaces_folder | ||
this._schemas_folder = schemas_folder | ||
} | ||
|
||
validate (): ValidationError[] { | ||
const errors: ValidationError[] = [] | ||
|
||
const visitor = new SchemaVisitor((ctx, schema) => { | ||
this.#validate_schema(ctx, schema, errors) | ||
}); | ||
|
||
[ | ||
...this._namespaces_folder.files, | ||
...this._schemas_folder.files | ||
].forEach(f => { visitor.visit_specification(new SpecificationContext(f.file), f.spec()) }) | ||
|
||
return errors | ||
} | ||
|
||
#validate_schema (ctx: SpecificationContext, schema: MaybeRef<OpenAPIV3.SchemaObject>, errors: ValidationError[]): void { | ||
if (is_ref(schema) || schema.type !== 'object' || schema.properties === undefined) { | ||
return | ||
} | ||
|
||
const this_key = ctx.key | ||
const parent_key = ctx.parent().key | ||
|
||
if (parent_key === 'properties' || this_key === 'additionalProperties' || this_key === 'items') { | ||
errors.push(ctx.error('object schemas should be defined out-of-line via a $ref')) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.