-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to align generated firebolt.d.ts sync with same is next branch
- Loading branch information
1 parent
5e8edf3
commit 1ee9fde
Showing
7 changed files
with
240 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
[1mdiff --git a/languages/javascript/templates/parameters/annotations.js b/languages/javascript/templates/parameters/annotations.js[m | ||
[1mindex d5b667d..23d285d 100644[m | ||
[1m--- a/languages/javascript/templates/parameters/annotations.js[m | ||
[1m+++ b/languages/javascript/templates/parameters/annotations.js[m | ||
[36m@@ -1 +1 @@[m | ||
[31m- * @param {${method.param.type}} ${method.param.name} ${method.param.summary}[m | ||
[32m+[m[32m * @param {${method.param.type}12345} ${method.param.name} ${method.param.summary}[m | ||
[1mdiff --git a/languages/javascript/templates/types/property.mjs b/languages/javascript/templates/types/property.mjs[m | ||
[1mindex fac92c9..66bf6f7 100644[m | ||
[1m--- a/languages/javascript/templates/types/property.mjs[m | ||
[1m+++ b/languages/javascript/templates/types/property.mjs[m | ||
[36m@@ -1 +1 @@[m | ||
[31m- ${property}${if.optional}?${end.if.optional}: ${title} // ${summary}[m | ||
[32m+[m[32m ${property}${if.optional}?${end.if.optional}: ${title}${if.summary} // ${summary}${end.if.summary}[m | ||
[1mdiff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs[m | ||
[1mindex cbdf066..490abe1 100644[m | ||
[1m--- a/src/macrofier/engine.mjs[m | ||
[1m+++ b/src/macrofier/engine.mjs[m | ||
[36m@@ -935,7 +935,7 @@[m [mfunction generateSchemas(json, templates, options) {[m | ||
else {[m | ||
content = content.replace(/\$\{if\.description\}(.*?)\{end\.if\.description\}/gms, '$1')[m | ||
}[m | ||
[31m- const schemaShape = types.getSchemaShape(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: options.section })[m | ||
[32m+[m[32m const schemaShape = types.getSchemaShape(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: options.section, primitive: config.primitives ? Object.keys(config.primitives).length > 0 : false })[m | ||
[m | ||
content = content[m | ||
.replace(/\$\{schema.title\}/, (schema.title || name))[m | ||
[1mdiff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs[m | ||
[1mindex 9d22fe4..55ef7b7 100644[m | ||
[1m--- a/src/macrofier/types.mjs[m | ||
[1m+++ b/src/macrofier/types.mjs[m | ||
[36m@@ -168,9 +168,22 @@[m [mconst getXSchemaGroup = (schema, module) => {[m | ||
return group[m | ||
}[m | ||
[m | ||
[32m+[m[32mfunction getSchemaDescription(schema, module) {[m | ||
[32m+[m[32m let description = schema.description || ''[m | ||
[32m+[m[32m if (schema.type === 'array' && schema.items) {[m | ||
[32m+[m[32m schema = schema.items[m | ||
[32m+[m[32m }[m | ||
[32m+[m[32m if (schema['$ref'] && (schema['$ref'][0] === '#')) {[m | ||
[32m+[m[32m const refSchema = getPath(schema['$ref'], module)[m | ||
[32m+[m[32m description = (refSchema && refSchema.description) || description[m | ||
[32m+[m[32m }[m | ||
[32m+[m[32m return description[m | ||
[32m+[m[32m}[m | ||
[32m+[m | ||
function insertSchemaMacros(content, schema, module, { name = '', parent = '', property = '', required = false, recursive = true, templateDir = 'types'}) {[m | ||
const title = name || schema.title || ''[m | ||
[31m- let moduleTitle = getXSchemaGroup(schema, module)[m | ||
[32m+[m[32m const moduleTitle = getXSchemaGroup(schema, module)[m | ||
[32m+[m[32m const description = getSchemaDescription(schema, module)[m | ||
[m | ||
content = content[m | ||
.replace(/\$\{title\}/g, title)[m | ||
[36m@@ -181,10 +194,11 @@[m [mfunction insertSchemaMacros(content, schema, module, { name = '', parent = '', p[m | ||
.replace(/\$\{if\.namespace\.notsame}(.*?)\$\{end\.if\.namespace\.notsame\}/g, (module.info.title !== (parent || moduleTitle)) ? '$1' : '')[m | ||
.replace(/\$\{parent\.title\}/g, parent || moduleTitle)[m | ||
.replace(/\$\{parent\.Title\}/g, capitalize(parent || moduleTitle))[m | ||
[31m- .replace(/\$\{description\}/g, schema.description ? schema.description : '')[m | ||
[32m+[m[32m .replace(/\$\{description\}/g, description)[m | ||
.replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, (Array.isArray(required) ? required.includes(property) : required) ? '' : '$1')[m | ||
.replace(/\$\{if\.non.optional\}(.*?)\$\{end\.if\.non.optional\}/gms, (Array.isArray(required) ? required.includes(property) : required) ? '$1' : '')[m | ||
[31m- .replace(/\$\{summary\}/g, schema.description ? schema.description.split('\n')[0] : '')[m | ||
[32m+[m[32m .replace(/\$\{if\.summary\}(.*?)\$\{end\.if\.summary\}/gms, description ? '$1' : '')[m | ||
[32m+[m[32m .replace(/\$\{summary\}/g, description ? description.split('\n')[0] : '')[m | ||
.replace(/\$\{name\}/g, title)[m | ||
.replace(/\$\{NAME\}/g, title.toUpperCase())[m | ||
.replace(/\$\{info.title\}/g, moduleTitle)[m | ||
[36m@@ -329,6 +343,7 @@[m [mconst insertObjectMacros = (content, schema, module, title, property, options) =[m | ||
const type = getSchemaType(localizedProp, module, options2)[m | ||
// don't push properties w/ unsupported types[m | ||
if (type) {[m | ||
[32m+[m[32m const description = getSchemaDescription(prop, module)[m | ||
let replacedTemplate = template[m | ||
.replace(/(^\s+)/g, '$1'.repeat(options2.level))[m | ||
.replace(/\$\{property\}/g, name)[m | ||
[36m@@ -336,8 +351,9 @@[m [mconst insertObjectMacros = (content, schema, module, title, property, options) =[m | ||
.replace(/\$\{parent\.title\}/g, title)[m | ||
.replace(/\$\{title\}/g, type)[m | ||
.replace(/\$\{shape\}/g, schemaShape)[m | ||
[31m- .replace(/\$\{description\}/g, prop.description || '')[m | ||
[31m- .replace(/\$\{summary\}/g, prop.description ? prop.description.split('\n')[0] : '')[m | ||
[32m+[m[32m .replace(/\$\{description\}/g, description)[m | ||
[32m+[m[32m .replace(/\$\{if\.summary\}(.*?)\$\{end\.if\.summary\}/gms, description ? '$1' : '')[m | ||
[32m+[m[32m .replace(/\$\{summary\}/g, description ? description.split('\n')[0] : '')[m | ||
.replace(/\$\{delimiter\}(.*?)\$\{end.delimiter\}/gms, i === schema.properties.length - 1 ? '' : '$1')[m | ||
.replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '' : '$1')[m | ||
.replace(/\$\{if\.non.optional\}(.*?)\$\{end\.if\.non.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '$1' : '')[m | ||
[36m@@ -347,6 +363,7 @@[m [mconst insertObjectMacros = (content, schema, module, title, property, options) =[m | ||
.replace(/\$\{if\.non\.anyOf\}(.*?)\$\{end\.if\.non\.anyOf\}/gms, (localizedProp.anyOf || localizedProp.anyOneOf) ? '' : '$1')[m | ||
.replace(/\$\{if\.non\.const\}(.*?)\$\{end\.if\.non\.const\}/gms, (typeof localizedProp.const === 'string') ? '' : '$1')[m | ||
let baseTitle = options.property[m | ||
[32m+[m | ||
if (isObject(localizedProp)) {[m | ||
replacedTemplate = replacedTemplate[m | ||
.replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '' : '$1')[m | ||
[36m@@ -398,14 +415,16 @@[m [mconst insertObjectMacros = (content, schema, module, title, property, options) =[m | ||
if (type) {[m | ||
options2.property = prop[m | ||
const schemaShape = getSchemaShape(type, module, options2)[m | ||
[32m+[m[32m const description = getSchemaDescription(prop, module)[m | ||
properties.push(template[m | ||
.replace(/\$\{property\}/g, getSafeEnumKeyName(prop))[m | ||
.replace(/\$\{Property\}/g, capitalize(getSafeEnumKeyName(prop)))[m | ||
.replace(/\$\{parent\.title\}/g, title)[m | ||
.replace(/\$\{title\}/g, getSchemaType(type, module, options2))[m | ||
.replace(/\$\{shape\}/g, schemaShape)[m | ||
[31m- .replace(/\$\{description\}/g, prop.description || '')[m | ||
[31m- .replace(/\$\{summary\}/g, prop.description ? prop.description.split('\n')[0] : '')[m | ||
[32m+[m[32m .replace(/\$\{description\}/g, description)[m | ||
[32m+[m[32m .replace(/\$\{if\.summary\}(.*?)\$\{end\.if\.summary\}/gms, description ? '$1' : '')[m | ||
[32m+[m[32m .replace(/\$\{summary\}/g, description ? description.split('\n')[0] : '')[m | ||
.replace(/\$\{delimiter\}(.*?)\$\{end.delimiter\}/gms, i === propertyNames.enum.length - 1 ? '' : '$1')[m | ||
.replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, schema.required && schema.required.includes(prop) ? '' : '$1')[m | ||
.replace(/\$\{if\.non.optional\}(.*?)\$\{end\.if\.non.optional\}/gms, schema.required && schema.required.includes(prop) ? '$1' : ''))[m | ||
[36m@@ -451,6 +470,7 @@[m [mconst insertTupleMacros = (content, schema, module, title, options) => {[m | ||
[m | ||
const doMacroWork = (str, prop, i, indent) => {[m | ||
const schemaShape = getSchemaShape(prop, module, options)[m | ||
[32m+[m[32m const description = getSchemaDescription(prop, module)[m | ||
[m | ||
return (i !== 0 ? indent : '') + str[m | ||
.replace(/\$\{property\}/g, prop['x-property'])[m | ||
[36m@@ -458,8 +478,9 @@[m [mconst insertTupleMacros = (content, schema, module, title, options) => {[m | ||
.replace(/\$\{parent\.title\}/g, title)[m | ||
.replace(/\$\{shape\}/g, schemaShape)[m | ||
.replace(/\$\{title\}/g, getSchemaType(prop, module, options))[m | ||
[31m- .replace(/\$\{description\}/g, prop.description || '')[m | ||
[31m- .replace(/\$\{summary\}/g, prop.description ? prop.description.split('\n')[0] : '')[m | ||
[32m+[m[32m .replace(/\$\{description\}/g, description)[m | ||
[32m+[m[32m .replace(/\$\{if\.summary\}(.*?)\$\{end\.if\.summary\}/gms, description ? '$1' : '')[m | ||
[32m+[m[32m .replace(/\$\{summary\}/g, description ? description.split('\n')[0] : '')[m | ||
.replace(/\$\{delimiter\}(.*?)\$\{end.delimiter\}/g, i === schema.items.length - 1 ? '' : '$1')[m | ||
.replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, '')[m | ||
.replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, '')[m | ||
[36m@@ -471,9 +492,9 @@[m [mconst insertTupleMacros = (content, schema, module, title, options) => {[m | ||
return content[m | ||
}[m | ||
[m | ||
[31m-const getPrimitiveType = (type, templateDir = 'types') => {[m | ||
[32m+[m[32mconst getPrimitiveType = (type, templateDir = 'types', title = false) => {[m | ||
const template = getTemplate(path.join(templateDir, type)) || getTemplate(path.join(templateDir, 'generic'))[m | ||
[31m- return (primitives[type] || template)[m | ||
[32m+[m[32m return (title ? template : primitives[type] || template)[m | ||
}[m | ||
[m | ||
const pickBestType = types => Array.isArray(types) ? types.find(t => t !== 'null') : types[m | ||
[36m@@ -511,7 +532,7 @@[m [mconst sanitize = (schema) => {[m | ||
return result[m | ||
}[m | ||
[m | ||
[31m-function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', parent = '', property = '', required = false, parentLevel = 0, level = 0, summary, descriptions = true, destination, section, enums = true, skipTitleOnce = false, array = false, primitive = false } = {}) {[m | ||
[32m+[m[32mfunction getSchemaShape(schema = {}, module = {}, { templateDir = 'types', parent = '', property = '', required = false, parentLevel = 0, level = 0, summary, descriptions = true, destination, section, enums = true, skipTitleOnce = false, array = false, primitive = false, type = false } = {}) {[m | ||
schema = sanitize(schema)[m | ||
state.destination = destination[m | ||
state.section = section[m | ||
[36m@@ -522,7 +543,7 @@[m [mfunction getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren[m | ||
const suffix = destination && ('.' + destination.split('.').pop()) || ''[m | ||
const theTitle = insertSchemaMacros(getTemplate(path.join(templateDir, 'title' + suffix)), schema, module, { name: schema.title, parent, property, required, recursive: false })[m | ||
[m | ||
[31m- let result = level === 0 && !primitive ? getTemplate(path.join(templateDir, 'default' + suffix)) : '${shape}'[m | ||
[32m+[m[32m let result = getTemplate(path.join(templateDir, 'default' + suffix)) || '${shape}'[m[41m [m | ||
[m | ||
let genericTemplate = getTemplate(path.join(templateDir, 'generic' + suffix))[m | ||
if (enums && level === 0 && Array.isArray(schema.enum) && ((schema.type === "string") || (schema.type[0] === "string"))) {[m | ||
[36m@@ -857,8 +878,10 @@[m [mfunction getSchemaType(schema, module, { destination, templateDir = 'types', lin[m | ||
// TODO: this assumes that when type is an array of types, that it's one other primative & 'null', which isn't necessarily true.[m | ||
const schemaType = !Array.isArray(schema.type) ? schema.type : schema.type.find(t => t !== 'null')[m | ||
const baseDir = (templateDir !== 'json-types' ? 'types': templateDir)[m | ||
[31m- const primitive = getPrimitiveType(schemaType, baseDir)[m | ||
[32m+[m[32m let primitive = getPrimitiveType(schemaType, baseDir, schema.title ? true: false)[m | ||
[32m+[m[32m primitive = primitive ? primitive.replace(/\$\{title\}/g, schema.title) : primitive[m | ||
const type = allocatedProxy ? allocatedPrimitiveProxies[schemaType] || primitive : primitive[m | ||
[32m+[m | ||
return wrap(type, code ? '`' : '')[m | ||
}[m | ||
}[m | ||
[1mdiff --git a/src/shared/typescript.mjs b/src/shared/typescript.mjs[m | ||
[1mindex 930549f..28e8008 100644[m | ||
[1m--- a/src/shared/typescript.mjs[m | ||
[1m+++ b/src/shared/typescript.mjs[m | ||
[36m@@ -54,7 +54,6 @@[m [mfunction getSchemaShape(schema = {}, module = {}, { name = '', level = 0, title,[m | ||
[m | ||
if (schema['$ref']) {[m | ||
if (level === 0) {[m | ||
[31m- throw "Ref at level 0!"[m | ||
return `${prefix}${theTitle};`[m | ||
}[m | ||
else {[m | ||
[36m@@ -63,7 +62,6 @@[m [mfunction getSchemaShape(schema = {}, module = {}, { name = '', level = 0, title,[m | ||
return getSchemaShape(someJson, module, { name, level, title, summary, descriptions, destination, enums: false })[m | ||
}[m | ||
else {[m | ||
[31m- throw "unknown $ref!!"[m | ||
' '.repeat(level) + `${prefix}${theTitle}${operator}`[m | ||
}[m | ||
}[m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @param {${method.param.type}} ${method.param.name} ${method.param.summary} | ||
* @param {${method.param.type}12345} ${method.param.name} ${method.param.summary} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type ${title} = ${shape} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${title} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
${property}${if.optional}?${end.if.optional}: ${title} // ${summary} | ||
${property}${if.optional}?${end.if.optional}: ${title}${if.summary} // ${summary}${end.if.summary} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.