-
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.
Merge pull request #120 from seriousme/add-ref-check-to-validation
Add ref check to validation
- Loading branch information
Showing
7 changed files
with
103 additions
and
12 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
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
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,21 @@ | ||
import { strict as assert } from "node:assert/strict"; | ||
import { test } from "node:test"; | ||
import { URL, fileURLToPath } from "url"; | ||
import { Validator } from "../index.js"; | ||
|
||
function localFile(fileName) { | ||
return fileURLToPath(new URL(fileName, import.meta.url)); | ||
} | ||
|
||
const invalidRefsSpec = localFile("./validation/invalid-refs.yaml"); | ||
|
||
test("invalid refs in YAML fail validation", async (t) => { | ||
const validator = new Validator(); | ||
const res = await validator.validate(invalidRefsSpec); | ||
assert.equal(res.valid, false, "validation fails"); | ||
assert.equal( | ||
res.errors, | ||
"Can't resolve #/components/schemas/nonExisting1, only internal refs are supported.", | ||
"correct error message", | ||
); | ||
}); |
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,38 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: test | ||
version: 1.0.0 | ||
paths: | ||
/get: | ||
get: | ||
summary: test | ||
description: test | ||
parameters: | ||
- name: param | ||
in: query | ||
description: param | ||
required: true | ||
schema: | ||
type: string | ||
example: "foo" | ||
responses: | ||
"200": | ||
description: Successful response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/nonExisting1" | ||
components: | ||
schemas: | ||
testObject: | ||
type: object | ||
properties: | ||
prop1: | ||
type: string | ||
searchResults: | ||
type: object | ||
properties: | ||
testObjects: | ||
type: array | ||
items: | ||
$ref: "#/components/schemas/nonExisting2" |