diff --git a/bun.lockb b/bun.lockb index 2936b047..eb247b80 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 04181641..9d2fa54a 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "devDependencies": { "@modyfi/vite-plugin-yaml": "^1.1.0", "@redocly/cli": "^1.23.1", + "@types/lodash-es": "^4.17.12", "@types/node": "^22.5.0", "chokidar-cli": "^3.0.0", "prettier": "3.3.3", @@ -41,6 +42,7 @@ }, "dependencies": { "ajv": "^8.17.1", - "ajv-formats": "^3.0.1" + "ajv-formats": "^3.0.1", + "lodash-es": "^4.17.21" } } diff --git a/src/models/UserPlexAccount.yaml b/src/models/UserPlexAccount.yaml index 9e04bcd5..17f41a45 100644 --- a/src/models/UserPlexAccount.yaml +++ b/src/models/UserPlexAccount.yaml @@ -128,6 +128,7 @@ required: - twoFactorEnabled - username - uuid + - attributionPartner properties: adsConsent: type: @@ -329,3 +330,8 @@ properties: type: string description: The account UUID example: dae343c1f45beb4f + attributionPartner: + type: + - string + - "null" + example: null diff --git a/tests/utils/import.ts b/tests/utils/import.ts index 4ba83cf4..a087ffa0 100644 --- a/tests/utils/import.ts +++ b/tests/utils/import.ts @@ -2,7 +2,7 @@ import PMSSpec from "../../output/plex-media-server-spec-dereferenced.yaml" import Ajv from "ajv" import addFormats from "ajv-formats" import { expect } from "vitest" - +import { merge } from "lodash-es" /** * Validate a response against the OpenAPI spec * NOTE: It accounts for the following scenarios: @@ -24,7 +24,7 @@ export function validateResponseSpec( const schema = PMSSpec - addAdditionalPropertiesFalse(schema.paths) + addAdditionalProperties(schema.paths) ajv.addSchema(schema, "API.yaml") addFormats(ajv) @@ -42,16 +42,24 @@ export function validateResponseSpec( } /** - * Recursively add additionalProperties: false to all objects in the schema + * Recursively add additionalProperties: false to all objects in the schema and merge allOf schemas * This is necessary to ensure that the schema is strict and does not allow additional properties without explicitly defined in the openApi spec * DOC: https://ajv.js.org/json-schema.html#additionalproperties * @param schema */ -function addAdditionalPropertiesFalse(schema) { +function addAdditionalProperties(schema) { if (schema === null || typeof schema !== "object") { return } + // If the current schema has allOf, merge the schemas because AJV handles mentions of allOf as separate schemas that all need to pass at the same time. We use it in the spec to combine multiple schemas into one. + // DOC: https://ajv.js.org/json-schema.html#allof + if (schema.hasOwnProperty("allOf")) { + const merged = merge({}, ...schema.allOf) + delete schema.allOf + Object.assign(schema, merged) + } + // If the current schema defines an object, ensure additionalProperties is false if (schema.hasOwnProperty("type") && schema.type === "object") { if (!schema.hasOwnProperty("additionalProperties")) { @@ -62,11 +70,11 @@ function addAdditionalPropertiesFalse(schema) { // Recursively handle properties if they exist for (const [_, value] of Object.entries(schema)) { if (Array.isArray(value)) { - value.forEach((x) => addAdditionalPropertiesFalse(x)) + value.forEach((x) => addAdditionalProperties(x)) } if (typeof value === "object") { - addAdditionalPropertiesFalse(value) + addAdditionalProperties(value) } } }