in eng/tools/lint-diff/src/markdown-utils.ts [23:58]
export async function getOpenapiType(markdownFile: string): Promise<MarkdownType> {
let markdownContent = await readFile(markdownFile, { encoding: "utf-8" });
for (const codeBlock of parseCodeblocks(markdownContent)) {
if (
!codeBlock.info ||
codeBlock.info.trim().toLocaleLowerCase() !== "yaml" ||
!codeBlock.literal
) {
continue;
}
let lines = codeBlock.literal.trim().split("\n");
for (const line of lines) {
if (line.trim().startsWith("openapi-type:")) {
let openapiType = line.trim().split(":")[1].trim().toLowerCase();
if (Object.values(MarkdownType).includes(openapiType as MarkdownType)) {
return openapiType as MarkdownType;
}
}
}
}
// Fallback, no openapi-type found in the file. Look at path to determine type
// resource-manager: Arm
// data-plane: DataPlane
if (markdownFile.match(/.*specification\/.*\/resource-manager\/.*readme.md$/g)) {
return MarkdownType.Arm;
} else if (markdownFile.match(/.*specification\/.*\/data-plane\/.*readme.md$/g)) {
return MarkdownType.DataPlane;
}
// No type was found, return Default
return MarkdownType.Default;
}