fix: handle boolean false for UrlPattern and UrlPrefix in ContentTypeOptions#25
Merged
demeyerthom merged 2 commits intoMay 15, 2026
Merged
Conversation
…Options The Contentstack API returns false (boolean) for string fields that are unset, rather than omitting them or returning an empty string. This caused json.Unmarshal to fail with 'cannot unmarshal bool into string'. Introduce FlexString, a string type with a custom UnmarshalJSON that accepts both JSON strings and booleans (treating false as empty string). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
demeyerthom
requested changes
May 15, 2026
Member
demeyerthom
left a comment
There was a problem hiding this comment.
Hi @rasmus-lisborg-19! Would you mind adding some tests to check if the unmarshal works as intended?
Contributor
Author
|
Apologies - might have been a bit too keen, I'll have a look now 👍 |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Tests added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Contentstack API returns `false` (boolean) for `url_pattern` and `url_prefix` fields when they are unset, rather than omitting them or returning an empty string. Since these fields are typed as `string` in `ContentTypeOptions`, `json.Unmarshal` fails with:
```
json: cannot unmarshal bool into Go struct field ContentTypeOptions.content_type.options.url_pattern of type string
```
This error occurs on any Read/Import of a content type that does not have `url_pattern` configured.
Fix
Introduce `FlexString`, a `string` type with a custom `UnmarshalJSON` that accepts both JSON strings and JSON booleans (treating `false` as empty string). Change `UrlPattern` and `UrlPrefix` to use `FlexString`.
Notes
`FlexString` marshals as a plain string so no changes are needed on the write path.
BUG FIXES