Skip to content

fix: handle boolean false for UrlPattern and UrlPrefix in ContentTypeOptions#25

Merged
demeyerthom merged 2 commits into
labd:mainfrom
rasmus-lisborg-19:fix/flex-string-options
May 15, 2026
Merged

fix: handle boolean false for UrlPattern and UrlPrefix in ContentTypeOptions#25
demeyerthom merged 2 commits into
labd:mainfrom
rasmus-lisborg-19:fix/flex-string-options

Conversation

@rasmus-lisborg-19
Copy link
Copy Markdown
Contributor

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

  • Fix panic/error when unmarshalling content type options where `url_pattern` or `url_prefix` is returned as boolean `false` by the API

…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>
Copy link
Copy Markdown
Member

@demeyerthom demeyerthom left a comment

Choose a reason for hiding this comment

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

Hi @rasmus-lisborg-19! Would you mind adding some tests to check if the unmarshal works as intended?

@rasmus-lisborg-19
Copy link
Copy Markdown
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>
@rasmus-lisborg-19
Copy link
Copy Markdown
Contributor Author

Tests added

Copy link
Copy Markdown
Member

@demeyerthom demeyerthom left a comment

Choose a reason for hiding this comment

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

Thanks for adding!

@demeyerthom demeyerthom merged commit 85d0191 into labd:main May 15, 2026
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.

2 participants