api 4.5.1 → 5.0.0-beta.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/LICENSE +1 -1
- package/README.md +32 -162
- package/bin/api +2 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +91 -0
- package/dist/cache.d.ts +30 -0
- package/dist/cache.js +217 -0
- package/dist/cli/codegen/index.d.ts +4 -0
- package/dist/cli/codegen/index.js +23 -0
- package/dist/cli/codegen/language.d.ts +27 -0
- package/dist/cli/codegen/language.js +19 -0
- package/dist/cli/codegen/languages/typescript.d.ts +99 -0
- package/dist/cli/codegen/languages/typescript.js +769 -0
- package/dist/cli/commands/index.d.ts +4 -0
- package/dist/cli/commands/index.js +9 -0
- package/dist/cli/commands/install.d.ts +3 -0
- package/dist/cli/commands/install.js +230 -0
- package/dist/cli/lib/prompt.d.ts +9 -0
- package/dist/cli/lib/prompt.js +81 -0
- package/dist/cli/logger.d.ts +1 -0
- package/dist/cli/logger.js +16 -0
- package/dist/cli/storage.d.ts +105 -0
- package/dist/cli/storage.js +264 -0
- package/dist/core/getJSONSchemaDefaults.d.ts +15 -0
- package/dist/core/getJSONSchemaDefaults.js +62 -0
- package/dist/core/index.d.ts +32 -0
- package/dist/core/index.js +143 -0
- package/dist/core/parseResponse.d.ts +1 -0
- package/dist/core/parseResponse.js +65 -0
- package/dist/core/prepareAuth.d.ts +5 -0
- package/dist/core/prepareAuth.js +55 -0
- package/dist/core/prepareParams.d.ts +24 -0
- package/dist/core/prepareParams.js +351 -0
- package/dist/core/prepareServer.d.ts +13 -0
- package/dist/core/prepareServer.js +50 -0
- package/dist/fetcher.d.ts +54 -0
- package/dist/fetcher.js +165 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +276 -0
- package/dist/packageInfo.d.ts +2 -0
- package/dist/packageInfo.js +6 -0
- package/package.json +67 -28
- package/src/.sink.d.ts +1 -0
- package/src/bin.ts +20 -0
- package/src/cache.ts +212 -0
- package/src/cli/codegen/index.ts +31 -0
- package/src/cli/codegen/language.ts +47 -0
- package/src/cli/codegen/languages/typescript.ts +807 -0
- package/src/cli/commands/index.ts +5 -0
- package/src/cli/commands/install.ts +196 -0
- package/src/cli/lib/prompt.ts +29 -0
- package/src/cli/logger.ts +10 -0
- package/src/cli/storage.ts +297 -0
- package/src/core/getJSONSchemaDefaults.ts +74 -0
- package/src/core/index.ts +108 -0
- package/src/{lib/parseResponse.js → core/parseResponse.ts} +5 -7
- package/src/core/prepareAuth.ts +85 -0
- package/src/core/prepareParams.ts +338 -0
- package/src/{lib/prepareServer.js → core/prepareServer.ts} +13 -12
- package/src/fetcher.ts +141 -0
- package/src/index.ts +212 -0
- package/src/packageInfo.ts +3 -0
- package/src/typings.d.ts +3 -0
- package/tsconfig.json +24 -0
- package/src/cache.js +0 -225
- package/src/index.js +0 -177
- package/src/lib/getSchema.js +0 -34
- package/src/lib/index.js +0 -11
- package/src/lib/prepareAuth.js +0 -69
- package/src/lib/prepareParams.js +0 -198
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type Oas from 'oas';
|
|
2
|
+
import type { Operation } from 'oas';
|
|
3
|
+
import type { JSONSchema, SchemaObject } from 'oas/@types/rmoas.types';
|
|
4
|
+
import type { ClassDeclaration, MethodDeclaration } from 'ts-morph';
|
|
5
|
+
import type Storage from '../../storage';
|
|
6
|
+
import type { InstallerOptions } from '../language';
|
|
7
|
+
import CodeGeneratorLanguage from '../language';
|
|
8
|
+
import { Project } from 'ts-morph';
|
|
9
|
+
declare type OperationTypeHousing = {
|
|
10
|
+
types: {
|
|
11
|
+
params?: false | Record<'body' | 'formData' | 'metadata', string>;
|
|
12
|
+
responses?: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
operation: Operation;
|
|
15
|
+
};
|
|
16
|
+
export default class TSGenerator extends CodeGeneratorLanguage {
|
|
17
|
+
project: Project;
|
|
18
|
+
outputJS: boolean;
|
|
19
|
+
compilerTarget: 'cjs' | 'esm';
|
|
20
|
+
types: Map<string, string>;
|
|
21
|
+
files: Record<string, string>;
|
|
22
|
+
methodGenerics: Map<string, MethodDeclaration>;
|
|
23
|
+
sdk: ClassDeclaration;
|
|
24
|
+
schemas: Map<string, {
|
|
25
|
+
schema: SchemaObject;
|
|
26
|
+
name: string;
|
|
27
|
+
tsType?: string;
|
|
28
|
+
}>;
|
|
29
|
+
constructor(spec: Oas, specPath: string, identifier: string, opts?: {
|
|
30
|
+
outputJS?: boolean;
|
|
31
|
+
compilerTarget?: 'cjs' | 'esm';
|
|
32
|
+
});
|
|
33
|
+
static formatter(content: string): string;
|
|
34
|
+
installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Compile the current OpenAPI definition into a TypeScript library.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
generator(): Promise<{
|
|
40
|
+
[x: string]: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a generic HTTP method accessor on the SDK.
|
|
44
|
+
*
|
|
45
|
+
* @param method
|
|
46
|
+
*/
|
|
47
|
+
createGenericMethodAccessor(method: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Create operation accessors on the SDK.
|
|
50
|
+
*
|
|
51
|
+
* @param operation
|
|
52
|
+
* @param operationId
|
|
53
|
+
* @param paramTypes
|
|
54
|
+
* @param responseTypes
|
|
55
|
+
*/
|
|
56
|
+
createOperationAccessor(operation: Operation, operationId: string, paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses']): void;
|
|
57
|
+
/**
|
|
58
|
+
* Convert a JSON Schema object into a readily available TypeScript type or interface along with
|
|
59
|
+
* any `$ref` pointers that are in use and turn those into TS types too.
|
|
60
|
+
*
|
|
61
|
+
* Under the hood this uses https://npm.im/json-schema-to-typescript for all composition and
|
|
62
|
+
* conversion.
|
|
63
|
+
*
|
|
64
|
+
* @param schema
|
|
65
|
+
* @param name
|
|
66
|
+
*/
|
|
67
|
+
convertJSONSchemaToTypescript(schema: JSONSchema, name: string): Promise<{
|
|
68
|
+
primaryType: string;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Scour through the current OpenAPI definition and compile a store of every operation, along
|
|
72
|
+
* with every HTTP method that's in use, and their available TypeScript types that we can use,
|
|
73
|
+
* along with every HTTP method that's in use.
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
loadOperationsAndMethods(): Promise<{
|
|
77
|
+
operations: Record<string, OperationTypeHousing>;
|
|
78
|
+
methods: Set<unknown>;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Compile the parameter (path, query, cookie, and header) schemas for an API operation into
|
|
82
|
+
* usable TypeScript types.
|
|
83
|
+
*
|
|
84
|
+
* @param operation
|
|
85
|
+
* @param operationId
|
|
86
|
+
*/
|
|
87
|
+
prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"formData" | "body" | "metadata", string>;
|
|
88
|
+
/**
|
|
89
|
+
* Compile the response schemas for an API operation into usable TypeScript types.
|
|
90
|
+
*
|
|
91
|
+
* @todo what does this do for a spec that has no responses?
|
|
92
|
+
* @param operation
|
|
93
|
+
* @param operationId
|
|
94
|
+
*/
|
|
95
|
+
prepareResponseTypesForOperation(operation: Operation, operationId: string): {
|
|
96
|
+
[x: string]: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export {};
|