Skip to content

Commit

Permalink
Fix sample path issue (#5045)
Browse files Browse the repository at this point in the history
To honor its original folder path. Fix
#5041

---------

Co-authored-by: Pan Shao <[email protected]>
  • Loading branch information
pshao25 and Pan Shao authored Dec 10, 2024
1 parent 739d73f commit fbd40b8
Show file tree
Hide file tree
Showing 1,529 changed files with 11,270 additions and 565 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Fix sample path issue",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
1 change: 1 addition & 0 deletions eng/scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function run(command, args, options) {
stdio: "inherit",
sync: true,
throwOnNonZeroExit: true,
shell: process.platform === "win32",
...options,
};

Expand Down
2 changes: 2 additions & 0 deletions packages/extensions/openapi-to-typespec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ version: 3.10.1
use-extension:
"@autorest/modelerfour": "^4.27.0"

include-x-ms-examples-original-file: true

modelerfour:
# this runs a pre-namer step to clean up names
prenamer: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export async function emitArmResources(program: TypespecProgram, metadata: Metad
for (const [filename, content] of Object.entries(examples)) {
if (serviceInformation.versions) {
session.writeFile({
filename: join(basePath, "examples", serviceInformation.versions[0], `${filename}.json`),
filename: join(basePath, "examples", serviceInformation.versions[0], filename),
content,
});
} else {
session.writeFile({ filename: join(basePath, "examples", "unknown", `${filename}.json`), content });
session.writeFile({ filename: join(basePath, "examples", "unknown", filename), content });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { getOptions } from "../options";
import { getTSPOperationGroupName } from "../transforms/transform-arm-resources";
import { generateAugmentedDecorators, generateDecorators } from "../utils/decorators";
import { generateDocs } from "../utils/docs";
import { getLogger } from "../utils/logger";
import { getModelPropertiesDeclarations } from "../utils/model-generation";
import { generateSuppressions } from "../utils/suppressions";
import { generateOperation } from "./generate-operations";

const logger = () => getLogger("generate-arm-resource");

export function generateArmResource(resource: TspArmResource): string {
const definitions: string[] = [];

Expand Down Expand Up @@ -157,7 +160,23 @@ function generateExamples(
for (const [title, example] of _.entries(examples)) {
example.operationId = operationId;
example.title = title;
let filename = operationId;

let filename = undefined;
const originalFile = example["x-ms-original-file"] as string;
if (originalFile) {
const exampleIndex = originalFile.lastIndexOf("/examples/");
if (exampleIndex !== -1) {
filename = originalFile.substring(exampleIndex + "/examples/".length);
delete example["x-ms-original-file"];
generatedExamples[filename] = JSON.stringify(example, null, 2);
continue;
}
}

logger().info(
`Cannot find the example original path or the path isn't in the examples folder for operation ${operationId}`,
);
filename = operationId;
if (count > 1) {
if (title.startsWith(filename)) {
filename = title;
Expand Down
Loading

0 comments on commit fbd40b8

Please sign in to comment.