Skip to content

Commit

Permalink
Stricter multilink typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearson committed Nov 1, 2023
1 parent 48dc396 commit 34cbc74
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 34cbc74

Please sign in to comment.