Skip to content

Commit

Permalink
Rename test to fix test hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekistler committed Jul 26, 2023
1 parent 77b8445 commit ae4e73a
Showing 1 changed file with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import oai3 from "@azure-tools/openapi";
import { AutoRest } from "../src/exports";
import { AppRoot } from "../src/lib/constants";

const generate = async (additionalConfig: any): Promise<oai3.Model> => {
const generate = async (additionalConfig: any): Promise<oai3.OpenAPI3Document> => {
const logger = new AutorestTestLogger();
const autoRest = new AutoRest(logger, new RealFileSystem());
autoRest.AddConfiguration({
Expand All @@ -22,7 +22,7 @@ const generate = async (additionalConfig: any): Promise<oai3.Model> => {
});
autoRest.AddConfiguration(additionalConfig);

let resolvedDocument: oai3.Model | undefined;
let resolvedDocument: oai3.OpenAPI3Document | undefined;

autoRest.GeneratedFile.Subscribe((sender, args) => {
if (args.type === "openapi-document") {
Expand All @@ -42,37 +42,17 @@ const generate = async (additionalConfig: any): Promise<oai3.Model> => {
return resolvedDocument;
};

const findModel = (spec: oai3.Model, name: string): oai3.Schema | undefined => {
return Object.values(spec.components?.schemas ?? [])
.filter((x) => !("$ref" in x))
.find((schema: oai3.Schema) => schema["x-ms-metadata"].name === name);
};

const findOperation = (spec: oai3.Model, name: string): oai3.HttpOperation | undefined => {
const findOperation = (spec: oai3.OpenAPI3Document, name: string): oai3.HttpOperation | undefined => {
for (const pathItem of Object.values(spec.paths)) {
for (const operation of Object.values(pathItem)) {
if (operation.operationId === name) {
return operation;
}
}
}

for (const pathItem of Object.values(spec["x-ms-paths"] ?? [])) {
for (const operation of Object.values(pathItem as object)) {
if (operation.operationId === name) {
return operation;
}
}
}
return undefined;
};

const findParameter = (spec: oai3.Model, name: string): oai3.Parameter | undefined => {
return Object.values((spec.components?.parameters as Record<string, oai3.Parameter>) ?? [])
.filter((x) => !("$ref" in x))
.find((parameter: oai3.Parameter) => parameter.name === name);
};

describe("final-state-schema", () => {
it("Correctly processes final-state-schema with external ref", async () => {
const code = await generate({});
Expand Down

0 comments on commit ae4e73a

Please sign in to comment.