- Handle type arrays: type: ['string', 'null'] → string | null - Handle const keyword: const: "active" → 'active' literal type - Handle nullable (OpenAPI 3.0 backward compatibility) - Extract and display webhook count in metadata - Add security escaping for string literals and JSDoc comments - Add OpenAPI 3.1 test fixture and 12 unit tests Fixes #365 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
96 lines
2.3 KiB
TypeScript
96 lines
2.3 KiB
TypeScript
import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
|
|
export type OpenAPISpec = OpenAPI.Document;
|
|
export type OpenAPIV3Spec = OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
|
|
/** Standard HTTP methods supported in OpenAPI specifications */
|
|
export const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'] as const;
|
|
|
|
/** Type derived from HTTP_METHODS constant */
|
|
export type HttpMethod = typeof HTTP_METHODS[number];
|
|
|
|
export interface ParsedSpec {
|
|
version: string;
|
|
title: string;
|
|
description?: string;
|
|
servers: string[];
|
|
pathCount: number;
|
|
schemaCount: number;
|
|
operationCount: number;
|
|
tags: string[];
|
|
/** Number of webhooks (OpenAPI 3.1+) */
|
|
webhookCount?: number;
|
|
}
|
|
|
|
export interface ValidationError {
|
|
path: string;
|
|
message: string;
|
|
severity: 'error' | 'warning';
|
|
}
|
|
|
|
export interface ValidationResult {
|
|
valid: boolean;
|
|
errors: ValidationError[];
|
|
warnings: ValidationError[];
|
|
}
|
|
|
|
export interface EndpointInfo {
|
|
method: string;
|
|
path: string;
|
|
operationId?: string;
|
|
summary?: string;
|
|
description?: string;
|
|
tags: string[];
|
|
parameters: ParameterInfo[];
|
|
requestBody?: RequestBodyInfo;
|
|
responses: ResponseInfo[];
|
|
}
|
|
|
|
export interface ParameterInfo {
|
|
name: string;
|
|
in: 'query' | 'header' | 'path' | 'cookie';
|
|
required: boolean;
|
|
description?: string;
|
|
schema?: object;
|
|
}
|
|
|
|
export interface RequestBodyInfo {
|
|
required: boolean;
|
|
description?: string;
|
|
contentTypes: string[];
|
|
}
|
|
|
|
export interface ResponseInfo {
|
|
statusCode: string;
|
|
description?: string;
|
|
contentTypes: string[];
|
|
}
|
|
|
|
export interface EndpointFilter {
|
|
method?: string;
|
|
pathPattern?: string;
|
|
tag?: string;
|
|
operationId?: string;
|
|
}
|
|
|
|
export interface SchemaInfo {
|
|
name: string;
|
|
type?: string;
|
|
description?: string;
|
|
properties?: Record<string, object>;
|
|
required?: string[];
|
|
schema: object;
|
|
}
|
|
|
|
export interface TypeScriptOptions {
|
|
/** Generate enums as union types (default: true) */
|
|
enumAsUnion?: boolean;
|
|
/** Generate enums as TypeScript enums */
|
|
enumAsEnum?: boolean;
|
|
/** Prefix for interface names (e.g., "I") */
|
|
interfacePrefix?: string;
|
|
/** Suffix for interface names (e.g., "Type") */
|
|
interfaceSuffix?: string;
|
|
/** Indentation style: '2' spaces, '4' spaces, or 'tab' */
|
|
indentation?: '2' | '4' | 'tab';
|
|
}
|