import { performance } from 'node:perf_hooks';
import { createConfig } from '@redocly/openapi-core';
import { validateAndBundle } from './lib/redoc.mjs';
import { scanDiscriminators, debug, resolveRef } from './lib/utils.mjs';
export { createDiscriminatorProperty, createRef, error, formatTime, getEntries, walk, warn } from './lib/utils.mjs';
import transformSchema from './transform/index.mjs';
export { BOOLEAN, FALSE, JS_ENUM_INVALID_CHARS_RE, JS_PROPERTY_INDEX_INVALID_CHARS_RE, JS_PROPERTY_INDEX_RE, NEVER, NULL, NUMBER, QUESTION_TOKEN, SPECIAL_CHARACTER_MAP, STRING, TRUE, UNDEFINED, UNKNOWN, addJSDocComment, astToString, enumCache, oapiRef, stringToAST, tsArrayLiteralExpression, tsDedupe, tsEnum, tsEnumMember, tsIntersection, tsIsPrimitive, tsLiteral, tsModifiers, tsNullable, tsOmit, tsPropertyIndex, tsReadonlyArray, tsRecord, tsUnion, tsWithRequired } from './lib/ts.mjs';
export { default as transformComponentsObject } from './transform/components-object.mjs';
export { default as transformHeaderObject } from './transform/header-object.mjs';
export { default as transformMediaTypeObject } from './transform/media-type-object.mjs';
export { injectOperationObject, default as transformOperationObject } from './transform/operation-object.mjs';
export { default as transformParameterObject } from './transform/parameter-object.mjs';
export { default as transformPathItemObject } from './transform/path-item-object.mjs';
export { default as transformPathsObject } from './transform/paths-object.mjs';
export { default as transformRequestBodyObject } from './transform/request-body-object.mjs';
export { default as transformResponseObject } from './transform/response-object.mjs';
export { default as transformResponsesObject } from './transform/responses-object.mjs';
export { default as transformSchemaObject, transformSchemaObjectWithComposition } from './transform/schema-object.mjs';
export { default as c } from 'ansi-colors';

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 = options.redocly ?? await createConfig(
    {
      rules: {
        "operation-operationId-unique": { severity: "error" }
        // throw error on duplicate operationIDs
      }
    },
    { extends: ["minimal"] }
  );
  const schema = await validateAndBundle(source, {
    redoc,
    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: 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,
    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 resolveRef(schema, $ref, { silent: options.silent ?? false });
    }
  };
  const transformT = performance.now();
  const result = transformSchema(schema, ctx);
  debug("Completed AST transformation for entire document", "ts", performance.now() - transformT);
  return result;
}

export { COMMENT_HEADER, debug, openapiTS as default, resolveRef, scanDiscriminators, transformSchema };
//# sourceMappingURL=index.mjs.map
