-
Notifications
You must be signed in to change notification settings - Fork 149
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
JSON schema parsing strips extra properties #5275
JSON schema parsing strips extra properties #5275
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Coverage report
Show files with reduced coverage 🔻
Test suite run success2015 tests passing in 905 suites. Report generated by 🧪jest coverage report action from 4007c75 |
We detected some changes at packages/*/src and there are no updates in the .changeset. |
ef6c4b7
to
ae8f1b5
Compare
13991f2
to
61faa92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small comment, but not blocking
61faa92
to
d92ad26
Compare
d92ad26
to
4007c75
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/json-schema.d.ts@@ -1,5 +1,6 @@
import { ParseConfigurationResult } from './schema.js';
import { ErrorObject, SchemaObject } from 'ajv';
+export type HandleInvalidAdditionalProperties = 'strip' | 'fail';
type AjvError = ErrorObject<string, {
[key: string]: unknown;
}>;
@@ -19,10 +20,11 @@ export declare function normaliseJsonSchema(schema: string): Promise<SchemaObjec
*
* @param subject - The object to validate.
* @param schema - The JSON schema to validate against.
+ * @param handleInvalidAdditionalProperties - Whether to strip or fail on invalid additional properties.
* @param identifier - The identifier of the schema being validated, used to cache the validator.
* @returns The result of the validation. If the state is 'error', the errors will be in a zod-like format.
*/
-export declare function jsonSchemaValidate(subject: object, schema: SchemaObject, identifier: string): ParseConfigurationResult<unknown> & {
+export declare function jsonSchemaValidate(subject: object, schema: SchemaObject, handleInvalidAdditionalProperties: HandleInvalidAdditionalProperties, identifier?: string): ParseConfigurationResult<unknown> & {
rawErrors?: AjvError[];
};
export {};
\ No newline at end of file
|
JSON schema validation is tweaked to strip additional properties that aren't parsed by the schema. This lets us use JSON schema to parse partial config objects, which is what we need for parsing app.toml from JSON schema only (otherwise, validation either has to fail, or we don't know what slice of the config was relevant to the schema)
I've preserved the existing behaviour as much as possible, and this is triggered only when UID strategy === single.