@autorest/openapi-to-typespec
Version:
Autorest plugin to scaffold a Typespec definition from an OpenAPI document
57 lines (56 loc) • 2.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.emitTypespecConfig = void 0;
const autorest_session_1 = require("../autorest-session");
const options_1 = require("../options");
const format_1 = require("../utils/format");
async function emitTypespecConfig(filePath, programDetails) {
const session = (0, autorest_session_1.getSession)();
const { isArm, isFullCompatible } = (0, options_1.getOptions)();
let content = `
emit:
- "@azure-tools/typespec-autorest"
options:
"@azure-tools/typespec-autorest":
azure-resource-provider-folder: "data-plane"
emitter-output-dir: "{project-root}/.."
examples-dir: "{project-root}/examples"
output-file: "{azure-resource-provider-folder}/{service-name}/{version-status}/{version}/openapi.json"
# Uncomment this line and add "@azure-tools/typespec-python" to your package.json to generate Python code
# "@azure-tools/typespec-python":
# "basic-setup-py": true
# "package-version":
# "package-name":
# "output-path":
# Uncomment this line and add "@azure-tools/typespec-java" to your package.json to generate Java code
# "@azure-tools/typespec-java": true
# Uncomment this line and add "@azure-tools/typespec-csharp" to your package.json to generate C# code
# "@azure-tools/typespec-csharp": true
# Uncomment this line and add "@azure-tools/typespec-ts" to your package.json to generate Typescript code
# "@azure-tools/typespec-ts": true
`;
if (isArm) {
const inputFiles = session.configuration["input-file"];
const swaggerName = inputFiles.length > 1 ? "openapi.json" : inputFiles[0].split("/").pop();
content = `emit:
- '@azure-tools/typespec-autorest'
options:
'@azure-tools/typespec-autorest':
use-read-only-status-schema: true
omit-unreachable-types: true
emitter-output-dir: "{project-root}/.."
azure-resource-provider-folder: "resource-manager"
output-file: "{azure-resource-provider-folder}/{service-name}/{version-status}/{version}/${swaggerName}"
examples-dir: "{project-root}/examples"${isFullCompatible
? `
arm-resource-flattening: true`
: ""}
linter:
extends:
- "@azure-tools/typespec-azure-rulesets/resource-manager"
`;
}
session.writeFile({ filename: filePath, content: await (0, format_1.formatFile)(content, filePath) });
}
exports.emitTypespecConfig = emitTypespecConfig;
//# sourceMappingURL=emit-typespec-config.js.map