@@ -37,6 +37,7 @@ const NUMERIC_INDEX_PATTERN = "^[0-9]+$";
3737
3838export function getDefaultArgs ( ) : Args {
3939 return {
40+ avoidSymbolRefs : false ,
4041 ref : true ,
4142 aliasRef : false ,
4243 topRef : false ,
@@ -67,6 +68,7 @@ export type ValidationKeywords = {
6768} ;
6869
6970export type Args = {
71+ avoidSymbolRefs : boolean ;
7072 ref : boolean ;
7173 aliasRef : boolean ;
7274 topRef : boolean ;
@@ -1180,16 +1182,15 @@ export class JsonSchemaGenerator {
11801182 // Name already assigned?
11811183 return this . typeNamesById [ id ] ;
11821184 }
1183- return this . makeTypeNameUnique (
1184- typ ,
1185- this . tc
1186- . typeToString (
1187- typ ,
1188- undefined ,
1189- ts . TypeFormatFlags . NoTruncation | ts . TypeFormatFlags . UseFullyQualifiedType
1190- )
1191- . replace ( REGEX_FILE_NAME_OR_SPACE , "" )
1192- ) ;
1185+ const name = this . tc
1186+ . typeToString (
1187+ typ ,
1188+ undefined ,
1189+ ts . TypeFormatFlags . NoTruncation | ts . TypeFormatFlags . UseFullyQualifiedType
1190+ )
1191+ . replace ( REGEX_FILE_NAME_OR_SPACE , "" )
1192+
1193+ return this . makeTypeNameUnique ( typ , name ) ;
11931194 }
11941195
11951196 private makeTypeNameUnique ( typ : ts . Type , baseName : string ) : string {
@@ -1320,8 +1321,10 @@ export class JsonSchemaGenerator {
13201321 }
13211322 }
13221323
1324+ const avoidRef = this . args . avoidSymbolRefs && / [ ^ \d \w _ ] / . test ( fullTypeName )
1325+ asRef = asRef && ! avoidRef
13231326 // Handle recursive types
1324- if ( ! isRawType || ! ! typ . aliasSymbol ) {
1327+ if ( ! avoidRef && ( ! isRawType || ! ! typ . aliasSymbol ) ) {
13251328 if ( this . recursiveTypeRef . has ( fullTypeName ) && ! forceNotRef ) {
13261329 asRef = true ;
13271330 } else {
0 commit comments