UNPKG

@autorest/openapi-to-typespec

Version:

Autorest plugin to scaffold a Typespec definition from an OpenAPI document

23 lines (18 loc) 818 B
import { TypespecAlias, TypespecObject } from "../interfaces"; export function addCorePageAlias(typespecObject: TypespecObject): TypespecAlias | undefined { if (!typespecObject.decorators?.some((d) => d.name === "pagedResult")) { return; } const value = typespecObject.properties?.filter((p) => p.name === "value"); if (!typespecObject.properties?.some((p) => p.name === "nextLink") || !value?.length) { return; } typespecObject.decorators = typespecObject.decorators.filter((d) => d.name !== "pagedResult"); typespecObject.properties = typespecObject.properties.filter((p) => p.name !== "nextLink" && p.name !== "value"); typespecObject.alias = { alias: "Azure.Core.Page", params: [value[0].type.replace("[]", "")], module: "@azure-tools/typespec-azure-core", }; return; }