Skip to content

Commit

Permalink
feat(codegen): support contentful v7.14.2 and above
Browse files Browse the repository at this point in the history
Contentful changed their typings for `space` in a minor version update, meaning that users of this library had incorrect types.

BREAKING CHANGE: Drops compatibility with `contentful` versions lower than 7.14.2

Closes #26 but blocked by contentful/contentful.js#398
  • Loading branch information
Steven Petryk committed Apr 16, 2020
1 parent 96d29a7 commit 6d290be
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/renderers/contentful/renderContentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ function renderSys(sys: Sys) {
createdAt: string;
updatedAt: string;
locale: string;
space: {
sys: SpaceLink;
}
contentType: {
sys: {
id: '${sys.id}';
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/contentful/renderContentfulImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ export default function renderContentfulImports(localization: boolean = false):
return `
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Entry } from 'contentful'
import { Entry, SpaceLink } from 'contentful'
import { Document } from '@contentful/rich-text-types'
`
}

return `
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Asset, Entry } from 'contentful'
import { Asset, Entry, SpaceLink } from 'contentful'
import { Document } from '@contentful/rich-text-types'
`
}
49 changes: 26 additions & 23 deletions test/renderers/contentful/renderContentType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,32 @@ describe("renderContentType()", () => {

it("works with miscellaneous field types", () => {
expect(format(renderContentType(contentType, false))).toMatchInlineSnapshot(`
"export interface IMyContentTypeFields {
/** Symbol Field™ */
symbolField?: string | undefined;
"export interface IMyContentTypeFields {
/** Symbol Field™ */
symbolField?: string | undefined;
/** Array field */
arrayField: (\\"one\\" | \\"of\\" | \\"the\\" | \\"above\\")[];
}
/** Array field */
arrayField: (\\"one\\" | \\"of\\" | \\"the\\" | \\"above\\")[];
}
export interface IMyContentType extends Entry<IMyContentTypeFields> {
sys: {
id: string,
type: string,
createdAt: string,
updatedAt: string,
locale: string,
contentType: {
sys: {
id: \\"myContentType\\",
linkType: \\"ContentType\\",
type: \\"Link\\"
}
}
};
}"
`)
export interface IMyContentType extends Entry<IMyContentTypeFields> {
sys: {
id: string,
type: string,
createdAt: string,
updatedAt: string,
locale: string,
space: SpaceLink,
contentType: {
sys: {
id: \\"myContentType\\",
linkType: \\"ContentType\\",
type: \\"Link\\"
}
}
};
}"
`)
})

it("supports descriptions", () => {
Expand All @@ -96,6 +97,7 @@ describe("renderContentType()", () => {
createdAt: string,
updatedAt: string,
locale: string,
space: SpaceLink,
contentType: {
sys: {
id: \\"myContentType\\",
Expand Down Expand Up @@ -125,6 +127,7 @@ describe("renderContentType()", () => {
createdAt: string,
updatedAt: string,
locale: string,
space: SpaceLink,
contentType: {
sys: {
id: \\"myContentType\\",
Expand Down
4 changes: 2 additions & 2 deletions test/renderers/contentful/renderContentfulImports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("renderContentfulImports()", () => {
expect(format(renderContentfulImports())).toMatchInlineSnapshot(`
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Asset, Entry } from \\"contentful\\";
import { Asset, Entry, SpaceLink } from \\"contentful\\";
import { Document } from \\"@contentful/rich-text-types\\";"
`)
})
Expand All @@ -15,7 +15,7 @@ describe("renderContentfulImports()", () => {
expect(format(renderContentfulImports(true))).toMatchInlineSnapshot(`
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Entry } from \\"contentful\\";
import { Entry, SpaceLink } from \\"contentful\\";
import { Document } from \\"@contentful/rich-text-types\\";"
`)
})
Expand Down
15 changes: 12 additions & 3 deletions test/renderers/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("render()", () => {
expect(await render(contentTypes, locales)).toMatchInlineSnapshot(`
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Asset, Entry } from \\"contentful\\"
import { Asset, Entry, SpaceLink } from \\"contentful\\"
import { Document } from \\"@contentful/rich-text-types\\"
export interface IMyContentTypeFields {
Expand All @@ -70,6 +70,9 @@ describe("render()", () => {
createdAt: string
updatedAt: string
locale: string
space: {
sys: SpaceLink
}
contentType: {
sys: {
id: \\"myContentType\\"
Expand Down Expand Up @@ -125,7 +128,7 @@ describe("render()", () => {
expect(await render(contentTypes, locales, { localization: true })).toMatchInlineSnapshot(`
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Entry } from \\"contentful\\"
import { Entry, SpaceLink } from \\"contentful\\"
import { Document } from \\"@contentful/rich-text-types\\"
export interface IMyContentTypeFields {
Expand All @@ -140,6 +143,9 @@ describe("render()", () => {
createdAt: string
updatedAt: string
locale: string
space: {
sys: SpaceLink
}
contentType: {
sys: {
id: \\"myContentType\\"
Expand Down Expand Up @@ -187,7 +193,7 @@ describe("render()", () => {
expect(await render(contentTypes, locales, { namespace: "Codegen" })).toMatchInlineSnapshot(`
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
import { Asset, Entry } from \\"contentful\\"
import { Asset, Entry, SpaceLink } from \\"contentful\\"
import { Document } from \\"@contentful/rich-text-types\\"
declare namespace Codegen {
Expand All @@ -203,6 +209,9 @@ describe("render()", () => {
createdAt: string
updatedAt: string
locale: string
space: {
sys: SpaceLink
}
contentType: {
sys: {
id: \\"myContentType\\"
Expand Down

0 comments on commit 6d290be

Please sign in to comment.