Skip to content

Commit

Permalink
[Bugfix] Fix comment emmission for closing comments in patternPropert…
Browse files Browse the repository at this point in the history
…ies keys (fix #546)
  • Loading branch information
bcherny committed Jan 14, 2024
1 parent bf63b97 commit 569f492
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function parseSchema(
map(schema.patternProperties, (value, key: string) => {
const ast = parse(value, options, key, processed, usedNames)
const comment = `This interface was referenced by \`${parentSchemaName}\`'s JSON-Schema definition
via the \`patternProperty\` "${key}".`
via the \`patternProperty\` "${key.replace('*/', '*\\/')}".`
ast.comment = ast.comment ? `${ast.comment}\n\n${comment}` : comment
return {
ast,
Expand Down
40 changes: 40 additions & 0 deletions test/__snapshots__/test/test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,46 @@ Generated by [AVA](https://avajs.dev).
}␊
`

## patternProperties.7.js

> Expected output to match snapshot for e2e test: patternProperties.7.js

`/* eslint-disable */␊
/**␊
* This file was automatically generated by json-schema-to-typescript.␊
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
* and run json-schema-to-typescript to regenerate this file.␊
*/␊
export interface PatternProperties {␊
/**␊
* This interface was referenced by \`PatternProperties\`'s JSON-Schema definition␊
* via the \`patternProperty\` "^[a-z][a-z0-9-]*\\/[a-z][a-z0-9-]*$".␊
*/␊
[k: string]: string;␊
}␊
`

## patternProperties.8.js

> Expected output to match snapshot for e2e test: patternProperties.8.js

`/* eslint-disable */␊
/**␊
* This file was automatically generated by json-schema-to-typescript.␊
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
* and run json-schema-to-typescript to regenerate this file.␊
*/␊
export interface PatternProperties {␊
/**␊
* This interface was referenced by \`PatternProperties\`'s JSON-Schema definition␊
* via the \`patternProperty\` "^[a-z][a-z0-9-]/*[a-z][a-z0-9-]*$".␊
*/␊
[k: string]: string;␊
}␊
`

## realWorld.awsQuicksight.js

> Expected output to match snapshot for e2e test: realWorld.awsQuicksight.js
Expand Down
Binary file modified test/__snapshots__/test/test.ts.snap
Binary file not shown.
9 changes: 9 additions & 0 deletions test/e2e/patternProperties.7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @see https://github.com/bcherny/json-schema-to-typescript/issues/546
export const input = {
type: 'object',
patternProperties: {
'^[a-z][a-z0-9-]*/[a-z][a-z0-9-]*$': {
type: 'string',
},
},
}
9 changes: 9 additions & 0 deletions test/e2e/patternProperties.8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @see https://github.com/bcherny/json-schema-to-typescript/issues/546
export const input = {
type: 'object',
patternProperties: {
'^[a-z][a-z0-9-]/*[a-z][a-z0-9-]*$': {
type: 'string',
},
},
}

0 comments on commit 569f492

Please sign in to comment.