docs: restrict string's length for openAPI SDK to prevent API rejection#8009
docs: restrict string's length for openAPI SDK to prevent API rejection#8009afsuyadi wants to merge 5 commits into
Conversation
|
@afsuyadi is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
for more information, see https://pre-commit.ci
📝 WalkthroughWalkthroughAdds an OpenAPI post-processing hook that applies Estimated code review effort: 3 (Moderate) | ~20 minutes Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 667e6886-aa87-4c07-b324-35c958fa1715
📒 Files selected for processing (4)
api/api/openapi.pyapi/app/settings/common.pyapi/tests/unit/api/test_unit_openapi.pysdk/openapi.yaml
| def test_postprocessing_add_trait_value_max_length__string_variant__adds_max_length() -> ( | ||
| None | ||
| ): | ||
| # Given | ||
| result: dict[str, Any] = { | ||
| "components": { | ||
| "schemas": { | ||
| "TraitInput": { | ||
| "properties": { | ||
| "trait_value": { | ||
| "anyOf": [ | ||
| {"type": "integer"}, | ||
| {"type": "number"}, | ||
| {"type": "boolean"}, | ||
| {"type": "string"}, | ||
| {"type": "null"}, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| # When | ||
| postprocessing_add_trait_value_max_length(result, generator=None) | ||
|
|
||
| # Then | ||
| trait_value_schema = result["components"]["schemas"]["TraitInput"]["properties"][ | ||
| "trait_value" | ||
| ] | ||
| assert trait_value_schema["anyOf"] == [ | ||
| {"type": "integer"}, | ||
| {"type": "number"}, | ||
| {"type": "boolean"}, | ||
| {"type": "string", "maxLength": TRAIT_STRING_VALUE_MAX_LENGTH}, | ||
| {"type": "null"}, | ||
| ] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
Cover both request and response trait schemas.
This test exercises only TraitInput, while the contract also requires Trait.trait_value to be constrained. Add a second matching component, or assert the generated schema, so the traversal cannot regress to updating only the request schema.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #7995
trait_valueto return the desired resultmaxLengthHow did you test this code?