'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const node_perf_hooks = require('node:perf_hooks');
const openapiCore = require('@redocly/openapi-core');
const redoc = require('./lib/redoc.cjs');
const utils = require('./lib/utils.cjs');
const index = require('./transform/index.cjs');
const ts = require('./lib/ts.cjs');
const componentsObject = require('./transform/components-object.cjs');
const headerObject = require('./transform/header-object.cjs');
const mediaTypeObject = require('./transform/media-type-object.cjs');
const operationObject = require('./transform/operation-object.cjs');
const parameterObject = require('./transform/parameter-object.cjs');
const pathItemObject = require('./transform/path-item-object.cjs');
const pathsObject = require('./transform/paths-object.cjs');
const requestBodyObject = require('./transform/request-body-object.cjs');
const responseObject = require('./transform/response-object.cjs');
const responsesObject = require('./transform/responses-object.cjs');
const schemaObject = require('./transform/schema-object.cjs');
const c = require('ansi-colors');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }

const c__default = /*#__PURE__*/_interopDefaultCompat(c);

const COMMENT_HEADER = `/**
 * This file was auto-generated by openapi-typescript.
 * Do not make direct changes to the file.
 */

`;
async function openapiTS(source, options = {}) {
  if (!source) {
    throw new Error("Empty schema. Please specify a URL, file path, or Redocly Config");
  }
  const redoc$1 = options.redocly ?? await openapiCore.createConfig(
    {
      rules: {
        "operation-operationId-unique": { severity: "error" }
        // throw error on duplicate operationIDs
      }
    },
    { extends: ["minimal"] }
  );
  const schema = await redoc.validateAndBundle(source, {
    redoc: redoc$1,
    cwd: options.cwd instanceof URL ? options.cwd : new URL(`file://${options.cwd ?? process.cwd()}/`),
    silent: options.silent ?? false
  });
  const ctx = {
    additionalProperties: options.additionalProperties ?? false,
    alphabetize: options.alphabetize ?? false,
    arrayLength: options.arrayLength ?? false,
    defaultNonNullable: options.defaultNonNullable ?? true,
    discriminators: utils.scanDiscriminators(schema, options),
    emptyObjectsUnknown: options.emptyObjectsUnknown ?? false,
    enum: options.enum ?? false,
    enumValues: options.enumValues ?? false,
    conditionalEnums: options.conditionalEnums ?? false,
    dedupeEnums: options.dedupeEnums ?? false,
    excludeDeprecated: options.excludeDeprecated ?? false,
    exportType: options.exportType ?? false,
    immutable: options.immutable ?? false,
    rootTypes: options.rootTypes ?? false,
    rootTypesNoSchemaPrefix: options.rootTypesNoSchemaPrefix ?? false,
    rootTypesKeepCasing: options.rootTypesKeepCasing ?? false,
    injectFooter: [],
    pathParamsAsTypes: options.pathParamsAsTypes ?? false,
    postTransform: typeof options.postTransform === "function" ? options.postTransform : void 0,
    propertiesRequiredByDefault: options.propertiesRequiredByDefault ?? false,
    redoc: redoc$1,
    silent: options.silent ?? false,
    inject: options.inject ?? void 0,
    transform: typeof options.transform === "function" ? options.transform : void 0,
    transformProperty: typeof options.transformProperty === "function" ? options.transformProperty : void 0,
    makePathsEnum: options.makePathsEnum ?? false,
    generatePathParams: options.generatePathParams ?? false,
    readWriteMarkers: options.readWriteMarkers ?? false,
    resolve($ref) {
      return utils.resolveRef(schema, $ref, { silent: options.silent ?? false });
    }
  };
  const transformT = node_perf_hooks.performance.now();
  const result = index(schema, ctx);
  utils.debug("Completed AST transformation for entire document", "ts", node_perf_hooks.performance.now() - transformT);
  return result;
}

exports.createDiscriminatorProperty = utils.createDiscriminatorProperty;
exports.createRef = utils.createRef;
exports.debug = utils.debug;
exports.error = utils.error;
exports.formatTime = utils.formatTime;
exports.getEntries = utils.getEntries;
exports.resolveRef = utils.resolveRef;
exports.scanDiscriminators = utils.scanDiscriminators;
exports.walk = utils.walk;
exports.warn = utils.warn;
exports.transformSchema = index;
exports.BOOLEAN = ts.BOOLEAN;
exports.FALSE = ts.FALSE;
exports.JS_ENUM_INVALID_CHARS_RE = ts.JS_ENUM_INVALID_CHARS_RE;
exports.JS_PROPERTY_INDEX_INVALID_CHARS_RE = ts.JS_PROPERTY_INDEX_INVALID_CHARS_RE;
exports.JS_PROPERTY_INDEX_RE = ts.JS_PROPERTY_INDEX_RE;
exports.NEVER = ts.NEVER;
exports.NULL = ts.NULL;
exports.NUMBER = ts.NUMBER;
exports.QUESTION_TOKEN = ts.QUESTION_TOKEN;
exports.SPECIAL_CHARACTER_MAP = ts.SPECIAL_CHARACTER_MAP;
exports.STRING = ts.STRING;
exports.TRUE = ts.TRUE;
exports.UNDEFINED = ts.UNDEFINED;
exports.UNKNOWN = ts.UNKNOWN;
exports.addJSDocComment = ts.addJSDocComment;
exports.astToString = ts.astToString;
exports.enumCache = ts.enumCache;
exports.oapiRef = ts.oapiRef;
exports.stringToAST = ts.stringToAST;
exports.tsArrayLiteralExpression = ts.tsArrayLiteralExpression;
exports.tsDedupe = ts.tsDedupe;
exports.tsEnum = ts.tsEnum;
exports.tsEnumMember = ts.tsEnumMember;
exports.tsIntersection = ts.tsIntersection;
exports.tsIsPrimitive = ts.tsIsPrimitive;
exports.tsLiteral = ts.tsLiteral;
exports.tsModifiers = ts.tsModifiers;
exports.tsNullable = ts.tsNullable;
exports.tsOmit = ts.tsOmit;
exports.tsPropertyIndex = ts.tsPropertyIndex;
exports.tsReadonlyArray = ts.tsReadonlyArray;
exports.tsRecord = ts.tsRecord;
exports.tsUnion = ts.tsUnion;
exports.tsWithRequired = ts.tsWithRequired;
exports.transformComponentsObject = componentsObject.default;
exports.transformHeaderObject = headerObject;
exports.transformMediaTypeObject = mediaTypeObject;
exports.injectOperationObject = operationObject.injectOperationObject;
exports.transformOperationObject = operationObject.default;
exports.transformParameterObject = parameterObject;
exports.transformPathItemObject = pathItemObject;
exports.transformPathsObject = pathsObject;
exports.transformRequestBodyObject = requestBodyObject;
exports.transformResponseObject = responseObject;
exports.transformResponsesObject = responsesObject;
exports.transformSchemaObject = schemaObject.default;
exports.transformSchemaObjectWithComposition = schemaObject.transformSchemaObjectWithComposition;
exports.c = c__default;
exports.COMMENT_HEADER = COMMENT_HEADER;
exports.default = openapiTS;
//# sourceMappingURL=index.cjs.map
