@ng-openapi/http-resource 0.0.2-pr-9-feature-http-resource-e6134bb.0
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/LICENSE +21 -0
- package/README.md +226 -0
- package/index.cjs +3788 -0
- package/index.d.ts +221 -0
- package/index.js +3749 -0
- package/package.json +88 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { ScriptTarget, ModuleKind, Project, ClassDeclaration, OptionalKind, ParameterDeclarationStructure, MethodDeclarationOverloadStructure } from 'ts-morph';
|
|
2
|
+
import { Info, ExternalDocs, Path, ParameterType, XML, BodyParameter, QueryParameter, Security, Tag } from 'swagger-schema-official';
|
|
3
|
+
|
|
4
|
+
interface Parameter {
|
|
5
|
+
name: string;
|
|
6
|
+
in: "query" | "path" | "header" | "cookie";
|
|
7
|
+
required?: boolean;
|
|
8
|
+
schema?: any;
|
|
9
|
+
type?: string;
|
|
10
|
+
format?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
interface PathInfo {
|
|
14
|
+
path: string;
|
|
15
|
+
method: string;
|
|
16
|
+
operationId?: string;
|
|
17
|
+
summary?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
parameters?: Parameter[];
|
|
21
|
+
requestBody?: RequestBody;
|
|
22
|
+
responses?: Record<string, SwaggerResponse>;
|
|
23
|
+
}
|
|
24
|
+
interface RequestBody {
|
|
25
|
+
required?: boolean;
|
|
26
|
+
content?: Record<string, {
|
|
27
|
+
schema?: SwaggerDefinition;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
interface SwaggerResponse {
|
|
31
|
+
description?: string;
|
|
32
|
+
content?: Record<string, {
|
|
33
|
+
schema?: any;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
interface SwaggerDefinition {
|
|
37
|
+
type?: ParameterType | undefined;
|
|
38
|
+
format?: string | undefined;
|
|
39
|
+
title?: string | undefined;
|
|
40
|
+
description?: string | undefined;
|
|
41
|
+
default?: any;
|
|
42
|
+
multipleOf?: number | undefined;
|
|
43
|
+
maximum?: number | undefined;
|
|
44
|
+
exclusiveMaximum?: boolean | undefined;
|
|
45
|
+
minimum?: number | undefined;
|
|
46
|
+
exclusiveMinimum?: boolean | undefined;
|
|
47
|
+
maxLength?: number | undefined;
|
|
48
|
+
minLength?: number | undefined;
|
|
49
|
+
pattern?: string | undefined;
|
|
50
|
+
maxItems?: number | undefined;
|
|
51
|
+
minItems?: number | undefined;
|
|
52
|
+
uniqueItems?: boolean | undefined;
|
|
53
|
+
maxProperties?: number | undefined;
|
|
54
|
+
minProperties?: number | undefined;
|
|
55
|
+
enum?: any[] | undefined;
|
|
56
|
+
items?: SwaggerDefinition | SwaggerDefinition[] | undefined;
|
|
57
|
+
$ref?: string | undefined;
|
|
58
|
+
allOf?: SwaggerDefinition[] | undefined;
|
|
59
|
+
additionalProperties?: SwaggerDefinition | boolean | undefined;
|
|
60
|
+
properties?: {
|
|
61
|
+
[propertyName: string]: SwaggerDefinition;
|
|
62
|
+
} | undefined;
|
|
63
|
+
discriminator?: string | undefined;
|
|
64
|
+
readOnly?: boolean | undefined;
|
|
65
|
+
nullable?: boolean | undefined;
|
|
66
|
+
xml?: XML | undefined;
|
|
67
|
+
externalDocs?: ExternalDocs | undefined;
|
|
68
|
+
example?: any;
|
|
69
|
+
required?: string[] | undefined;
|
|
70
|
+
oneOf?: SwaggerDefinition[];
|
|
71
|
+
anyOf?: SwaggerDefinition[];
|
|
72
|
+
}
|
|
73
|
+
interface SwaggerSpec {
|
|
74
|
+
openapi: string;
|
|
75
|
+
swagger: string;
|
|
76
|
+
info: Info;
|
|
77
|
+
externalDocs?: ExternalDocs | undefined;
|
|
78
|
+
host?: string | undefined;
|
|
79
|
+
basePath?: string | undefined;
|
|
80
|
+
schemes?: string[] | undefined;
|
|
81
|
+
consumes?: string[] | undefined;
|
|
82
|
+
produces?: string[] | undefined;
|
|
83
|
+
paths: {
|
|
84
|
+
[pathName: string]: Path;
|
|
85
|
+
};
|
|
86
|
+
definitions?: {
|
|
87
|
+
[definitionsName: string]: SwaggerDefinition;
|
|
88
|
+
} | undefined;
|
|
89
|
+
parameters?: {
|
|
90
|
+
[parameterName: string]: BodyParameter | QueryParameter;
|
|
91
|
+
} | undefined;
|
|
92
|
+
responses?: {
|
|
93
|
+
[responseName: string]: SwaggerResponse;
|
|
94
|
+
} | undefined;
|
|
95
|
+
security?: Array<{
|
|
96
|
+
[securityDefinitionName: string]: string[];
|
|
97
|
+
}> | undefined;
|
|
98
|
+
securityDefinitions?: {
|
|
99
|
+
[securityDefinitionName: string]: Security;
|
|
100
|
+
} | undefined;
|
|
101
|
+
tags?: Tag[] | undefined;
|
|
102
|
+
components?: {
|
|
103
|
+
schemas?: Record<string, SwaggerDefinition>;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class SwaggerParser {
|
|
108
|
+
private readonly spec;
|
|
109
|
+
private constructor();
|
|
110
|
+
static create(swaggerPathOrUrl: string, config: GeneratorConfig): Promise<SwaggerParser>;
|
|
111
|
+
private static loadContent;
|
|
112
|
+
private static isUrl;
|
|
113
|
+
private static fetchUrlContent;
|
|
114
|
+
private static parseSpecContent;
|
|
115
|
+
private static detectFormat;
|
|
116
|
+
getDefinitions(): Record<string, SwaggerDefinition>;
|
|
117
|
+
getDefinition(name: string): SwaggerDefinition | undefined;
|
|
118
|
+
resolveReference(ref: string): SwaggerDefinition | undefined;
|
|
119
|
+
getAllDefinitionNames(): string[];
|
|
120
|
+
getSpec(): SwaggerSpec;
|
|
121
|
+
getPaths(): Record<string, any>;
|
|
122
|
+
isValidSpec(): boolean;
|
|
123
|
+
getSpecVersion(): {
|
|
124
|
+
type: "swagger" | "openapi";
|
|
125
|
+
version: string;
|
|
126
|
+
} | null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Interface for generator instances
|
|
131
|
+
*/
|
|
132
|
+
interface IPluginGenerator {
|
|
133
|
+
/**
|
|
134
|
+
* Generate code files
|
|
135
|
+
*/
|
|
136
|
+
generate(outputRoot: string): void;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface GeneratorConfig {
|
|
140
|
+
input: string;
|
|
141
|
+
output: string;
|
|
142
|
+
clientName?: string;
|
|
143
|
+
validateInput?: (spec: SwaggerSpec) => boolean;
|
|
144
|
+
options: {
|
|
145
|
+
dateType: "string" | "Date";
|
|
146
|
+
enumStyle: "enum" | "union";
|
|
147
|
+
generateServices?: boolean;
|
|
148
|
+
generateEnumBasedOnDescription?: boolean;
|
|
149
|
+
customHeaders?: Record<string, string>;
|
|
150
|
+
responseTypeMapping?: {
|
|
151
|
+
[contentType: string]: "json" | "blob" | "arraybuffer" | "text";
|
|
152
|
+
};
|
|
153
|
+
customizeMethodName?: (operationId: string) => string;
|
|
154
|
+
};
|
|
155
|
+
compilerOptions?: {
|
|
156
|
+
declaration?: boolean;
|
|
157
|
+
target?: ScriptTarget;
|
|
158
|
+
module?: ModuleKind;
|
|
159
|
+
strict?: boolean;
|
|
160
|
+
};
|
|
161
|
+
plugins?: (new (...args: any) => IPluginGenerator)[];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare class HttpResourceGenerator implements IPluginGenerator {
|
|
165
|
+
private project;
|
|
166
|
+
private parser;
|
|
167
|
+
private spec;
|
|
168
|
+
private config;
|
|
169
|
+
private methodGenerator;
|
|
170
|
+
private indexGenerator;
|
|
171
|
+
constructor(parser: SwaggerParser, project: Project, config: GeneratorConfig);
|
|
172
|
+
static create(swaggerPathOrUrl: string, project: Project, config: GeneratorConfig): Promise<HttpResourceGenerator>;
|
|
173
|
+
generate(outputRoot: string): void;
|
|
174
|
+
private groupPathsByController;
|
|
175
|
+
private generateServiceFile;
|
|
176
|
+
private addImports;
|
|
177
|
+
private addServiceClass;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare class HttpResourceMethodGenerator {
|
|
181
|
+
#private;
|
|
182
|
+
private config;
|
|
183
|
+
private bodyGenerator;
|
|
184
|
+
private paramsGenerator;
|
|
185
|
+
constructor(config: GeneratorConfig);
|
|
186
|
+
addResourceMethod(serviceClass: ClassDeclaration, operation: PathInfo): void;
|
|
187
|
+
generateMethodName(operation: PathInfo): string;
|
|
188
|
+
generateReturnType(operation: PathInfo): string;
|
|
189
|
+
generateMethodOverload(methodParams: OptionalKind<ParameterDeclarationStructure>[]): OptionalKind<MethodDeclarationOverloadStructure>[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare class HttpResourceIndexGenerator {
|
|
193
|
+
private project;
|
|
194
|
+
constructor(project: Project);
|
|
195
|
+
generateIndex(outputRoot: string): void;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
declare class HttpResourceMethodBodyGenerator {
|
|
199
|
+
private config;
|
|
200
|
+
constructor(config: GeneratorConfig);
|
|
201
|
+
generateMethodBody(operation: PathInfo): string;
|
|
202
|
+
private createGenerationContext;
|
|
203
|
+
private generateUrl;
|
|
204
|
+
private generateQueryParams;
|
|
205
|
+
private generateHeaders;
|
|
206
|
+
private generateRequestOptions;
|
|
207
|
+
private generateHttpResource;
|
|
208
|
+
private determineResponseType;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare class HttpResourceMethodParamsGenerator {
|
|
212
|
+
private config;
|
|
213
|
+
constructor(config: GeneratorConfig);
|
|
214
|
+
generateMethodParameters(operation: PathInfo): OptionalKind<ParameterDeclarationStructure>[];
|
|
215
|
+
generateApiParameters(operation: PathInfo): OptionalKind<ParameterDeclarationStructure>[];
|
|
216
|
+
addOptionsParameter(responseType: string): OptionalKind<ParameterDeclarationStructure>[];
|
|
217
|
+
private getApiReturnType;
|
|
218
|
+
private getResourceRawDataType;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { HttpResourceGenerator, HttpResourceIndexGenerator, HttpResourceMethodBodyGenerator, HttpResourceMethodGenerator, HttpResourceMethodParamsGenerator };
|