From 85895f943cc67de30922c8cead1b1fd744b9249c Mon Sep 17 00:00:00 2001 From: Ricardo Ferreira Date: Wed, 22 Oct 2025 09:21:48 +0100 Subject: [PATCH] feat: preserve hyphenated property names in OpenAPI generators when using propertyNaming=original Signed-off-by: Ricardo Ferreira --- .changeset/loose-pets-slide.md | 10 ++++++++++ .../commands/package/schema/openapi/generate/client.ts | 10 +++++----- .../typescript-backstage-client/modelGeneric.mustache | 2 +- .../modelTaggedUnion.mustache | 2 +- .../typescript-backstage-server/modelGeneric.mustache | 2 +- .../modelTaggedUnion.mustache | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 .changeset/loose-pets-slide.md diff --git a/.changeset/loose-pets-slide.md b/.changeset/loose-pets-slide.md new file mode 100644 index 0000000000..b8ec201f1c --- /dev/null +++ b/.changeset/loose-pets-slide.md @@ -0,0 +1,10 @@ +--- +'@backstage/repo-tools': patch +--- + +Updates OpenAPI generator templates to preserve original property names (like 'group-name', 'user-id') from OpenAPI specs when propertyNaming=original is specified. Previously, these were always converted to camelCase regardless of the propertyNaming setting. + +- Updates modelGeneric.mustache templates in both client and server generators +- Updates modelTaggedUnion.mustache templates in both client and server generators +- Uses {{baseName}} when available, falls back to {{name}} for backward compatibility +- Maintains backward compatibility - no changes when propertyNaming=original is not used diff --git a/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts b/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts index 8a8817c721..7402342607 100644 --- a/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts +++ b/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts @@ -14,21 +14,21 @@ * limitations under the License. */ +import { resolvePackagePath } from '@backstage/backend-plugin-api'; import chalk from 'chalk'; +import fs from 'fs-extra'; import { resolve } from 'path'; +import { exec } from '../../../../../lib/exec'; import { OPENAPI_IGNORE_FILES, OUTPUT_PATH, } from '../../../../../lib/openapi/constants'; -import { paths as cliPaths } from '../../../../../lib/paths'; -import fs from 'fs-extra'; -import { exec } from '../../../../../lib/exec'; -import { resolvePackagePath } from '@backstage/backend-plugin-api'; +import { deduplicateImports } from '../../../../../lib/openapi/dedupe-imports'; import { getPathToCurrentOpenApiSpec, toGeneratorAdditionalProperties, } from '../../../../../lib/openapi/helpers'; -import { deduplicateImports } from '../../../../../lib/openapi/dedupe-imports'; +import { paths as cliPaths } from '../../../../../lib/paths'; async function generate( outputDirectory: string, diff --git a/packages/repo-tools/templates/typescript-backstage-client/modelGeneric.mustache b/packages/repo-tools/templates/typescript-backstage-client/modelGeneric.mustache index d01ea29260..d246837155 100644 --- a/packages/repo-tools/templates/typescript-backstage-client/modelGeneric.mustache +++ b/packages/repo-tools/templates/typescript-backstage-client/modelGeneric.mustache @@ -18,7 +18,7 @@ export {{#isNullable}}type{{/isNullable}}{{^isNullable}}interface{{/isNullable}} * {{{.}}} */ {{/description}} - '{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}}; + '{{#baseName}}{{baseName}}{{/baseName}}{{^baseName}}{{name}}{{/baseName}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}}; {{/vars}} }{{#isNullable}} | null{{/isNullable}} diff --git a/packages/repo-tools/templates/typescript-backstage-client/modelTaggedUnion.mustache b/packages/repo-tools/templates/typescript-backstage-client/modelTaggedUnion.mustache index a3f5e00904..3f5a3baf5e 100644 --- a/packages/repo-tools/templates/typescript-backstage-client/modelTaggedUnion.mustache +++ b/packages/repo-tools/templates/typescript-backstage-client/modelTaggedUnion.mustache @@ -12,7 +12,7 @@ export interface {{classname}} { {{>modelGenericAdditionalProperties}} * {{{.}}} */ {{/description}} - {{name}}{{^required}}?{{/required}}: {{#discriminatorValue}}'{{.}}'{{/discriminatorValue}}{{^discriminatorValue}}{{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/discriminatorValue}}{{#isNullable}} | null{{/isNullable}}; + '{{#baseName}}{{baseName}}{{/baseName}}{{^baseName}}{{name}}{{/baseName}}'{{^required}}?{{/required}}: {{#discriminatorValue}}'{{.}}'{{/discriminatorValue}}{{^discriminatorValue}}{{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/discriminatorValue}}{{#isNullable}} | null{{/isNullable}}; {{/allVars}} } {{>modelGenericEnums}} diff --git a/packages/repo-tools/templates/typescript-backstage-server/modelGeneric.mustache b/packages/repo-tools/templates/typescript-backstage-server/modelGeneric.mustache index d01ea29260..d246837155 100644 --- a/packages/repo-tools/templates/typescript-backstage-server/modelGeneric.mustache +++ b/packages/repo-tools/templates/typescript-backstage-server/modelGeneric.mustache @@ -18,7 +18,7 @@ export {{#isNullable}}type{{/isNullable}}{{^isNullable}}interface{{/isNullable}} * {{{.}}} */ {{/description}} - '{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}}; + '{{#baseName}}{{baseName}}{{/baseName}}{{^baseName}}{{name}}{{/baseName}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}}; {{/vars}} }{{#isNullable}} | null{{/isNullable}} diff --git a/packages/repo-tools/templates/typescript-backstage-server/modelTaggedUnion.mustache b/packages/repo-tools/templates/typescript-backstage-server/modelTaggedUnion.mustache index a3f5e00904..3f5a3baf5e 100644 --- a/packages/repo-tools/templates/typescript-backstage-server/modelTaggedUnion.mustache +++ b/packages/repo-tools/templates/typescript-backstage-server/modelTaggedUnion.mustache @@ -12,7 +12,7 @@ export interface {{classname}} { {{>modelGenericAdditionalProperties}} * {{{.}}} */ {{/description}} - {{name}}{{^required}}?{{/required}}: {{#discriminatorValue}}'{{.}}'{{/discriminatorValue}}{{^discriminatorValue}}{{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/discriminatorValue}}{{#isNullable}} | null{{/isNullable}}; + '{{#baseName}}{{baseName}}{{/baseName}}{{^baseName}}{{name}}{{/baseName}}'{{^required}}?{{/required}}: {{#discriminatorValue}}'{{.}}'{{/discriminatorValue}}{{^discriminatorValue}}{{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/discriminatorValue}}{{#isNullable}} | null{{/isNullable}}; {{/allVars}} } {{>modelGenericEnums}}