Repository navigation
Conversation
…losed schema forbids or a path or query value off its enum
…h ref chains, compositions and wrong-shaped values, and enums match by value
… sent as, and a closed object's shape, and sends composed bodies unvalidated
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab1f6f19ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| val name = if (at.isEmpty()) "$key" else "$at.$key" | ||
| val declared = resolved.properties?.get(key.toString()) | ||
| when { | ||
| declared != null -> bodyViolation(declared, child, name) | ||
| resolved.additionalProperties == false -> | ||
| "Request body property '$name' is not declared by the operation's schema, which allows no other properties" | ||
| else -> bodyViolation(resolved.additionalProperties as? Schema<*>, child, name) |
There was a problem hiding this comment.
Validate bracketed form keys against their effective nested paths
For a form-encoded operation with an open root and a closed nested payload object, {"body":{"payload[secret]":"x"}} passes this check because payload[secret] is treated as an unrelated, permitted root property. However, toFormBody emits that key unchanged, so a server using the bracket notation supported by this client's serializer interprets it as payload.secret. This allows a forbidden nested write to reach the server despite the closed schema. Normalize or reject bracketed aliases before validating form bodies.
Useful? React with 👍 / 👎.
| val items = (value as? Collection<*>)?.filterNotNull() ?: listOf(value) | ||
| val allowed = (enum == null || enum.any { enumMatches(it, value) } || items.all { v -> enum.any { enumMatches(it, v) } }) && | ||
| (itemEnum == null || items.all { v -> itemEnum.any { enumMatches(it, v) } }) |
There was a problem hiding this comment.
Match array-valued enums only against the whole array
When a query schema declares an array-valued enum, the item-by-item fallback accepts values outside that enum. For example, with enum: [["a","b"]], input {"q":[["a","b"]]} passes because its single item matches an enum entry, although the supplied outer array does not; {"q":[]} also passes vacuously. resolveQueryParams then sends these inputs instead of refusing them. Keep whole-value enum validation separate from items.enum validation rather than allowing either interpretation to satisfy the same constraint.
Useful? React with 👍 / 👎.
| else -> if (closed) { | ||
| "$what is not an object where the operation's schema expects a closed object" |
There was a problem hiding this comment.
Require an object type before rejecting non-object values
A schema containing properties and additionalProperties: false without type: object does not prohibit arrays or scalars: those keywords constrain object instances only. This branch nevertheless rejects every non-null, non-map value, so previously working requests with valid array or scalar values are now refused locally. It also rejects an explicitly array-typed schema carrying additionalProperties: false. Distinguish an explicitly required object shape from object-specific keywords before issuing this refusal.
Useful? React with 👍 / 👎.
An OpenAPI operation call is now checked against the operation's schema before it is sent. A call that breaks the schema is refused, and nothing is sent.
Why
A realm narrows a vendor API by declaring closed write bodies (
additionalProperties: false). For example,realm-hubspot'sdealUpdatemust not setdealstage: a stage move goes only through an operation that needs approval. Today the client ignores the closed schema, sodealUpdate {properties: {dealstage}}reaches HubSpot and moves the deal without approval (embabel-worlds/realm-hubspot#4).What changes (
OpenApiOperationTool)additionalProperties: falseis refused, at any depth. The check follows$refchains,allOf,oneOfandanyOf, and names the offending path, e.g.properties.dealstage.Live, against HubSpot, the refusal reads "Request body property 'properties.dealstage' is not declared by the operation's schema, which allows no other properties; the request was not sent".
Tests
OpenApiArgumentValidationTestandOpenApiArgumentShapeValidationTestare new.mvn -B -pl embabel-api-client testpasses 328 tests.Not covered (follow-up issues)
Shapes HubSpot doesn't use, tracked in #58:
payload[secret]) can alias a closed nested object;additionalProperties: falsewithouttypeis treated as an object, so a valid array is rejected;#31 also edits
OpenApiOperationTool(path parameters fail fast), so whichever merges second will need a rebase.