Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat add basic blok information if not specified #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const makeSBComponent = (schema: Record<string, any>) => ({
const prepareString = (str: string) => str.replace(/\s/g, "").trim();

const makeExpectString = (str: string) =>
prepareString(`export interface ResourceNameStoryblok {
prepareString(`export interface ResourceNameStoryblok {
${str}
_uid: string;
component: "ResourceName";
Expand Down Expand Up @@ -80,8 +80,8 @@ describe("storyblokToTypescript", () => {
});
const mainType = prepareString(types[2]);
const expectation = makeExpectString(`
myField?:any[];
myRequiredField:any[];
myField?:{_uid:string;[k:string]:any;}[];
myRequiredField:{_uid:string;[k:string]:any;}[];
`);

expect(mainType).toBe(expectation);
Expand All @@ -96,8 +96,8 @@ describe("storyblokToTypescript", () => {
});
const mainType = prepareString(types[2]);
const expectation = makeExpectString(`
myField?:number;
myRequiredField:number;
myField?:string;
myRequiredField:string;
`);

expect(mainType).toBe(expectation);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("storyblokToTypescript", () => {
});

const richtextType = prepareString(types[2])
const mainType = prepareString(types[3]);
const mainType = prepareString(types[3]);

const richtextTypeExpect = prepareString(`export interface RichtextStoryblok {
type: string;
Expand Down Expand Up @@ -192,7 +192,7 @@ describe("storyblokToTypescript", () => {
}),
});
const assetType = prepareString(types[2])
const mainType = prepareString(types[3]);
const mainType = prepareString(types[3]);

const assetTypeExpect = prepareString(`export interface AssetStoryblok {
alt?: string;
Expand Down Expand Up @@ -299,8 +299,8 @@ describe("storyblokToTypescript", () => {
}),
});

const assetType = prepareString(types[2]);
const mainType = prepareString(types[3]);
const assetType = prepareString(types[2]);
const mainType = prepareString(types[3]);

const assetTypeExpect =
prepareString(`export type MultiassetStoryblok = {
Expand Down Expand Up @@ -329,8 +329,8 @@ describe("storyblokToTypescript", () => {
}),
});

const tableType = prepareString(types[2]);
const mainType = prepareString(types[3]);
const tableType = prepareString(types[2]);
const mainType = prepareString(types[3]);

const tableTypeExpect = prepareString(`export interface TableStoryblok {
thead: {
Expand Down
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,18 @@ export default async function storyblokToTypescript({
case 'text':
return {type: 'string'}
case 'bloks':
return {type: 'array'}
return {
type: 'array',
items: {
type: 'object',
required: ['_uid'],
properties: {
_uid: {
type: 'string'
}
}
}
}
case 'number':
return {type: 'string'}
case 'image':
Expand Down