Skip to content

Commit

Permalink
feat(parser): 增加 DocumentParser
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Apr 14, 2023
1 parent c6fdd7f commit 05de46e
Show file tree
Hide file tree
Showing 4 changed files with 1,556 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/parsers/DocumentParser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { PathsParser } from './PathsParser';
import { TypeDocument } from './types';

export class DocumentParser extends PathsParser {}
export class DocumentParser extends PathsParser {
parse(): TypeDocument {
const components = this.parseComponents();
const paths = this.parsePaths();
return { components, paths };
}
}
7 changes: 6 additions & 1 deletion src/parsers/PathsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ export class PathsParser extends ComponentsParser {
}

parseOperationRequest(name: string, body: NonNullable<OpenAPIV3.OperationObject['requestBody']>) {
if (this.isReference(body)) return this.parseSchemaNever(name, true, {});
if (this.isReference(body)) return;

const { content } = body;
const okMedia = content[this.options.okMediaType];
if (!okMedia) return;

return this.parseOperationMedia(name, okMedia);
}

Expand All @@ -114,6 +117,8 @@ export class PathsParser extends ComponentsParser {
if (!content) return;

const okMedia = content[this.options.okMediaType];
if (!okMedia) return;

return this.parseOperationMedia(name, okMedia);
}

Expand Down
9 changes: 6 additions & 3 deletions src/parsers/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { OpenAPIV3 } from 'openapi-types';

export type TypeKind = 'origin' | 'alias';
export type TypeUnit = 'number' | 'string' | 'boolean' | 'never' | 'object' | 'array';

Expand Down Expand Up @@ -37,7 +35,7 @@ export interface ParseOptions {
}

export interface TypeOperation {
method: OpenAPIV3.HttpMethods;
method: string;
url: string;
name: string;
summary?: string;
Expand All @@ -59,3 +57,8 @@ export interface TypeQueryPath {
query: TypeList;
path: TypeList;
}

export interface TypeDocument {
components: TypeList;
paths: TypeOperations;
}
Loading

0 comments on commit 05de46e

Please sign in to comment.