Repository navigation
Conversation
Follow-up to the review of #16. The hand-written shape validator covered only the fields the commands happened to dereference, so matchPath, flattenAllOf, and the contract id, type, and declaredArtifact went unchecked: matchPath: null crashed both commands with no report, a bad regex crashed check, and flattenAllOf: null silently turned off --flatten-allof. - Add modules/openapi-compat/descriptor.py, which interprets schemas/contract-set.schema.json itself (the workflows install no Python packages). It implements exactly the keywords the schema uses (type, required, properties, items, additionalProperties, $ref, allOf, if/then, const, enum, pattern, minLength, minItems) and refuses to run if the schema gains another. One rule is stricter than the schema: matchPath must compile as a regular expression. - validate_descriptor() now delegates to it, so check and coverage enforce every schema rule up front with path-qualified errors, e.g. "spec.contracts[0].policy.flattenAllOf must be a boolean (true or false)". check also catches re.error as an integrity error. - Require non-empty oasdiffVersion and yqVersion in the schema (minLength 1); the commands already treated an empty pin as unpinned. - Rewrite test_schema.py to generate its cases from the schema: every property (including array items, additionalProperties, and both generator branches) omitted, given wrong-type values, and given values that break its const/enum/pattern/minLength/minItems rule; jsonschema and descriptor.py must agree on all of them. A test fails if VALID stops exercising a property or the schema uses an unimplemented keyword. - CLI tests through both commands for the reviewed cases. - Remove coverage's non-openapi contract warning, now unreachable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Edson Tirelli <etirelli@redhat.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #16, fixing the three issues from its last review (comment). All three predate #16.
matchPathwas not validated.matchPath: nullor1crashed both commands with aTypeErrorand no report.matchPath: "["crashedcheckwithre.error.flattenAllOfwas not checked as a boolean.nulland"false"passed, andnullsilently turned off--flatten-allof.id,typeanddeclaredArtifactwere not checked, and the parity table covered only selected fields.Approach
#16's hand-written validator covered only the fields the commands happened to read, so each review round found another gap. This PR enforces the schema itself instead.
modules/openapi-compat/descriptor.pyinterpretsschemas/contract-set.schema.jsonat run time. The workflows use the runner'spython3with no packages, so it doesn't depend on jsonschema.type,required,properties,items,additionalProperties,$ref,allOf,if/then,const,enum,pattern,minLengthandminItems.matchPathmust compile as a regular expression, because both commands use it as one.validate_descriptor()now delegates to it, socheckandcoverageenforce every schema rule before doing anything else. Errors name the field's path, for examplespec.contracts[0].policy.flattenAllOf must be a boolean (true or false), not str 'false'.checkalso catchesre.erroras an integrity error, as a second safeguard.oasdiffVersionandyqVersionnow require at least one character (minLength: 1). An empty pin was already treated as unpinned.openapitype is removed; the schema now rejects such contracts up front.Tests
modules/coverage/tests/test_schema.pynow generates its cases from the schema. It walks every property, including array items,additionalProperties, and both generatorif/thenbranches. Each property is omitted, given wrong-type values, and given values that break itsconst/enum/pattern/minLength/minItemsrule. jsonschema anddescriptor.pymust agree on all 285 generated cases.matchPathnull, int or bad regexflattenAllOfnull or a stringidmissing, a list or null;typemissing orprotobuf;declaredArtifacta listapiVersion,metadataandseverityOverridesvaluescheck, each one also writesreport.json.Verification
All 655 Python tests in the CI directories pass, mypy is clean, and the action-pin check and
actionlintpass. I also validated the descriptors in the onboarded repositories I could find (opendatahub-io/model-registry,opendatahub-io/odh-dashboard,red-hat-data-services/model-registryandred-hat-data-services/odh-dashboard). All pass both jsonschema and the new validator.model-registry-operatorruns coverage without a descriptor (CRD-only), which this change doesn't touch.Compatibility
No change for schema-valid descriptors. Descriptors the schema already rejects now fail both commands with exit 2 and a report. In v2.2.0, these passed or crashed:
matchPaththat isn't a string, or isn't a valid regex. These crashed, except a bad regex in coverage, which already exited 2.flattenAllOfthat isn't a boolean, which passed.id,typeordeclaredArtifact, or with a non-string value. These passed or reported gaps.typeother thanopenapi. Coverage warned;checkalready rejected it.apiVersionormetadata.name, which passed.severityOverrideslevel outsideinfo/warn/error. These were passed through to oasdiff.sourceGlobs, a generator missing a field its adapter requires, or an empty version pin.Some error messages change for cases that were already rejected. A missing
reasonis nowspec.exclusions[0].reason is required: record why, for reviewers; ..., and an unregistered adapter is now rejected by the schema'senumbefore reaching the adapter registry, which still fails closed on its own.🤖 Generated with Claude Code