openapi: support additionalProperties: true/false boolean shorthand#310
openapi: support additionalProperties: true/false boolean shorthand#310
additionalProperties: true/false boolean shorthand#310Conversation
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
additionalProperties: true/false boolean shorthand
There was a problem hiding this comment.
Pull request overview
Adds support to the OpenAPI module’s schema parser/validator for the OpenAPI 3.0 / JSON Schema additionalProperties boolean shorthand, so specs using additionalProperties: true/false no longer fail to parse and are validated correctly at runtime.
Changes:
- Introduces an
openAPIAdditionalPropertiesunion type with YAML/JSON unmarshalling to support both boolean and schema-object forms. - Updates
openAPISchema.AdditionalPropertiesto use the new union type and extendsvalidateJSONBodyto implementtrue/false/ schema semantics. - Adds unit/integration tests covering parsing and request-validation behavior for the three forms.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
module/openapi.go |
Adds a union type for additionalProperties and updates request-body validation logic to enforce boolean/schema semantics. |
module/openapi_test.go |
Adds tests for YAML/JSON unmarshalling and request validation behavior for additionalProperties variants. |
| // Valid: extra key is a string | ||
| body := `{"name":"test","extra":"string-value"}` | ||
| w := httptest.NewRecorder() | ||
| r := httptest.NewRequest(http.MethodPost, "/typed-extra", strings.NewReader(body)) | ||
| r.Header.Set("Content-Type", "application/json") | ||
| h.Handle(w, r) | ||
|
|
||
| if w.Code == http.StatusBadRequest { | ||
| t.Errorf("expected string extra key to pass additionalProperties:{type:string}, got 400: %s", w.Body.String()) | ||
| } |
There was a problem hiding this comment.
The additionalProperties schema case test only covers the "valid extra" path. Adding a failing case (e.g. extra key value with the wrong type) would verify that extra keys are actually being validated against the provided schema, not just accepted.
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
|
@copilot apply changes based on the comments in this thread And fix the failing linter |
- Add bodyLabel prefix to additionalProperties:false error messages - Strengthen AdditionalProperties_True assertion to check for 200 (not just non-400) - Add invalid-type failing case to AdditionalProperties_Schema test - Fix gocritic ifElseChain lint issue in pipeline_step_graphql.go (from main) Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
All three review items are addressed in commit
The |
OpenAPI 3.0 allows
additionalPropertiesto be either a boolean or a schema object, but the module only handled the object form — causing a YAML parse error on any spec using the boolean shorthand.Changes
openAPIAdditionalPropertiesunion type (module/openapi.go) — wrapsbooland*openAPISchemawith customUnmarshalYAML,UnmarshalJSON, andMarshalJSONto handle both forms transparently.openAPISchema.AdditionalPropertieschanged from*openAPISchema→*openAPIAdditionalProperties.validateJSONBodyupdated to enforce all three semantics:true→ any extra keys permitted (no-op)false→ extra keys not inpropertiesare rejected with a validation error{…schema…}→ extra keys validated against the given schemaOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.