Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: merge similar ajv errors * fix: more reasonable stylish-cli logging for oas-schema rule * feat: include OAI number formats * chore: cleanup imports * test: improve tests of formats * chore: rename validator to oasFormatValidator * refactor: deprecate summary property * chore: add a comment * test: summary field * chore: comment on oclif & declare var
- Loading branch information
Showing
57 changed files
with
485 additions
and
223 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
58 changes: 58 additions & 0 deletions
58
src/__tests__/__fixtures__/petstore.invalid-schema.oas3.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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
openapi: 3.0.0 | ||
info: | ||
version: 1.0.0 | ||
title: Swagger Petstore | ||
license: | ||
name: MIT | ||
contact: | ||
email: bar@foo | ||
description: test | ||
servers: | ||
- url: 'http://petstore.swagger.io/v1' | ||
paths: | ||
/pets: | ||
get: | ||
summary: List all pets | ||
operationId: listPets | ||
description: test | ||
tags: | ||
- pets | ||
parameters: | ||
- name: limit | ||
in: query | ||
description: How many items to return at one time (max 100) | ||
required: false | ||
schema: | ||
type: integer | ||
format: int32 | ||
responses: | ||
'200': | ||
description: A paged array of pets | ||
headers: | ||
x-next: | ||
description: A link to the next page of responses | ||
schema: | ||
type: string | ||
header-1: | ||
type: string | ||
op: foo | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ./models/pet.yaml | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ../common/models/error.yaml | ||
components: | ||
schemas: | ||
Pets: | ||
type: array | ||
items: | ||
$ref: ./models/pet.yaml | ||
x-tags: | ||
- Pets | ||
title: Pets | ||
description: A list of pets. |
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,67 @@ | ||
import { stylish } from '../stylish'; | ||
|
||
const results = [ | ||
{ | ||
code: 'oas3-schema', | ||
summary: 'Validate structure of OpenAPIv3 specification.', | ||
message: 'should NOT have additional properties: type', | ||
path: ['paths', '/pets', 'get', 'responses', '200', 'headers', 'header-1'], | ||
severity: 0, | ||
source: '/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.invalid-schema.oas3.yaml', | ||
range: { | ||
start: { | ||
line: 35, | ||
character: 21, | ||
}, | ||
end: { | ||
line: 37, | ||
character: 21, | ||
}, | ||
}, | ||
}, | ||
{ | ||
code: 'oas3-schema', | ||
summary: 'Validate structure of OpenAPIv3 specification.', | ||
message: 'should match exactly one schema in oneOf', | ||
path: ['paths', '/pets', 'get', 'responses', '200', 'headers', 'header-1'], | ||
severity: 0, | ||
source: '/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.invalid-schema.oas3.yaml', | ||
range: { | ||
start: { | ||
line: 35, | ||
character: 21, | ||
}, | ||
end: { | ||
line: 37, | ||
character: 21, | ||
}, | ||
}, | ||
}, | ||
{ | ||
code: 'oas3-schema', | ||
summary: 'Validate structure of OpenAPIv3 specification.', | ||
message: "should have required property '$ref'", | ||
path: ['paths', '/pets', 'get', 'responses', '200', 'headers', 'header-1'], | ||
severity: 0, | ||
source: '/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.invalid-schema.oas3.yaml', | ||
range: { | ||
start: { | ||
line: 35, | ||
character: 21, | ||
}, | ||
end: { | ||
line: 37, | ||
character: 21, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
describe('Stylish formatter', () => { | ||
test('should prefer message for oas-schema errors', () => { | ||
const result = stylish(results); | ||
expect(result).toContain('oas3-schema should NOT have additional properties: type\n'); | ||
expect(result).toContain('oas3-schema should match exactly one schema in oneOf'); | ||
expect(result).toContain("oas3-schema should have required property '$ref'\n"); | ||
}); | ||
}); |
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,19 @@ | ||
export interface IMessageVars { | ||
property: string | number; | ||
error: string; | ||
description?: string; | ||
} | ||
|
||
export type MessageInterpolator = (values: IMessageVars) => string; | ||
|
||
export function message(strings: TemplateStringsArray, ...vars: Array<keyof IMessageVars>) { | ||
return (values: IMessageVars) => { | ||
const result = [strings[0]]; | ||
|
||
for (const [i, key] of vars.entries()) { | ||
result.push(String(values[key] || ''), strings[i + 1]); | ||
} | ||
|
||
return result.join(''); | ||
}; | ||
} |
Oops, something went wrong.