Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@seriousme/openapi-schema-validator

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seriousme/openapi-schema-validator - npm Package Compare versions

Comparing version 2.1.4 to 2.1.5

test/validation/petstore-openapi.v3.1.json

4

CHANGELOG.md

@@ -6,2 +6,6 @@ # Changelog

## [v2.1.5] 16-11-2023
### Changed
- fix: validation after resolveRefs (tansin)
## [v2.1.4] 13-11-2023

@@ -8,0 +12,0 @@ ### Changed

2

index.d.ts

@@ -12,5 +12,5 @@ import { ErrorObject, Options } from "ajv";

}>;
addSpecRef(schema: object | string, uri: string): void;
addSpecRef(schema: object | string, uri: string): Promise<void>;
specification: object;
version: string;
}
{
"name": "@seriousme/openapi-schema-validator",
"version": "2.1.4",
"version": "2.1.5",
"description": "Validate OpenApi specifications against their JSON schema",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -110,3 +110,3 @@ function escapeJsonPointer(str) {

if (replace) {
obj[prop] = undefined;
delete obj[prop];
}

@@ -113,0 +113,0 @@ }

@@ -19,2 +19,3 @@ import { readFileSync } from "fs";

const yamlFileName = localFile("./validation/petstore-openapi.v3.yaml");
const jsonFileName = localFile("./validation/petstore-openapi.v3.1.json");
const mainSpecYamlFileName = localFile("./validation/main-spec.v3.yaml");

@@ -120,2 +121,47 @@ const subSpecYamlFileName = localFile("./validation/sub-spec.v3.yaml");

test("json string validation works", async (t) => {
const jsonSpec = await readFile(jsonFileName, "utf-8");
const validator = new Validator();
const res = await validator.validate(jsonSpec);
assert.equal(res.valid, true, "json spec as string is valid");
const ver = validator.version;
assert.equal(ver, "3.1", "json spec version matches expected version");
});
test("object validation works", async (t) => {
const jsonSpec = await readFile(jsonFileName, "utf-8");
const objectSpec = JSON.parse(jsonSpec);
const validator = new Validator();
const res = await validator.validate(objectSpec);
assert.equal(res.valid, true, "spec as object is valid");
const ver = validator.version;
assert.equal(ver, "3.1", "object spec version matches expected version");
});
test("multiple consecutive object validations work", async (t) => {
const jsonSpec = await readFile(jsonFileName, "utf-8");
const objectSpec = JSON.parse(jsonSpec);
const validator = new Validator();
const res = await validator.validate(objectSpec);
assert.equal(res.valid, true, "spec as object is valid in round 1");
const res2 = await validator.validate(objectSpec);
assert.equal(res2.valid, true, "spec as object is valid in round 2");
const ver = validator.version;
assert.equal(ver, "3.1", "object spec version matches expected version");
});
test("re-validation of validator.specification works", async (t) => {
const validator = new Validator();
const res = await validator.validate(jsonFileName);
assert.equal(res.valid, true, "spec is valid in round 1");
const res2 = await validator.validate(validator.specification);
assert.equal(res2.valid, true, "spec as object is valid in round 2");
const ver = validator.version;
assert.equal(ver, "3.1", "object spec version matches expected version");
});
test("Invalid yaml specification as string gives an error", async (t) => {

@@ -254,1 +300,38 @@ const yamlSpec = `

});
test("re-validation works after resolving refs", async (t) => {
const validator = new Validator();
await validator.addSpecRef(subSpecYamlFileName, subSpecUri);
await validator.addSpecRef(subSpec2YamlFileName);
const res = await validator.validate(mainSpecYamlFileName);
assert.equal(res.valid, true, "main spec + subspec is valid");
assert.equal(
validator.specification[inlinedRefs][subSpecUri].components.requestBodies
.Pet.required,
true,
);
assert.equal(
validator.specification[inlinedRefs][subSpecUri2].get.summary,
"Finds Pets by status",
);
validator.resolveRefs();
const res2 = await validator.validate(validator.specification);
assert.equal(
res2.valid,
true,
"main spec + subspec is valid after resolving refs",
);
assert.equal(
validator.specification.paths["/pet"].post.requestBody.required,
true,
"$refs from main spec to sub spec are correctly resolved",
);
assert.equal(
validator.specification.paths["/pet/findByStatus"].get.summary,
"Finds Pets by status",
"$refs from main spec to sub2 spec are correctly resolved",
);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc