Skip to content

Commit

Permalink
fix: Quote unsafe property names in languages that support it
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacivita committed Aug 21, 2024
1 parent 756e88a commit 647043d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions languages/javascript/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"/index.mjs",
"/defaults.mjs"
],
"enableStringPropertyKeys": true,
"createModuleDirectories": true,
"copySchemasIntoModules": true,
"aggregateFiles": [
Expand Down
6 changes: 4 additions & 2 deletions src/macrofier/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ const insertObjectPatternPropertiesMacros = (content, schema, module, title, opt
}

const getIndents = level => level ? ' ' : ''
const wrapProp = name => name.match(/[/\.\+]/) ? `"${name}"` : name
const safePropName = name => config.enableStringPropertyKeys ? wrapProp(name) : getSafeEnumKeyName(name)
const insertObjectMacros = (content, schema, module, title, property, options) => {
const options2 = options ? JSON.parse(JSON.stringify(options)) : {}
options2.parent = title
Expand Down Expand Up @@ -348,8 +350,8 @@ const insertObjectMacros = (content, schema, module, title, property, options) =
const description = getSchemaDescription(prop, module)
let replacedTemplate = template
.replace(/(^\s+)/g, '$1'.repeat(options2.level))
.replace(/\$\{property\}/g, name)
.replace(/\$\{Property\}/g, capitalize(name))
.replace(/\$\{property\}/g, safePropName(name))
.replace(/\$\{Property\}/g, capitalize(safePropName(name)))
.replace(/\$\{parent\.title\}/g, title)
.replace(/\$\{title\}/g, type)
.replace(/\$\{shape\}/g, schemaShape)
Expand Down

0 comments on commit 647043d

Please sign in to comment.