Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: Unable to use {service-name} interpolation for filenames with openapi3-emitter when only one service is defined #6182

Merged
merged 12 commits into from
Mar 3, 2025
Prev Previous commit
Next Next commit
move test back to family
  • Loading branch information
albertxavier100 committed Feb 28, 2025
commit 3a3b9fc125666b84269be7844c9a998f66c7b2ce
56 changes: 56 additions & 0 deletions packages/openapi3/test/output-file.test.ts
Original file line number Diff line number Diff line change
@@ -134,4 +134,60 @@ describe("openapi3: output file", () => {
});
});
});

describe("Predefined variable name behavior", () => {
interface ServiceNameCase {
description: string;
code: string;
outputFilePattern: string;
expectedOutputFiles: string[];
}
it.each([
// {service-name} cases
{
description: "{service-name} for one service",
code: "@service namespace AAA { model M {a: string} }",
outputFilePattern: "{service-name}.yaml",
expectedOutputFiles: ["AAA.yaml"],
},
{
description: "{service-name} for multiple services",
code:
"@service namespace AAA { model M {a: string} }" +
"@service namespace BBB { model N {b: string} }",
outputFilePattern: "{service-name}.yaml",
expectedOutputFiles: ["AAA.yaml", "BBB.yaml"],
},
// {service-name-if-multiple} cases
{
description: "{service-name-if-multiple} for one service",
code: "@service namespace AAA { model M {a: string} }",
outputFilePattern: "{service-name-if-multiple}.yaml",
expectedOutputFiles: ["yaml"],
},
{
description: "{service-name-if-multiple} for multiple services",
code:
"@service namespace AAA { model M {a: string} }" +
"@service namespace BBB { model N {b: string} }",
outputFilePattern: "{service-name-if-multiple}.yaml",
expectedOutputFiles: ["AAA.yaml", "BBB.yaml"],
},
// fixed name cases
{
description: "fixed name for one service",
code: "@service namespace AAA { model M {a: string} }",
outputFilePattern: "fixed-name.yaml",
expectedOutputFiles: ["fixed-name.yaml"],
},
])("$description", async (c: ServiceNameCase) => {
await compileOpenAPI(
{
"output-file": c.outputFilePattern,
},
c.code,
);
for (const outputFile of c.expectedOutputFiles) expectHasOutput(outputFile);
});
});
});
66 changes: 0 additions & 66 deletions packages/openapi3/test/predefined-variable.test.ts

This file was deleted.

Loading
Oops, something went wrong.