Skip to content

Commit

Permalink
Fix sample path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan Shao committed Dec 9, 2024
1 parent 739d73f commit b1be09a
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 @@ -9,6 +9,9 @@ import { generateDocs } from "../utils/docs";
import { getModelPropertiesDeclarations } from "../utils/model-generation";
import { generateSuppressions } from "../utils/suppressions";
import { generateOperation } from "./generate-operations";
import { getLogger } from "../utils/logger";

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 b1be09a

Please sign in to comment.