Skip to content

feat: enforce lowercase opengraph property names BED-8071#2805

Open
computator wants to merge 4 commits into
mainfrom
BED-8071--lowercase-og-property-names
Open

feat: enforce lowercase opengraph property names BED-8071#2805
computator wants to merge 4 commits into
mainfrom
BED-8071--lowercase-og-property-names

Conversation

@computator

@computator computator commented May 21, 2026

Copy link
Copy Markdown
Member

Description

  • Updated the OpenGraph node and edge schemas to enforce property key names with a regex pattern
  • Updated the OpenGraph edge schema to enforce property_matchers[].key values with a regex pattern

Character Set

It is not realistic to implement this solely by checking for and rejecting uppercase characters, especially if enforcement is done via the schema files. Since enforcing lowercase will be a breaking change anyway, we decided to go with a character set that only allows lowercase Latin letters, numbers, dash, and underscore (a-z0-9_-). We also set the maximum length as 128 characters.

UI Error Discoverability

These changes use the same mechanism for reporting errors that all the other OpenGraph validation code uses. As such, the validation errors appear in the API logs and the HTTP response body. The UI however does not always surface these errors to the user. It did not seem logical to special-case this error to make it appear in the UI, and seemed more appropriate to create a separate ticket to surface all validation errors in the UI regardless of cause.

Motivation and Context

Resolves BED-8071

Not all systems that OpenGraph will interact with are case sensitive, so we are standardizing on lowercase property names.

How Has This Been Tested?

Uploaded some test data to verify it was rejected, and ran created tests locally.

Screenshots (optional):

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Summary by CodeRabbit

  • Bug Fixes

    • Strengthened validation for property names in uploaded data: keys must be 1–128 chars, lowercase letters, digits, hyphens or underscores. Uploads with invalid property names are now rejected during validation.
  • Tests

    • Added negative test cases to ensure invalid property keys (uppercase, empty, spaces, overly long) are rejected for both node and edge data.

@computator computator self-assigned this May 21, 2026
@computator computator added api A pull request containing changes affecting the API code. go Pull requests that update go code labels May 21, 2026
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds property name validation constraints to node and edge ingest schemas. The propertyNames regex ^[a-z0-9_-]{1,128}$ restricts object attribute keys to lowercase alphanumerics, underscores, and hyphens with length 1–128. Test cases verify the schemas reject uppercase, empty, space-containing, and over-length property keys.

Changes

Property name validation

Layer / File(s) Summary
Property name validation schema constraints
cmd/api/src/services/upload/jsonschema/edge.json, cmd/api/src/services/upload/jsonschema/node.json
Node and edge property_map definitions add propertyNames/pattern constraints restricting keys to ^[a-z0-9_-]{1,128}$ (lowercase alphanumerics, hyphens, underscores; length 1–128).
Schema validation test cases
cmd/api/src/services/upload/streamdecoder_test.go
Test cases verify schema validation rejects node and edge property keys and property_matchers[].key values that are uppercase, empty, contain spaces, or exceed 128 characters.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: enforcing lowercase names for OpenGraph properties, matching the primary objective of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering all major template sections including motivation, testing approach, and completed checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8071--lowercase-og-property-names

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@computator computator added the enhancement New feature or request label May 21, 2026
@computator computator marked this pull request as ready for review May 29, 2026 00:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/api/src/services/upload/jsonschema/edge.json`:
- Around line 24-26: Confirm validation uses raw map keys (no normalization) by
noting streamdecoder.go calls schema.Validate(item) directly and that only
bomenc.NormalizeToUTF8 is applied; then add negative test cases asserting keys
with '.' and ':' are rejected by the edge schema (jsonschema/edge.json enforcing
propertyNames.pattern "^[a-z0-9_-]{1,128}$"), adding tests similar to the
existing uppercase/empty/space/length failures that expect schema validation to
fail and assert the error text contains the schema/propertyNames violation (or
the same error substring used by other negative cases).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 2fc12455-b8b4-434c-b6b7-158ebec22070

📥 Commits

Reviewing files that changed from the base of the PR and between 378d0ed and 616ac3d.

📒 Files selected for processing (3)
  • cmd/api/src/services/upload/jsonschema/edge.json
  • cmd/api/src/services/upload/jsonschema/node.json
  • cmd/api/src/services/upload/streamdecoder_test.go

Comment thread cmd/api/src/services/upload/jsonschema/edge.json

@urangel urangel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks to be failing the upload with a 400 as expected! 🙌

Since there have been a few updates that are not in the ticket, would you please add some notes on the changes so that we track the expectations accordingly? Mostly around the chosen pattern and the UI display related details.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cmd/api/src/services/upload/streamdecoder_test.go (1)

1205-1272: ⚡ Quick win

Remove redundant element type in composite literals (gofmt -s).

In each new case the slice element type is already declared, so repeating propertyMatcher{...} inside []propertyMatcher{...} is redundant. gofmt -s (and likely CI's format check) will flag/rewrite these on lines 1213, 1230, 1247, and 1264.

♻️ Proposed simplification (apply to all four occurrences)
-						End: &edgePiece{MatchBy: "property", PropertyMatchers: []propertyMatcher{
-							propertyMatcher{Key: "TESTKey", Operator: "equals", Value: "asdf"},
-						}},
+						End: &edgePiece{MatchBy: "property", PropertyMatchers: []propertyMatcher{
+							{Key: "TESTKey", Operator: "equals", Value: "asdf"},
+						}},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/api/src/services/upload/streamdecoder_test.go` around lines 1205 - 1272,
The composite literals in the test cases repeat the element type inside the
slice (e.g., []propertyMatcher{ propertyMatcher{...} }) which is redundant;
update each occurrence to use the short form by removing the inner type so the
slices read []propertyMatcher{ {...} } (apply to the four cases constructing
PropertyMatchers in the testPayload/Edges where propertyMatcher is used) and run
gofmt -s to ensure formatting passes CI; search for propertyMatcher in this test
to locate all spots.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/api/src/services/upload/streamdecoder_test.go`:
- Around line 1205-1272: The composite literals in the test cases repeat the
element type inside the slice (e.g., []propertyMatcher{ propertyMatcher{...} })
which is redundant; update each occurrence to use the short form by removing the
inner type so the slices read []propertyMatcher{ {...} } (apply to the four
cases constructing PropertyMatchers in the testPayload/Edges where
propertyMatcher is used) and run gofmt -s to ensure formatting passes CI; search
for propertyMatcher in this test to locate all spots.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: acde173a-d170-45d9-9dcd-6ff51260288f

📥 Commits

Reviewing files that changed from the base of the PR and between 616ac3d and e55666b.

📒 Files selected for processing (2)
  • cmd/api/src/services/upload/jsonschema/edge.json
  • cmd/api/src/services/upload/streamdecoder_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/api/src/services/upload/jsonschema/edge.json

@computator

Copy link
Copy Markdown
Member Author

@urangel I added information about the character set and error discoverability to the PR description!

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

Labels

api A pull request containing changes affecting the API code. enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants