Skip to content

Commit

Permalink
Merge pull request #57 from cjpearson/fix-multilink
Browse files Browse the repository at this point in the history
Stricter multilink typing
  • Loading branch information
dohomi authored Nov 1, 2023
2 parents 48dc396 + 34cbc74 commit 06c373d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 0 additions & 11 deletions src/genericTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ async function generateMultiLinkTypeIfNotYetGenerated(title: string, compilerOpt
$id: '#/multilink',
title: title,
'oneOf': [
{
type: 'object',
properties: {
cached_url: {
type: 'string'
},
linktype: {
type: 'string'
}
}
},
{
type: 'object',
properties: {
Expand Down
17 changes: 16 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,22 @@ export default async function storyblokToTypescript({

obj[key] = element

if (TYPES.includes(type)) {
if (type === 'multilink') {
const excludedLinktypes = [];
const baseType = camelcase(getTitle(type), {
pascalCase: true
})

if (!schemaElement.email_link_type) {
excludedLinktypes.push('{ linktype?: "email" }');
}
if (!schemaElement.asset_link_type) {
excludedLinktypes.push('{ linktype?: "asset" }');
}

obj[key].tsType = excludedLinktypes.length ?
`Exclude<${baseType}, ${excludedLinktypes.join(' | ')}>` : baseType
} else if (TYPES.includes(type)) {
obj[key].tsType = camelcase(getTitle(type), {
pascalCase: true
})
Expand Down

0 comments on commit 06c373d

Please sign in to comment.