@@ -37,6 +37,7 @@ const NUMERIC_INDEX_PATTERN = "^[0-9]+$";
37
37
38
38
export function getDefaultArgs ( ) : Args {
39
39
return {
40
+ avoidSymbolRefs : false ,
40
41
ref : true ,
41
42
aliasRef : false ,
42
43
topRef : false ,
@@ -67,6 +68,7 @@ export type ValidationKeywords = {
67
68
} ;
68
69
69
70
export type Args = {
71
+ avoidSymbolRefs : boolean ;
70
72
ref : boolean ;
71
73
aliasRef : boolean ;
72
74
topRef : boolean ;
@@ -1180,16 +1182,15 @@ export class JsonSchemaGenerator {
1180
1182
// Name already assigned?
1181
1183
return this . typeNamesById [ id ] ;
1182
1184
}
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 ) ;
1193
1194
}
1194
1195
1195
1196
private makeTypeNameUnique ( typ : ts . Type , baseName : string ) : string {
@@ -1320,8 +1321,10 @@ export class JsonSchemaGenerator {
1320
1321
}
1321
1322
}
1322
1323
1324
+ const avoidRef = this . args . avoidSymbolRefs && / [ ^ \d \w _ ] / . test ( fullTypeName )
1325
+ asRef = asRef && ! avoidRef
1323
1326
// Handle recursive types
1324
- if ( ! isRawType || ! ! typ . aliasSymbol ) {
1327
+ if ( ! avoidRef && ( ! isRawType || ! ! typ . aliasSymbol ) ) {
1325
1328
if ( this . recursiveTypeRef . has ( fullTypeName ) && ! forceNotRef ) {
1326
1329
asRef = true ;
1327
1330
} else {
0 commit comments