Skip to content

Commit

Permalink
feat(ts): added '--ts-non-exported' flag to define strategy for what …
Browse files Browse the repository at this point in the history
…to do with non-exported types

fix #26
  • Loading branch information
grantila committed Jun 18, 2022
1 parent 0009532 commit 5e75186
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/bin/typeconv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ExportRefMethod } from 'suretype'
import { userPackage, userPackageUrl } from "../package"
import { TypeImplementation } from "../types"
import { ensureType } from "../utils"
import { FromTsOptions } from "core-types-ts"


type SureTypeMissingRef = JsonSchemaToSuretypeOptions[ 'missingReference' ];
Expand Down Expand Up @@ -162,6 +163,30 @@ const oppaInstance =
description: "Use 'unknown' type instead of 'any'",
default: true,
} )
.add( {
name: 'ts-non-exported',
type: 'string',
argumentName: 'method',
description: "Strategy for non-exported types",
default: 'include-if-referenced',
values: [
{ 'fail': "Fail conversion" },
{ 'ignore': [
"Don't include non-exported types,",
"even if referenced",
] },
{ 'include': "Include non-exported types" },
{ 'inline': [
"Don't include non-exported types, ",
"inline them if necessary.",
"Will fail on cyclic types"
] },
{ 'include-if-referenced': [
"Include non-exported types only if they",
"are referenced from exported types",
] },
],
} )

.group( {
name: "GraphQL",
Expand Down Expand Up @@ -323,6 +348,7 @@ const {
"ts-disable-lint-header": tsDisableLintHeader,
"ts-descriptive-header": tsDescriptiveHeader,
"ts-use-unknown": tsUseUnknown,
"ts-non-exported": tsNonExported,

// JSON Schema

Expand Down Expand Up @@ -368,6 +394,14 @@ if ( !ensureType< TypeImplementation >(
) )
throw new Error( );

if ( !ensureType< FromTsOptions[ 'nonExported' ] >(
tsNonExported,
'ts-non-exported',
[ 'fail', 'ignore', 'include', 'inline', 'include-if-referenced' ],
printHelp
) )
throw new Error( );

if ( !ensureType< ExportRefMethod | undefined >(
stRefMethod,
'ref-method',
Expand All @@ -387,7 +421,9 @@ if ( !ensureType< SureTypeMissingRef | undefined >(
const getReader = ( ): Reader =>
{
return fromType === 'ts'
? getTypeScriptReader( )
? getTypeScriptReader( {
nonExported: tsNonExported,
} )
: fromType === 'jsc'
? getJsonSchemaReader( )
: fromType === 'oapi'
Expand Down

0 comments on commit 5e75186

Please sign in to comment.