-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[openapi-response-validator] valid body fails incorrectly against allOf schemas with additionalProperties: false #609
Comments
i don't. would appreciate if you could jump in further to the code and see if you can fix it. |
👋 Thanks for the tools you've built. Has there been any forward momentum on this? I just ran into it using |
@mvegter and I have just reviewed this (for If everyone agrees, we can probably close this |
Yes, I also came to the conclusion that this is expected behavior. |
Hey, does anyone know how to restrict additional properties in inherited types (which is usually done with |
Hi @Envek , we ran into the same issue. We solved this by having a |
Finally I solved it by using json-schema-merge-allof library to preprocess existing schema. It works like a charm with code like this: import yaml from "js-yaml"
import { readFileSync } from "fs"
import mergeAllOf from "json-schema-merge-allof"
import $RefParser from "@apidevtools/json-schema-ref-parser"
const apiSpec = <Record<string, any>>yaml.safeLoad(readFileSync("./apiSchema.yaml").toString())
async function preprocessOpenapiSpec(apiSpec: Record<string, any>): Promise<Record<string, any>> {
const schema = await $RefParser.dereference(apiSpec)
function mergeAllOfRecursively(candidate: Record<string, any>, parent: Record<string, any>, k: any) {
if (typeof candidate !== "object") return
if (candidate.allOf) {
parent[k] = mergeAllOf(candidate, { ignoreAdditionalProperties: true, deep: true })
} else {
for (const [key, value] of Object.entries(candidate)) {
mergeAllOfRecursively(value, candidate, key)
}
}
}
for (const [key, value] of Object.entries(schema)) {
mergeAllOfRecursively(value, apiSpec, key)
}
return schema
}
const preprocessedApiSpec = await preprocessOpenapiSpec(apiSpec) See mokkabonna/json-schema-merge-allof#26 for more details about why it is so verbose 😄 |
Hi,
Thanks for this great package!
@rolfisub and I found a bug where if you validate a response body against
allOf
multiple schemas where one of them hasadditionalProperties: false
, then you get a failure (when you should get no failures).I.e., this test should pass:
But instead it fails with this error:
This bug seems to occur only in this specific case. For example, schemas with
additionalProperties: true
seem to work correctly, as do schemas withallOf
just one schema, withadditionalProperties: false
, e.g.:Looking at the code of openapi-response-validator, it seems that you outsource your validation to Ajv, which I guess is this one https://github.com/epoberezkin/ajv/issues?utf8=%E2%9C%93&q=additionalProperties. I see recent mention of unexpected errors for anyOf schemas with additionalProperties: false, but they were resolved 2 months ago, and I'm a bit out of my depth spotting the fix.
Before I raise an issue there, I wondered if you have any ideas/thoughts on this?
The text was updated successfully, but these errors were encountered: