From 85895f943cc67de30922c8cead1b1fd744b9249c Mon Sep 17 00:00:00 2001 From: Ricardo Ferreira Date: Wed, 22 Oct 2025 09:21:48 +0100 Subject: [PATCH 1/4] 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}} From 5c87c0c0b5b4c28e5278aa652e8fdc09e3e6ca30 Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Tue, 11 Nov 2025 11:03:53 -0500 Subject: [PATCH 2/4] fix scaffolder schema Signed-off-by: aramissennyeydd --- plugins/scaffolder-backend/src/schema/openapi.yaml | 6 +++--- .../src/schema/openapi/generated/router.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/scaffolder-backend/src/schema/openapi.yaml b/plugins/scaffolder-backend/src/schema/openapi.yaml index b89f54603c..b26515a71b 100644 --- a/plugins/scaffolder-backend/src/schema/openapi.yaml +++ b/plugins/scaffolder-backend/src/schema/openapi.yaml @@ -113,7 +113,7 @@ components: type: string description: type: string - "'examples'": + examples: type: array items: $ref: '#/components/schemas/ActionExample' @@ -417,7 +417,7 @@ components: $ref: '#/components/schemas/JsonObject' output: $ref: '#/components/schemas/JsonObject' - "'examples'": + examples: type: array items: $ref: '#/components/schemas/ScaffolderUsageExample' @@ -449,7 +449,7 @@ components: $ref: '#/components/schemas/JsonObject' output: $ref: '#/components/schemas/JsonObject' - "'examples'": + examples: type: array items: $ref: '#/components/schemas/ScaffolderUsageExample' diff --git a/plugins/scaffolder-backend/src/schema/openapi/generated/router.ts b/plugins/scaffolder-backend/src/schema/openapi/generated/router.ts index 669dd63878..6401c84964 100644 --- a/plugins/scaffolder-backend/src/schema/openapi/generated/router.ts +++ b/plugins/scaffolder-backend/src/schema/openapi/generated/router.ts @@ -173,7 +173,7 @@ export const spec = { description: { type: 'string', }, - "'examples'": { + examples: { type: 'array', items: { $ref: '#/components/schemas/ActionExample', @@ -588,7 +588,7 @@ export const spec = { }, }, }, - "'examples'": { + examples: { type: 'array', items: { $ref: '#/components/schemas/ScaffolderUsageExample', @@ -636,7 +636,7 @@ export const spec = { }, }, }, - "'examples'": { + examples: { type: 'array', items: { $ref: '#/components/schemas/ScaffolderUsageExample', From b8717e25f93d06f0e45306c3d98ae301b2838708 Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Sun, 16 Nov 2025 11:24:12 -0500 Subject: [PATCH 3/4] disable invalid rule Signed-off-by: aramissennyeydd --- packages/repo-tools/src/commands/repo/schema/openapi/lint.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts b/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts index 515d1d68ed..8c610e44b1 100644 --- a/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts +++ b/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts @@ -68,6 +68,7 @@ async function lint(directoryPath: string, config?: { strict: boolean }) { 'operation-tags': 'off', 'hosts-https-only-oas3': 'off', 'no-unknown-error-format': 'off', + 'oas3-valid-media-example': 'off', }, }, ], From 78827da22539f02f9f01d4579c64b2a919fd7a85 Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Sun, 16 Nov 2025 11:24:35 -0500 Subject: [PATCH 4/4] add comment Signed-off-by: aramissennyeydd --- packages/repo-tools/src/commands/repo/schema/openapi/lint.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts b/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts index 8c610e44b1..34c8589d54 100644 --- a/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts +++ b/packages/repo-tools/src/commands/repo/schema/openapi/lint.ts @@ -68,6 +68,7 @@ async function lint(directoryPath: string, config?: { strict: boolean }) { 'operation-tags': 'off', 'hosts-https-only-oas3': 'off', 'no-unknown-error-format': 'off', + // Disabled as it currently gives false positives when 'example' is used as a property name. 'oas3-valid-media-example': 'off', }, },