@sebspark/openapi-core 4.1.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { inspect } from "util";
2
-
3
2
  //#region src/errors.ts
4
3
  var HttpError = class HttpError extends Error {
5
4
  statusCode;
@@ -265,14 +264,13 @@ const createHttpError = (statusCode, message, cause) => {
265
264
  };
266
265
  const fromAxiosError = (axiosError) => {
267
266
  const statusCode = axiosError.response?.status || 500;
268
- const message = axiosError.response?.statusText || "Internal Server Error";
267
+ const message = axiosError.response?.statusText || axiosError.message || "Internal Server Error";
269
268
  const cause = new Error(axiosError.message);
270
269
  cause.name = axiosError.name;
271
270
  cause.stack = axiosError.stack;
272
271
  cause.cause = axiosError?.response?.data;
273
272
  return createHttpError(statusCode, message, cause);
274
273
  };
275
-
276
274
  //#endregion
277
275
  //#region src/schema.ts
278
276
  const clone = (orig) => JSON.parse(JSON.stringify(orig));
@@ -365,7 +363,7 @@ const flattenEnums = (document) => {
365
363
  }
366
364
  return doc;
367
365
  };
368
-
369
366
  //#endregion
370
367
  export { BadGatewayError, BadRequestError, ConflictError, ExpectationFailedError, FailedDependencyError, ForbiddenError, GatewayTimeoutError, GoneError, HTTPVersionNotSupportedError, HttpError, IMATeapotError, InsufficientStorageError, InternalServerError, LengthRequiredError, LockedError, LoopDetectedError, MethodNotAllowedError, MisdirectedRequestError, NetworkAuthenticationRequiredError, NotAcceptableError, NotExtendedError, NotFoundError, NotImplementedError, PayloadTooLargeError, PaymentRequiredError, PreconditionFailedError, PreconditionRequiredError, ProxyAuthenticationRequiredError, RangeNotSatisfiableError, RequestHeaderFieldsTooLargeError, RequestTimeoutError, ServiceUnavailableError, TooEarlyError, TooManyRequestsError, URITooLongError, UnauthorizedError, UnavailableForLegalReasonsError, UnprocessableEntityError, UnsupportedMediaTypeError, UpgradeRequiredError, VariantAlsoNegotiatesError, appendVersionToServers, createHttpError, disableUnimplementedPaths, flattenEnums, fromAxiosError, resolveRef };
368
+
371
369
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/errors.ts","../src/schema.ts"],"sourcesContent":["import type { AxiosError } from 'axios'\n// biome-ignore lint/style/useNodejsImportProtocol: use 'util' for RN Metro + polyfill support\nimport { inspect } from 'util'\n\nexport type ClientErrorCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451\nexport type ServerErrorCode =\n | 500\n | 501\n | 502\n | 503\n | 504\n | 505\n | 506\n | 507\n | 508\n | 510\n | 511\nexport type ErrorCode = ClientErrorCode | ServerErrorCode\n\ntype SerializedError = {\n message: string\n stack?: string\n}\n\n// Base HttpError class\nexport class HttpError extends Error {\n statusCode: number\n\n constructor(statusCode: number, message: string, cause?: Error) {\n super(message)\n if (cause) {\n this.stack = undefined\n this.cause = cause\n }\n this.statusCode = statusCode\n Object.setPrototypeOf(this, HttpError.prototype)\n }\n\n toJSON(showStack = false) {\n const serialized: SerializedError = {\n message: this.message,\n }\n if (showStack) {\n serialized.stack = inspect(this)\n }\n return serialized\n }\n}\n\n// Specific error classes extending HttpError\nexport class BadRequestError extends HttpError {\n constructor(message = 'Bad Request', cause?: Error) {\n super(400, message, cause)\n }\n}\n\nexport class UnauthorizedError extends HttpError {\n constructor(message = 'Unauthorized', cause?: Error) {\n super(401, message, cause)\n }\n}\n\nexport class PaymentRequiredError extends HttpError {\n constructor(message = 'Payment Required', cause?: Error) {\n super(402, message, cause)\n }\n}\n\nexport class ForbiddenError extends HttpError {\n constructor(message = 'Forbidden', cause?: Error) {\n super(403, message, cause)\n }\n}\n\nexport class NotFoundError extends HttpError {\n constructor(message = 'Not Found', cause?: Error) {\n super(404, message, cause)\n }\n}\n\nexport class MethodNotAllowedError extends HttpError {\n constructor(message = 'Method Not Allowed', cause?: Error) {\n super(405, message, cause)\n }\n}\n\nexport class NotAcceptableError extends HttpError {\n constructor(message = 'Not Acceptable', cause?: Error) {\n super(406, message, cause)\n }\n}\n\nexport class ProxyAuthenticationRequiredError extends HttpError {\n constructor(message = 'Proxy Authentication Required', cause?: Error) {\n super(407, message, cause)\n }\n}\n\nexport class RequestTimeoutError extends HttpError {\n constructor(message = 'Request Timeout', cause?: Error) {\n super(408, message, cause)\n }\n}\n\nexport class ConflictError extends HttpError {\n constructor(message = 'Conflict', cause?: Error) {\n super(409, message, cause)\n }\n}\n\nexport class GoneError extends HttpError {\n constructor(message = 'Gone', cause?: Error) {\n super(410, message, cause)\n }\n}\n\nexport class LengthRequiredError extends HttpError {\n constructor(message = 'Length Required', cause?: Error) {\n super(411, message, cause)\n }\n}\n\nexport class PreconditionFailedError extends HttpError {\n constructor(message = 'Precondition Failed', cause?: Error) {\n super(412, message, cause)\n }\n}\n\nexport class PayloadTooLargeError extends HttpError {\n constructor(message = 'Payload Too Large', cause?: Error) {\n super(413, message, cause)\n }\n}\n\nexport class URITooLongError extends HttpError {\n constructor(message = 'URI Too Long', cause?: Error) {\n super(414, message, cause)\n }\n}\n\nexport class UnsupportedMediaTypeError extends HttpError {\n constructor(message = 'Unsupported Media Type', cause?: Error) {\n super(415, message, cause)\n }\n}\n\nexport class RangeNotSatisfiableError extends HttpError {\n constructor(message = 'Range Not Satisfiable', cause?: Error) {\n super(416, message, cause)\n }\n}\n\nexport class ExpectationFailedError extends HttpError {\n constructor(message = 'Expectation Failed', cause?: Error) {\n super(417, message, cause)\n }\n}\n\nexport class IMATeapotError extends HttpError {\n constructor(message = \"I'm a teapot\", cause?: Error) {\n super(418, message, cause)\n }\n}\n\nexport class MisdirectedRequestError extends HttpError {\n constructor(message = 'Misdirected Request', cause?: Error) {\n super(421, message, cause)\n }\n}\n\nexport class UnprocessableEntityError extends HttpError {\n constructor(message = 'Unprocessable Entity', cause?: Error) {\n super(422, message, cause)\n }\n}\n\nexport class LockedError extends HttpError {\n constructor(message = 'Locked', cause?: Error) {\n super(423, message, cause)\n }\n}\n\nexport class FailedDependencyError extends HttpError {\n constructor(message = 'Failed Dependency', cause?: Error) {\n super(424, message, cause)\n }\n}\n\nexport class TooEarlyError extends HttpError {\n constructor(message = 'Too Early', cause?: Error) {\n super(425, message, cause)\n }\n}\n\nexport class UpgradeRequiredError extends HttpError {\n constructor(message = 'Upgrade Required', cause?: Error) {\n super(426, message, cause)\n }\n}\n\nexport class PreconditionRequiredError extends HttpError {\n constructor(message = 'Precondition Required', cause?: Error) {\n super(428, message, cause)\n }\n}\n\nexport class TooManyRequestsError extends HttpError {\n constructor(message = 'Too Many Requests', cause?: Error) {\n super(429, message, cause)\n }\n}\n\nexport class RequestHeaderFieldsTooLargeError extends HttpError {\n constructor(message = 'Request Header Fields Too Large', cause?: Error) {\n super(431, message, cause)\n }\n}\n\nexport class UnavailableForLegalReasonsError extends HttpError {\n constructor(message = 'Unavailable For Legal Reasons', cause?: Error) {\n super(451, message, cause)\n }\n}\n\n// 500 Range Error Classes\nexport class InternalServerError extends HttpError {\n constructor(message = 'Internal Server Error', cause?: Error) {\n super(500, message, cause)\n }\n}\n\nexport class NotImplementedError extends HttpError {\n constructor(message = 'Not Implemented', cause?: Error) {\n super(501, message, cause)\n }\n}\n\nexport class BadGatewayError extends HttpError {\n constructor(message = 'Bad Gateway', cause?: Error) {\n super(502, message, cause)\n }\n}\n\nexport class ServiceUnavailableError extends HttpError {\n constructor(message = 'Service Unavailable', cause?: Error) {\n super(503, message, cause)\n }\n}\n\nexport class GatewayTimeoutError extends HttpError {\n constructor(message = 'Gateway Timeout', cause?: Error) {\n super(504, message, cause)\n }\n}\n\nexport class HTTPVersionNotSupportedError extends HttpError {\n constructor(message = 'HTTP Version Not Supported', cause?: Error) {\n super(505, message, cause)\n }\n}\n\nexport class VariantAlsoNegotiatesError extends HttpError {\n constructor(message = 'Variant Also Negotiates', cause?: Error) {\n super(506, message, cause)\n }\n}\n\nexport class InsufficientStorageError extends HttpError {\n constructor(message = 'Insufficient Storage', cause?: Error) {\n super(507, message, cause)\n }\n}\n\nexport class LoopDetectedError extends HttpError {\n constructor(message = 'Loop Detected', cause?: Error) {\n super(508, message, cause)\n }\n}\n\nexport class NotExtendedError extends HttpError {\n constructor(message = 'Not Extended', cause?: Error) {\n super(510, message, cause)\n }\n}\n\nexport class NetworkAuthenticationRequiredError extends HttpError {\n constructor(message = 'Network Authentication Required', cause?: Error) {\n super(511, message, cause)\n }\n}\n\n// Function to create an error based on status code\nexport const createHttpError = (\n statusCode: ErrorCode,\n message?: string,\n cause?: Error\n): HttpError => {\n switch (statusCode) {\n case 400:\n return new BadRequestError(message, cause)\n case 401:\n return new UnauthorizedError(message, cause)\n case 402:\n return new PaymentRequiredError(message, cause)\n case 403:\n return new ForbiddenError(message, cause)\n case 404:\n return new NotFoundError(message, cause)\n case 405:\n return new MethodNotAllowedError(message, cause)\n case 406:\n return new NotAcceptableError(message, cause)\n case 407:\n return new ProxyAuthenticationRequiredError(message, cause)\n case 408:\n return new RequestTimeoutError(message, cause)\n case 409:\n return new ConflictError(message, cause)\n case 410:\n return new GoneError(message, cause)\n case 411:\n return new LengthRequiredError(message, cause)\n case 412:\n return new PreconditionFailedError(message, cause)\n case 413:\n return new PayloadTooLargeError(message, cause)\n case 414:\n return new URITooLongError(message, cause)\n case 415:\n return new UnsupportedMediaTypeError(message, cause)\n case 416:\n return new RangeNotSatisfiableError(message, cause)\n case 417:\n return new ExpectationFailedError(message, cause)\n case 418:\n return new IMATeapotError(message, cause)\n case 421:\n return new MisdirectedRequestError(message, cause)\n case 422:\n return new UnprocessableEntityError(message, cause)\n case 423:\n return new LockedError(message, cause)\n case 424:\n return new FailedDependencyError(message, cause)\n case 425:\n return new TooEarlyError(message, cause)\n case 426:\n return new UpgradeRequiredError(message, cause)\n case 428:\n return new PreconditionRequiredError(message, cause)\n case 429:\n return new TooManyRequestsError(message, cause)\n case 431:\n return new RequestHeaderFieldsTooLargeError(message, cause)\n case 451:\n return new UnavailableForLegalReasonsError(message, cause)\n case 500:\n return new InternalServerError(message, cause)\n case 501:\n return new NotImplementedError(message, cause)\n case 502:\n return new BadGatewayError(message, cause)\n case 503:\n return new ServiceUnavailableError(message, cause)\n case 504:\n return new GatewayTimeoutError(message, cause)\n case 505:\n return new HTTPVersionNotSupportedError(message, cause)\n case 506:\n return new VariantAlsoNegotiatesError(message, cause)\n case 507:\n return new InsufficientStorageError(message, cause)\n case 508:\n return new LoopDetectedError(message, cause)\n case 510:\n return new NotExtendedError(message, cause)\n case 511:\n return new NetworkAuthenticationRequiredError(message, cause)\n default:\n return new HttpError(statusCode, message ?? 'Error', cause)\n }\n}\n\nexport const fromAxiosError = (axiosError: AxiosError): HttpError => {\n // Default to 500 Internal Server Error if the status code is not available\n const statusCode = (axiosError.response?.status || 500) as ErrorCode\n const message = axiosError.response?.statusText || 'Internal Server Error'\n\n // The internal error can contain more specific details about the Axios error\n const cause = new Error(axiosError.message)\n cause.name = axiosError.name\n cause.stack = axiosError.stack\n // If the error response has a data property pass it along\n cause.cause = axiosError?.response?.data\n\n return createHttpError(statusCode, message, cause)\n}\n","import type { SchemaObject } from './common'\nimport type { OpenApiDocument, OperationObject } from './openapi'\nimport type { APIServerDefinition } from './types'\n\nconst clone = <T>(orig: T): T => JSON.parse(JSON.stringify(orig))\n\n/**\n * Marks unimplemented paths as deprecated and tags them with 'not-implemented'.\n * Use to hide or visually separate endpoints not yet available on the given server.\n *\n * @param document - The OpenAPI document to modify\n * @param server - The server definition to check against for implemented paths\n * @returns A cloned document with unimplemented paths marked as deprecated\n */\nexport const disableUnimplementedPaths = <\n T extends OpenApiDocument,\n S extends APIServerDefinition,\n>(\n document: T,\n server: S\n): T => {\n const doc = clone(document)\n for (const path of Object.keys(doc.paths)) {\n const pathObj = doc.paths[path as keyof typeof doc.paths]\n const fixedPath = path.replace(/{(.+)}/, ':$1')\n if (!server[fixedPath] && !fixedPath.startsWith('/health')) {\n for (const method of Object.values(pathObj)) {\n const operation = method as OperationObject\n operation.deprecated = true\n operation.tags = [...(operation.tags ?? []), 'not-implemented']\n }\n }\n }\n return doc\n}\n\n/**\n * Appends the API version segment to all server URLs.\n *\n * @param document - The OpenAPI document to modify\n * @param version - The version string to append\n * @returns A cloned document with updated server URLs\n */\nexport const appendVersionToServers = <T extends OpenApiDocument>(\n document: T,\n version: string\n): T => {\n const doc = clone(document)\n for (const server of doc.servers || []) {\n server.url = `${server.url}/${version}`\n }\n return doc\n}\n\n/**\n * Resolves a $ref string to its schema definition within the document.\n *\n * @param ref - A JSON pointer ref string e.g. `#/components/schemas/Foo`\n * @param doc - The OpenAPI document to resolve against\n * @returns The resolved schema, or undefined if the ref cannot be resolved\n */\nexport const resolveRef = (\n ref: string,\n doc: OpenApiDocument\n): SchemaObject | undefined => {\n const parts = ref.replace('#/', '').split('/')\n let current: unknown = doc\n for (const part of parts) {\n if (typeof current !== 'object' || current === null) return undefined\n current = (current as Record<string, unknown>)[part]\n }\n return current as SchemaObject\n}\n\n/**\n * Flattens all schemas typed as oneOf[$ref, $ref, ...] where all refs resolve to enums\n * into a single merged enum. Enables API UI tools to render a dropdown instead of a text input.\n *\n * @param document - The OpenAPI document to modify\n * @returns A cloned document with flattened enum schemas\n */\nexport const flattenEnums = <T extends OpenApiDocument>(document: T): T => {\n const doc = clone(document)\n\n const flatten = (schema: SchemaObject): SchemaObject => {\n if (!('oneOf' in schema) || !schema.oneOf) return schema\n\n let allEnums = true\n const enumValues: unknown[] = []\n\n for (const s of schema.oneOf) {\n if (!('$ref' in s)) {\n allEnums = false\n break\n }\n const resolved = resolveRef(s.$ref, doc)\n if (!resolved || !('enum' in resolved) || !Array.isArray(resolved.enum)) {\n allEnums = false\n break\n }\n for (const v of resolved.enum) enumValues.push(v)\n }\n\n if (allEnums && enumValues.length > 0) {\n return { type: 'string', enum: [...new Set(enumValues)] as string[] }\n }\n return schema\n }\n\n if (doc.components?.parameters) {\n for (const parameter of Object.values(doc.components.parameters)) {\n parameter.schema = flatten(\n parameter.schema as SchemaObject\n ) as unknown as typeof parameter.schema\n }\n }\n\n if (doc.components?.schemas) {\n for (const [key, schema] of Object.entries(doc.components.schemas)) {\n doc.components.schemas[key] = flatten(\n schema as SchemaObject\n ) as unknown as typeof schema\n }\n }\n\n for (const pathItem of Object.values(doc.paths)) {\n for (const operation of Object.values(pathItem)) {\n const op = operation as OperationObject\n if (!op.parameters) continue\n for (const parameter of op.parameters) {\n if ('schema' in parameter) {\n parameter.schema = flatten(\n parameter.schema as SchemaObject\n ) as unknown as typeof parameter.schema\n }\n }\n }\n }\n\n return doc\n}\n"],"mappings":";;;AAsDA,IAAa,YAAb,MAAa,kBAAkB,MAAM;CACnC;CAEA,YAAY,YAAoB,SAAiB,OAAe;AAC9D,QAAM,QAAQ;AACd,MAAI,OAAO;AACT,QAAK,QAAQ;AACb,QAAK,QAAQ;;AAEf,OAAK,aAAa;AAClB,SAAO,eAAe,MAAM,UAAU,UAAU;;CAGlD,OAAO,YAAY,OAAO;EACxB,MAAM,aAA8B,EAClC,SAAS,KAAK,SACf;AACD,MAAI,UACF,YAAW,QAAQ,QAAQ,KAAK;AAElC,SAAO;;;AAKX,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAY,UAAU,eAAe,OAAe;AAClD,QAAM,KAAK,SAAS,MAAM;;;AAI9B,IAAa,oBAAb,cAAuC,UAAU;CAC/C,YAAY,UAAU,gBAAgB,OAAe;AACnD,QAAM,KAAK,SAAS,MAAM;;;AAI9B,IAAa,uBAAb,cAA0C,UAAU;CAClD,YAAY,UAAU,oBAAoB,OAAe;AACvD,QAAM,KAAK,SAAS,MAAM;;;AAI9B,IAAa,iBAAb,cAAoC,UAAU;CAC5C,YAAY,UAAU,aAAa,OAAe;AAChD,QAAM,KAAK,SAAS,MAAM;;;AAI9B,IAAa,gBAAb,cAAmC,UAAU;CAC3C,YAAY,U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AAM,aAAa,OAAO,OAAO,IAAI,WAAW,WAAW,CAC9D,WAAU,SAAS,QACjB,UAAU,OACX;AAIL,KAAI,IAAI,YAAY,QAClB,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,WAAW,QAAQ,CAChE,KAAI,WAAW,QAAQ,OAAO,QAC5B,OACD;AAIL,MAAK,MAAM,YAAY,OAAO,OAAO,IAAI,MAAM,CAC7C,MAAK,MAAM,aAAa,OAAO,OAAO,SAAS,EAAE;EAC/C,MAAM,KAAK;AACX,MAAI,CAAC,GAAG,WAAY;AACpB,OAAK,MAAM,aAAa,GAAG,WACzB,KAAI,YAAY,UACd,WAAU,SAAS,QACjB,UAAU,OACX;;AAMT,QAAO"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/errors.ts","../src/schema.ts"],"sourcesContent":["import type { AxiosError } from 'axios'\n// biome-ignore lint/style/useNodejsImportProtocol: use 'util' for RN Metro + polyfill support\nimport { inspect } from 'util'\n\nexport type ClientErrorCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451\nexport type ServerErrorCode =\n | 500\n | 501\n | 502\n | 503\n | 504\n | 505\n | 506\n | 507\n | 508\n | 510\n | 511\nexport type ErrorCode = ClientErrorCode | ServerErrorCode\n\ntype SerializedError = {\n message: string\n stack?: string\n}\n\n// Base HttpError class\nexport class HttpError extends Error {\n statusCode: number\n\n constructor(statusCode: number, message: string, cause?: Error) {\n super(message)\n if (cause) {\n this.stack = undefined\n this.cause = cause\n }\n this.statusCode = statusCode\n Object.setPrototypeOf(this, HttpError.prototype)\n }\n\n toJSON(showStack = false) {\n const serialized: SerializedError = {\n message: this.message,\n }\n if (showStack) {\n serialized.stack = inspect(this)\n }\n return serialized\n }\n}\n\n// Specific error classes extending HttpError\nexport class BadRequestError extends HttpError {\n constructor(message = 'Bad Request', cause?: Error) {\n super(400, message, cause)\n }\n}\n\nexport class UnauthorizedError extends HttpError {\n constructor(message = 'Unauthorized', cause?: Error) {\n super(401, message, cause)\n }\n}\n\nexport class PaymentRequiredError extends HttpError {\n constructor(message = 'Payment Required', cause?: Error) {\n super(402, message, cause)\n }\n}\n\nexport class ForbiddenError extends HttpError {\n constructor(message = 'Forbidden', cause?: Error) {\n super(403, message, cause)\n }\n}\n\nexport class NotFoundError extends HttpError {\n constructor(message = 'Not Found', cause?: Error) {\n super(404, message, cause)\n }\n}\n\nexport class MethodNotAllowedError extends HttpError {\n constructor(message = 'Method Not Allowed', cause?: Error) {\n super(405, message, cause)\n }\n}\n\nexport class NotAcceptableError extends HttpError {\n constructor(message = 'Not Acceptable', cause?: Error) {\n super(406, message, cause)\n }\n}\n\nexport class ProxyAuthenticationRequiredError extends HttpError {\n constructor(message = 'Proxy Authentication Required', cause?: Error) {\n super(407, message, cause)\n }\n}\n\nexport class RequestTimeoutError extends HttpError {\n constructor(message = 'Request Timeout', cause?: Error) {\n super(408, message, cause)\n }\n}\n\nexport class ConflictError extends HttpError {\n constructor(message = 'Conflict', cause?: Error) {\n super(409, message, cause)\n }\n}\n\nexport class GoneError extends HttpError {\n constructor(message = 'Gone', cause?: Error) {\n super(410, message, cause)\n }\n}\n\nexport class LengthRequiredError extends HttpError {\n constructor(message = 'Length Required', cause?: Error) {\n super(411, message, cause)\n }\n}\n\nexport class PreconditionFailedError extends HttpError {\n constructor(message = 'Precondition Failed', cause?: Error) {\n super(412, message, cause)\n }\n}\n\nexport class PayloadTooLargeError extends HttpError {\n constructor(message = 'Payload Too Large', cause?: Error) {\n super(413, message, cause)\n }\n}\n\nexport class URITooLongError extends HttpError {\n constructor(message = 'URI Too Long', cause?: Error) {\n super(414, message, cause)\n }\n}\n\nexport class UnsupportedMediaTypeError extends HttpError {\n constructor(message = 'Unsupported Media Type', cause?: Error) {\n super(415, message, cause)\n }\n}\n\nexport class RangeNotSatisfiableError extends HttpError {\n constructor(message = 'Range Not Satisfiable', cause?: Error) {\n super(416, message, cause)\n }\n}\n\nexport class ExpectationFailedError extends HttpError {\n constructor(message = 'Expectation Failed', cause?: Error) {\n super(417, message, cause)\n }\n}\n\nexport class IMATeapotError extends HttpError {\n constructor(message = \"I'm a teapot\", cause?: Error) {\n super(418, message, cause)\n }\n}\n\nexport class MisdirectedRequestError extends HttpError {\n constructor(message = 'Misdirected Request', cause?: Error) {\n super(421, message, cause)\n }\n}\n\nexport class UnprocessableEntityError extends HttpError {\n constructor(message = 'Unprocessable Entity', cause?: Error) {\n super(422, message, cause)\n }\n}\n\nexport class LockedError extends HttpError {\n constructor(message = 'Locked', cause?: Error) {\n super(423, message, cause)\n }\n}\n\nexport class FailedDependencyError extends HttpError {\n constructor(message = 'Failed Dependency', cause?: Error) {\n super(424, message, cause)\n }\n}\n\nexport class TooEarlyError extends HttpError {\n constructor(message = 'Too Early', cause?: Error) {\n super(425, message, cause)\n }\n}\n\nexport class UpgradeRequiredError extends HttpError {\n constructor(message = 'Upgrade Required', cause?: Error) {\n super(426, message, cause)\n }\n}\n\nexport class PreconditionRequiredError extends HttpError {\n constructor(message = 'Precondition Required', cause?: Error) {\n super(428, message, cause)\n }\n}\n\nexport class TooManyRequestsError extends HttpError {\n constructor(message = 'Too Many Requests', cause?: Error) {\n super(429, message, cause)\n }\n}\n\nexport class RequestHeaderFieldsTooLargeError extends HttpError {\n constructor(message = 'Request Header Fields Too Large', cause?: Error) {\n super(431, message, cause)\n }\n}\n\nexport class UnavailableForLegalReasonsError extends HttpError {\n constructor(message = 'Unavailable For Legal Reasons', cause?: Error) {\n super(451, message, cause)\n }\n}\n\n// 500 Range Error Classes\nexport class InternalServerError extends HttpError {\n constructor(message = 'Internal Server Error', cause?: Error) {\n super(500, message, cause)\n }\n}\n\nexport class NotImplementedError extends HttpError {\n constructor(message = 'Not Implemented', cause?: Error) {\n super(501, message, cause)\n }\n}\n\nexport class BadGatewayError extends HttpError {\n constructor(message = 'Bad Gateway', cause?: Error) {\n super(502, message, cause)\n }\n}\n\nexport class ServiceUnavailableError extends HttpError {\n constructor(message = 'Service Unavailable', cause?: Error) {\n super(503, message, cause)\n }\n}\n\nexport class GatewayTimeoutError extends HttpError {\n constructor(message = 'Gateway Timeout', cause?: Error) {\n super(504, message, cause)\n }\n}\n\nexport class HTTPVersionNotSupportedError extends HttpError {\n constructor(message = 'HTTP Version Not Supported', cause?: Error) {\n super(505, message, cause)\n }\n}\n\nexport class VariantAlsoNegotiatesError extends HttpError {\n constructor(message = 'Variant Also Negotiates', cause?: Error) {\n super(506, message, cause)\n }\n}\n\nexport class InsufficientStorageError extends HttpError {\n constructor(message = 'Insufficient Storage', cause?: Error) {\n super(507, message, cause)\n }\n}\n\nexport class LoopDetectedError extends HttpError {\n constructor(message = 'Loop Detected', cause?: Error) {\n super(508, message, cause)\n }\n}\n\nexport class NotExtendedError extends HttpError {\n constructor(message = 'Not Extended', cause?: Error) {\n super(510, message, cause)\n }\n}\n\nexport class NetworkAuthenticationRequiredError extends HttpError {\n constructor(message = 'Network Authentication Required', cause?: Error) {\n super(511, message, cause)\n }\n}\n\n// Function to create an error based on status code\nexport const createHttpError = (\n statusCode: ErrorCode,\n message?: string,\n cause?: Error\n): HttpError => {\n switch (statusCode) {\n case 400:\n return new BadRequestError(message, cause)\n case 401:\n return new UnauthorizedError(message, cause)\n case 402:\n return new PaymentRequiredError(message, cause)\n case 403:\n return new ForbiddenError(message, cause)\n case 404:\n return new NotFoundError(message, cause)\n case 405:\n return new MethodNotAllowedError(message, cause)\n case 406:\n return new NotAcceptableError(message, cause)\n case 407:\n return new ProxyAuthenticationRequiredError(message, cause)\n case 408:\n return new RequestTimeoutError(message, cause)\n case 409:\n return new ConflictError(message, cause)\n case 410:\n return new GoneError(message, cause)\n case 411:\n return new LengthRequiredError(message, cause)\n case 412:\n return new PreconditionFailedError(message, cause)\n case 413:\n return new PayloadTooLargeError(message, cause)\n case 414:\n return new URITooLongError(message, cause)\n case 415:\n return new UnsupportedMediaTypeError(message, cause)\n case 416:\n return new RangeNotSatisfiableError(message, cause)\n case 417:\n return new ExpectationFailedError(message, cause)\n case 418:\n return new IMATeapotError(message, cause)\n case 421:\n return new MisdirectedRequestError(message, cause)\n case 422:\n return new UnprocessableEntityError(message, cause)\n case 423:\n return new LockedError(message, cause)\n case 424:\n return new FailedDependencyError(message, cause)\n case 425:\n return new TooEarlyError(message, cause)\n case 426:\n return new UpgradeRequiredError(message, cause)\n case 428:\n return new PreconditionRequiredError(message, cause)\n case 429:\n return new TooManyRequestsError(message, cause)\n case 431:\n return new RequestHeaderFieldsTooLargeError(message, cause)\n case 451:\n return new UnavailableForLegalReasonsError(message, cause)\n case 500:\n return new InternalServerError(message, cause)\n case 501:\n return new NotImplementedError(message, cause)\n case 502:\n return new BadGatewayError(message, cause)\n case 503:\n return new ServiceUnavailableError(message, cause)\n case 504:\n return new GatewayTimeoutError(message, cause)\n case 505:\n return new HTTPVersionNotSupportedError(message, cause)\n case 506:\n return new VariantAlsoNegotiatesError(message, cause)\n case 507:\n return new InsufficientStorageError(message, cause)\n case 508:\n return new LoopDetectedError(message, cause)\n case 510:\n return new NotExtendedError(message, cause)\n case 511:\n return new NetworkAuthenticationRequiredError(message, cause)\n default:\n return new HttpError(statusCode, message ?? 'Error', cause)\n }\n}\n\nexport const fromAxiosError = (axiosError: AxiosError): HttpError => {\n // Default to 500 Internal Server Error if the status code is not available\n const statusCode = (axiosError.response?.status || 500) as ErrorCode\n const message =\n axiosError.response?.statusText ||\n axiosError.message ||\n 'Internal Server Error'\n\n // The internal error can contain more specific details about the Axios error\n const cause = new Error(axiosError.message)\n cause.name = axiosError.name\n cause.stack = axiosError.stack\n // If the error response has a data property pass it along\n cause.cause = axiosError?.response?.data\n\n return createHttpError(statusCode, message, cause)\n}\n","import type { SchemaObject } from './common'\nimport type { OpenApiDocument, OperationObject } from './openapi'\nimport type { APIServerDefinition } from './types'\n\nconst clone = <T>(orig: T): T => JSON.parse(JSON.stringify(orig))\n\n/**\n * Marks unimplemented paths as deprecated and tags them with 'not-implemented'.\n * Use to hide or visually separate endpoints not yet available on the given server.\n *\n * @param document - The OpenAPI document to modify\n * @param server - The server definition to check against for implemented paths\n * @returns A cloned document with unimplemented paths marked as deprecated\n */\nexport const disableUnimplementedPaths = <\n T extends OpenApiDocument,\n S extends APIServerDefinition,\n>(\n document: T,\n server: S\n): T => {\n const doc = clone(document)\n for (const path of Object.keys(doc.paths)) {\n const pathObj = doc.paths[path as keyof typeof doc.paths]\n const fixedPath = path.replace(/{(.+)}/, ':$1')\n if (!server[fixedPath] && !fixedPath.startsWith('/health')) {\n for (const method of Object.values(pathObj)) {\n const operation = method as OperationObject\n operation.deprecated = true\n operation.tags = [...(operation.tags ?? []), 'not-implemented']\n }\n }\n }\n return doc\n}\n\n/**\n * Appends the API version segment to all server URLs.\n *\n * @param document - The OpenAPI document to modify\n * @param version - The version string to append\n * @returns A cloned document with updated server URLs\n */\nexport const appendVersionToServers = <T extends OpenApiDocument>(\n document: T,\n version: string\n): T => {\n const doc = clone(document)\n for (const server of doc.servers || []) {\n server.url = `${server.url}/${version}`\n }\n return doc\n}\n\n/**\n * Resolves a $ref string to its schema definition within the document.\n *\n * @param ref - A JSON pointer ref string e.g. `#/components/schemas/Foo`\n * @param doc - The OpenAPI document to resolve against\n * @returns The resolved schema, or undefined if the ref cannot be resolved\n */\nexport const resolveRef = (\n ref: string,\n doc: OpenApiDocument\n): SchemaObject | undefined => {\n const parts = ref.replace('#/', '').split('/')\n let current: unknown = doc\n for (const part of parts) {\n if (typeof current !== 'object' || current === null) return undefined\n current = (current as Record<string, unknown>)[part]\n }\n return current as SchemaObject\n}\n\n/**\n * Flattens all schemas typed as oneOf[$ref, $ref, ...] where all refs resolve to enums\n * into a single merged enum. Enables API UI tools to render a dropdown instead of a text input.\n *\n * @param document - The OpenAPI document to modify\n * @returns A cloned document with flattened enum schemas\n */\nexport const flattenEnums = <T extends OpenApiDocument>(document: T): T => {\n const doc = clone(document)\n\n const flatten = (schema: SchemaObject): SchemaObject => {\n if (!('oneOf' in schema) || !schema.oneOf) return schema\n\n let allEnums = true\n const enumValues: unknown[] = []\n\n for (const s of schema.oneOf) {\n if (!('$ref' in s)) {\n allEnums = false\n break\n }\n const resolved = resolveRef(s.$ref, doc)\n if (!resolved || !('enum' in resolved) || !Array.isArray(resolved.enum)) {\n allEnums = false\n break\n }\n for (const v of resolved.enum) enumValues.push(v)\n }\n\n if (allEnums && enumValues.length > 0) {\n return { type: 'string', enum: [...new Set(enumValues)] as string[] }\n }\n return schema\n }\n\n if (doc.components?.parameters) {\n for (const parameter of Object.values(doc.components.parameters)) {\n parameter.schema = flatten(\n parameter.schema as SchemaObject\n ) as unknown as typeof parameter.schema\n }\n }\n\n if (doc.components?.schemas) {\n for (const [key, schema] of Object.entries(doc.components.schemas)) {\n doc.components.schemas[key] = flatten(\n schema as SchemaObject\n ) as unknown as typeof schema\n }\n }\n\n for (const pathItem of Object.values(doc.paths)) {\n for (const operation of Object.values(pathItem)) {\n const op = operation as OperationObject\n if (!op.parameters) continue\n for (const parameter of op.parameters) {\n if ('schema' in parameter) {\n parameter.schema = flatten(\n parameter.schema as SchemaObject\n ) as unknown as typeof parameter.schema\n }\n }\n }\n }\n\n return doc\n}\n"],"mappings":";;AAsDA,IAAa,YAAb,MAAa,kBAAkB,MAAM;CACnC;CAEA,YAAY,YAAoB,SAAiB,OAAe;AAC9D,QAAM,QAAQ;AACd,MAAI,OAAO;AACT,QAAK,QAAQ,KAAA;AACb,QAAK,QAAQ;;AAEf,OAAK,aAAa;AAClB,SAAO,eAAe,MAAM,UAAU,UAAU;;CAGlD,OAAO,YAAY,OAAO;EACxB,MAAM,aAA8B,EAClC,SAAS,KAAK,SACf;AACD,MAAI,UACF,YAAW,QAAQ,QAAQ,KAAK;AAElC,SAAO;;;AAKX,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAY,UAAU,eAAe,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AAI,EAAE,UAAU,IAAI;AAClB,eAAW;AACX;;GAEF,MAAM,WAAW,WAAW,EAAE,MAAM,IAAI;AACxC,OAAI,CAAC,YAAY,EAAE,UAAU,aAAa,CAAC,MAAM,QAAQ,SAAS,KAAK,EAAE;AACvE,eAAW;AACX;;AAEF,QAAK,MAAM,KAAK,SAAS,KAAM,YAAW,KAAK,EAAE;;AAGnD,MAAI,YAAY,WAAW,SAAS,EAClC,QAAO;GAAE,MAAM;GAAU,MAAM,CAAC,GAAG,IAAI,IAAI,WAAW,CAAC;GAAc;AAEvE,SAAO;;AAGT,KAAI,IAAI,YAAY,WAClB,MAAK,MAAM,aAAa,OAAO,OAAO,IAAI,WAAW,WAAW,CAC9D,WAAU,SAAS,QACjB,UAAU,OACX;AAIL,KAAI,IAAI,YAAY,QAClB,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,WAAW,QAAQ,CAChE,KAAI,WAAW,QAAQ,OAAO,QAC5B,OACD;AAIL,MAAK,MAAM,YAAY,OAAO,OAAO,IAAI,MAAM,CAC7C,MAAK,MAAM,aAAa,OAAO,OAAO,SAAS,EAAE;EAC/C,MAAM,KAAK;AACX,MAAI,CAAC,GAAG,WAAY;AACpB,OAAK,MAAM,aAAa,GAAG,WACzB,KAAI,YAAY,UACd,WAAU,SAAS,QACjB,UAAU,OACX;;AAMT,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/openapi-core",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",