Skip to content

docs: restrict string's length for openAPI SDK to prevent API rejection#8009

Open
afsuyadi wants to merge 5 commits into
Flagsmith:mainfrom
afsuyadi:fix/add-max-char-length
Open

docs: restrict string's length for openAPI SDK to prevent API rejection#8009
afsuyadi wants to merge 5 commits into
Flagsmith:mainfrom
afsuyadi:fix/add-max-char-length

Conversation

@afsuyadi

@afsuyadi afsuyadi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have filled in the "Changes" section below.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7995

  1. Use existing constant TRAIT_STRING_VALUE_MAX_LENGTH to restrict the string's length.
  2. Build a function for post-processing the hook and detecting trait_value to return the desired result
  3. Call the function during API calling
  4. Update yaml file with maxLength

How did you test this code?

  1. Build unit tests with various schemas to ensure reliable results

@afsuyadi
afsuyadi requested review from a team as code owners July 15, 2026 06:14
@afsuyadi
afsuyadi requested review from emyller and removed request for a team July 15, 2026 06:14
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

@afsuyadi is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an OpenAPI post-processing hook that applies TRAIT_STRING_VALUE_MAX_LENGTH to the string variant of trait_value schemas. Registers the hook in the API settings, adds unit tests for matching and absent schema cases, and updates the generated OpenAPI specification for identity trait request and response schemas with maxLength: 2000.

Estimated code review effort: 3 (Moderate) | ~20 minutes


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e55b56d and 231c559.

📒 Files selected for processing (4)
  • api/api/openapi.py
  • api/app/settings/common.py
  • api/tests/unit/api/test_unit_openapi.py
  • sdk/openapi.yaml

Comment on lines +273 to +310
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"},
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: SDK OpenAPI spec no longer documents the 2000-character trait value limit

1 participant