@@ -1414,7 +1414,7 @@ export class JsonSchemaGenerator {
14141414 // We don't return the full definition, but we put it into
14151415 // reffedDefinitions below.
14161416 returnedDefinition = {
1417- $ref : ` ${ this . args . id } #/definitions/` + fullTypeName ,
1417+ $ref : createRefURI ( this . args . id , fullTypeName ) ,
14181418 } ;
14191419 }
14201420
@@ -1519,7 +1519,7 @@ export class JsonSchemaGenerator {
15191519 } , { } ) ;
15201520
15211521 returnedDefinition = {
1522- $ref : ` ${ this . args . id } #/definitions/` + fullTypeName ,
1522+ $ref : createRefURI ( this . args . id , fullTypeName ) ,
15231523 ...annotations ,
15241524 } ;
15251525 }
@@ -1640,6 +1640,22 @@ export class JsonSchemaGenerator {
16401640 }
16411641}
16421642
1643+ /**
1644+ * Generates the reference URI to the definition in the schema `id`
1645+ * containing the definition `name`.
1646+ *
1647+ * Encodes the `name` using `encodeURIComponent`.
1648+ *
1649+ * @see https://datatracker.ietf.org/doc/html/rfc3986
1650+ * @param id the id of the schema containing the definition
1651+ * @param name the name of the definition
1652+ * @returns the URI pointing to the definition in the schema
1653+ */
1654+ function createRefURI ( id : string , name : string ) : string {
1655+ const encoded = encodeURIComponent ( name ) ;
1656+ return `${ id } #/definitions/${ encoded } ` ;
1657+ }
1658+
16431659export function getProgramFromFiles (
16441660 files : string [ ] ,
16451661 jsonCompilerOptions : any = { } ,
0 commit comments