Repository navigation
Conversation
What: adds the validateModelAdditionalProperties option (default: false): a named schema in components/schemas that is an object - either explicitly (type: object) or inferred from declared properties - should declare additionalProperties, as either a boolean or a schema. Schemas of other types, compositions without properties of their own (e.g. an allOf used for inheritance) and empty properties maps are not affected. Why: when additionalProperties is absent, whether an object accepts properties outside of the spec is left to the implementation, so models can silently accept undocumented properties (OpenAPITools#741). The rule is opt-in because most existing specs do not declare the keyword on every object, so flagging them by default would be too noisy. How: new AdditionalPropertiesValidator (lib) invoked from validateModels() behind the new flag; ModelStyleError.toString() omits the property part when a finding concerns the schema itself rather than one of its properties (same hardening as PR OpenAPITools#811); option wired through ValidatorParameters, the CLI options file, the Gradle plugin task and the Maven plugin mojo; README options table and sample specs/options.json updated. Tests use plain @test methods: junit-jupiter-params is declared testCompileOnly in the root build.gradle, so @ParameterizedTest methods compile but are silently skipped at runtime. Fixes OpenAPITools#741 Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 17 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
… objects with no properties What: testAllGetterSetters now sets validateModelAdditionalProperties to true and asserts it - the false it assigned before was already the value provided by the factory, so the setter was never exercised with a state change. Adds a case for an explicit `type: object` with an empty properties map: the declared type makes it an object, so it is reported like any other object without additionalProperties. Only the inferred path (no `type` keyword) needs a non-empty properties map to count as an object. Why: addresses the two review notes on PR OpenAPITools#812. Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
This branch has not been deployed
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
This adds a new model rule, enabled by the
validateModelAdditionalPropertiesoption, that flags named schemas incomponents/schemaswhich are objects but do not declareadditionalProperties- neither a boolean nor a schema.A schema counts as an object when it says so explicitly (
type: object) or when it declares properties (thetypekeyword is optional in that case). Schemas of other types, compositions that declare no properties of their own (e.g. anallOfused for inheritance) and empty properties maps are left alone.The rule is opt-in,
falseby default: most existing specs do not declareadditionalPropertieson every object, so flagging them by default would be too noisy for a validator that enables everything else out of the box. Users who want the strictness can turn it on in their options file (CLI), Gradle extension or Maven configuration. A finding looks like:Why
When
additionalPropertiesis absent, whether an object accepts properties that are not listed in the spec is left to the implementation (see the Schema Object definition). Declaring the keyword makes the contract explicit - that is what #741 asks for.How
AdditionalPropertiesValidatorinlib, invoked fromvalidateModels()behind the new flag, in the same style as the discriminator ruleModelStyleError.toString()now omits the property part when a finding concerns the schema itself rather than one of its properties (same hardening as Validate that oneOf and anyOf compositions define a discriminator #811 - model-level findings have no property name, and the old format printedproperty 'null')ValidatorParameters, the CLI options file, the Gradle plugin task and the Maven plugin mojo, with the default documented in the README options table and in the samplespecs/options.jsontrue,falseor as a schema) and the opt-in behavior (no violation with default parameters, none when the rule is disabled)The wiring follows #809, #810 and #811 as precedent.
One implementation note: the new tests use plain
@Testmethods on purpose.junit-jupiter-paramsis declaredtestCompileOnlyin the rootbuild.gradle, so@ParameterizedTestmethods compile but are silently skipped at runtime (this affects the existing parameterized tests too - happy to see that fixed in a separate change).The full suite (
./gradlew build, including the Gradle plugin functional tests and the Maven plugin integration test) is green.Fixes #741
Summary by cubic
Adds an opt-in model rule that flags named object schemas in
components/schemaswhich do not declareadditionalProperties. The rule is off by default (validateModelAdditionalProperties: false) because most existing specs omit the keyword; when the keyword is absent, whether an object accepts properties outside the spec is left to the implementation. Enable it via the CLI options file, Gradle task, or Maven mojo to make object contracts explicit.type: object(even with no properties) or when it declares properties without a type; other types, compositions without properties of their own, and inferred objects with empty properties maps are ignored.additionalPropertiesas a boolean or a schema satisfies the rule.property 'null'in the error message.ValidatorParameters, the CLI, the Gradle plugin, and the Maven plugin.Fixes #741.
Written for commit 77b4c80. Summary will update on new commits.