@autorest/openapi-to-typespec
Version:
Autorest plugin to scaffold a Typespec definition from an OpenAPI document
36 lines (28 loc) • 1.16 kB
text/typescript
import { CodeModel } from "@autorest/codemodel";
import { Session } from "@autorest/extension-base";
let _session: Session<CodeModel>;
let _armCommonTypeVersion: ArmCommonTypeVersion | undefined;
let _userSetArmCommonTypeVersion: string;
export function setSession(session: Session<CodeModel>): void {
_session = session;
}
export function getSession(): Session<CodeModel> {
return _session;
}
export function setArmCommonTypeVersion(version: string): void {
_userSetArmCommonTypeVersion = version;
}
export type ArmCommonTypeVersion = "v3" | "v4" | "v5" | "v6";
export function getArmCommonTypeVersion(): ArmCommonTypeVersion {
if (!_armCommonTypeVersion) {
if (["v3", "v4", "v5", "v6"].includes(_userSetArmCommonTypeVersion)) {
_armCommonTypeVersion = _userSetArmCommonTypeVersion as ArmCommonTypeVersion;
} else {
_armCommonTypeVersion = "v3"; // We hardcode the common type version to v3 if it's not set or the value is not valid, otherwise no model can extend a resource model.
}
}
return _armCommonTypeVersion;
}
export function getUserSetArmCommonTypeVersion(): string {
return _userSetArmCommonTypeVersion;
}