-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sps-request-support-json - Accuracy and Testing (#42)
- Loading branch information
1 parent
4adca15
commit c5d374b
Showing
2 changed files
with
124 additions
and
4 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
114 changes: 114 additions & 0 deletions
114
rulesets/test/serialization/sps-request-support-json.test.js
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,114 @@ | ||
const { SpectralTestHarness } = require("../harness/spectral-test-harness.js"); | ||
|
||
describe("sps-request-support-json", () => { | ||
let spectral = null; | ||
const ruleName = "sps-request-support-json"; | ||
const ruleset = "src/serialization.ruleset.yml"; | ||
|
||
beforeEach(async () => { | ||
spectral = new SpectralTestHarness(ruleset); | ||
}); | ||
|
||
test("single application/json type successful", async () => { | ||
const spec = ` | ||
openapi: 3.0.1 | ||
paths: | ||
/v1/users/{id}: | ||
post: | ||
summary: Create User | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
description: The unique identifier for the system this user belongs to. | ||
format: uid | ||
example: 12345678-1234-1234-1234-123456789012 | ||
required: true | ||
responses: | ||
"201": | ||
description: User has been successfully created. | ||
`; | ||
|
||
await spectral.validateSuccess(spec, ruleName); | ||
}); | ||
|
||
test("no request parameters validate", async () => { | ||
const spec = ` | ||
openapi: 3.0.1 | ||
paths: | ||
/v1/users/{id}: | ||
post: | ||
summary: Create User | ||
responses: | ||
"201": | ||
description: User has been successfully created. | ||
`; | ||
|
||
await spectral.validateSuccess(spec, ruleName); | ||
}); | ||
|
||
test("multiple content types works with application/json", async () => { | ||
const spec = ` | ||
openapi: 3.0.1 | ||
paths: | ||
/v1/users: | ||
post: | ||
summary: Create User | ||
requestBody: | ||
content: | ||
multipart/form-data: | ||
schema: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
description: The unique identifier for the system this user belongs to. | ||
format: uid | ||
example: 12345678-1234-1234-1234-123456789012 | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
description: The unique identifier for the system this user belongs to. | ||
format: uid | ||
example: 12345678-1234-1234-1234-123456789012 | ||
required: true | ||
responses: | ||
"201": | ||
description: User has been successfully created. | ||
`; | ||
await spectral.validateSuccess(spec, ruleName); | ||
}); | ||
|
||
test("no application/json media type causses error", async () => { | ||
const spec = ` | ||
openapi: 3.0.1 | ||
paths: | ||
/v1/users: | ||
post: | ||
summary: Create User | ||
requestBody: | ||
content: | ||
multipart/form-data: | ||
schema: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
description: The unique identifier for the system this user belongs to. | ||
format: uid | ||
example: 12345678-1234-1234-1234-123456789012 | ||
required: true | ||
responses: | ||
"201": | ||
description: User has been successfully created. | ||
`; | ||
await spectral.validateFailure(spec, ruleName, "Error"); | ||
}); | ||
}); |