mirror of
https://github.com/LukeHagar/plex-api-spec.git
synced 2025-12-07 12:37:44 +00:00
27 lines
749 B
TypeScript
27 lines
749 B
TypeScript
import PMSSpec from "../../output/plex-media-server-spec-dereferenced.yaml"
|
|
import Ajv from "ajv"
|
|
import addFormats from "ajv-formats"
|
|
import { expect } from "vitest"
|
|
|
|
export function validateResponseSpec(
|
|
path: string,
|
|
type: "get" | "post" | "delete",
|
|
statusCode: number,
|
|
response: any
|
|
): void {
|
|
const ajv = new Ajv({ allErrors: true, strict: false })
|
|
ajv.addSchema(PMSSpec, "API.yaml")
|
|
addFormats(ajv)
|
|
|
|
// Convert JSONPath to JSON Pointer
|
|
const pathPointer = `/paths/${path.replace(/\//g, `~1`)}/${type}/responses/${statusCode}/content/application~1json/schema`
|
|
|
|
const validate = ajv.validate({ $ref: "API.yaml#" + pathPointer }, response)
|
|
|
|
if (!validate) {
|
|
console.error(ajv.errors)
|
|
}
|
|
|
|
expect(validate).toBe(true)
|
|
}
|