Definition of `Asset` type is wrong - failing content validation
See original GitHub issueExpected Behavior
Type definition of Asset
should match the actual content that is returned from the API.
Actual Behavior
sys
: Asset uses the general definition ofsys
, which requires acontentType
entry. However,Asset
does not include it. This is the main blocker for us (at Intercom).title
is declared asrequired
- but it is not required by Contentful’s App/UIdescription
is declared asrequired
- but it is not required by Contentful’s App/UI
Possible Solution
- Fork the definition of
sys
soAsset
could have it’s ownsys
definition which does not includecontentType
- Change definition of
title
anddescription
to be optional
Steps to Reproduce
- Create an Asset on Contentful (see that you can leave the
title
anddescription
empty) - Export the asset’s JSON (either by API or by reloading the Contentful page and inspecting the network request in the browser)
- See that the returned response does not contain a
contentType
node
Context
This blocks us from validating our content when deploying to production. Here at Intercom we “export” all the content (as JSON) through the Content Delivery API upon deployment - and validate everything with JSONSchema.
Up until now we were using “weak” validation that only verified the “fields” of each entry - but that allowed too many bad deployments (specifically - deployments with references to deleted entries).
To generate the JSON schema we use typescript-json-schema
.
Most of the TypeScript types used for the schema are generated by our code - except for Entry
and Asset
that are coming from this lib.
Having this fixed would allow us to spot content issues during deployment, thus have much greater confidence in our deployments and less incidents in production.
Environment
Since this is tied directly to the code definitions I don’t believe my environment is relevant here. Omitting this to reduce noise.
Related Issues and PRs
https://github.com/contentful/contentful.js/issues/208 https://github.com/contentful/contentful.js/pull/258 https://github.com/contentful/contentful.js/pull/206
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Hey @alonre @alextiley @magnattic, we have completely rewritten the client in Typescript. This also includes better type definitions for Asset
You can check it out on npm under the beta-v10 tag (go to the “Versions” tab to find it). The migration guide and updated v10 README and can be found on the beta-v10 branch. All details on the new Typescript features can be found here.
@magnattic
created a PR to also address this issue: https://github.com/contentful/contentful.js/pull/1240