Skip to content

Commit 569f492

Browse files
committed
[Bugfix] Fix comment emmission for closing comments in patternProperties keys (fix #546)
1 parent bf63b97 commit 569f492

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ function parseSchema(
414414
map(schema.patternProperties, (value, key: string) => {
415415
const ast = parse(value, options, key, processed, usedNames)
416416
const comment = `This interface was referenced by \`${parentSchemaName}\`'s JSON-Schema definition
417-
via the \`patternProperty\` "${key}".`
417+
via the \`patternProperty\` "${key.replace('*/', '*\\/')}".`
418418
ast.comment = ast.comment ? `${ast.comment}\n\n${comment}` : comment
419419
return {
420420
ast,

test/__snapshots__/test/test.ts.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,46 @@ Generated by [AVA](https://avajs.dev).
24372437
}␊
24382438
`
24392439

2440+
## patternProperties.7.js
2441+
2442+
> Expected output to match snapshot for e2e test: patternProperties.7.js
2443+
2444+
`/* eslint-disable */␊
2445+
/**␊
2446+
* This file was automatically generated by json-schema-to-typescript.␊
2447+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
2448+
* and run json-schema-to-typescript to regenerate this file.␊
2449+
*/␊
2450+
2451+
export interface PatternProperties {␊
2452+
/**␊
2453+
* This interface was referenced by \`PatternProperties\`'s JSON-Schema definition␊
2454+
* via the \`patternProperty\` "^[a-z][a-z0-9-]*\\/[a-z][a-z0-9-]*$".␊
2455+
*/␊
2456+
[k: string]: string;␊
2457+
}␊
2458+
`
2459+
2460+
## patternProperties.8.js
2461+
2462+
> Expected output to match snapshot for e2e test: patternProperties.8.js
2463+
2464+
`/* eslint-disable */␊
2465+
/**␊
2466+
* This file was automatically generated by json-schema-to-typescript.␊
2467+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
2468+
* and run json-schema-to-typescript to regenerate this file.␊
2469+
*/␊
2470+
2471+
export interface PatternProperties {␊
2472+
/**␊
2473+
* This interface was referenced by \`PatternProperties\`'s JSON-Schema definition␊
2474+
* via the \`patternProperty\` "^[a-z][a-z0-9-]/*[a-z][a-z0-9-]*$".␊
2475+
*/␊
2476+
[k: string]: string;␊
2477+
}␊
2478+
`
2479+
24402480
## realWorld.awsQuicksight.js
24412481

24422482
> Expected output to match snapshot for e2e test: realWorld.awsQuicksight.js

test/__snapshots__/test/test.ts.snap

-1.07 KB
Binary file not shown.

test/e2e/patternProperties.7.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @see https://github.com/bcherny/json-schema-to-typescript/issues/546
2+
export const input = {
3+
type: 'object',
4+
patternProperties: {
5+
'^[a-z][a-z0-9-]*/[a-z][a-z0-9-]*$': {
6+
type: 'string',
7+
},
8+
},
9+
}

test/e2e/patternProperties.8.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @see https://github.com/bcherny/json-schema-to-typescript/issues/546
2+
export const input = {
3+
type: 'object',
4+
patternProperties: {
5+
'^[a-z][a-z0-9-]/*[a-z][a-z0-9-]*$': {
6+
type: 'string',
7+
},
8+
},
9+
}

0 commit comments

Comments
 (0)