Skip to content

Support more JSON ContentTypes in isJSON#1274

Merged
duglin merged 2 commits intocloudevents:mainfrom
Evynglais:main
Apr 13, 2026
Merged

Support more JSON ContentTypes in isJSON#1274
duglin merged 2 commits intocloudevents:mainfrom
Evynglais:main

Conversation

@Evynglais
Copy link
Copy Markdown
Contributor

Adds support for other JSON Content-Types outside of those defined in content_type.go.

See: Issue

@Evynglais Evynglais requested a review from a team as a code owner April 10, 2026 14:39
@Evynglais Evynglais force-pushed the main branch 3 times, most recently from dbd47b9 to dcc94f6 Compare April 10, 2026 14:43
@embano1
Copy link
Copy Markdown
Member

embano1 commented Apr 11, 2026

Thx, overall LGTM. Pinging @duglin if there's some SPEC-specifics which we need to consider here.

Comment thread v2/event/content_type.go
"strings"
)

const (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are those consts still needed?

Copy link
Copy Markdown
Contributor Author

@Evynglais Evynglais Apr 13, 2026

Choose a reason for hiding this comment

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

They're used in the StringOfApplicationJSON(), StringOfApplicationXML(), etc. functions below (which are pretty widely used), and they're also used directly in numerous places too.

@Evynglais
Copy link
Copy Markdown
Contributor Author

Apologies, had to fix one of the test cases for invalid mediatype parameters. Have set it to ignore parameter issues, since this function doesn't use parameters (it won't block us from checking the subtype). Not sure how I missed that the first time!

Comment thread v2/event/content_type.go Outdated
}

// fallback to checking the suffix of the entire Content-Type:
return strings.HasSuffix(contentType, "json")
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.

I might be wrong, but I think needs to check for "/json" and not just "json" because otherwise a contentType of "foojson" would return true and I'm not sure that's what we want. Thoughts?

Let's add a test for "foojson" either way to make sure it always returns the correct result

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, added the test and made it check for /json. Thanks for the suggestion :)

@duglin
Copy link
Copy Markdown
Contributor

duglin commented Apr 13, 2026

looks good - just one minor suggestion

…nt-Types

Signed-off-by: Matthew Hehir <hehir45@googlemail.com>
@duglin
Copy link
Copy Markdown
Contributor

duglin commented Apr 13, 2026

I think you need to rebase

@Evynglais
Copy link
Copy Markdown
Contributor Author

I think you need to rebase

Done ✅

@duglin duglin enabled auto-merge April 13, 2026 13:10
@duglin duglin merged commit 9b26cc9 into cloudevents:main Apr 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants