@povio/openapi-codegen-cli 0.5.0 → 0.5.1
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/README.md +23 -15
- package/dist/commands/generate.d.ts +1 -1
- package/dist/generators/const/acl.const.d.ts +2 -2
- package/dist/generators/const/deps.const.d.ts +17 -0
- package/dist/generators/core/SchemaResolver.class.d.ts +1 -0
- package/dist/generators/generate/generateAppRestClient.d.ts +2 -0
- package/dist/generators/types/generate.d.ts +4 -0
- package/dist/generators/types/metadata.d.ts +2 -2
- package/dist/generators/utils/deps.utils.d.ts +3 -0
- package/dist/generators/utils/file.utils.d.ts +2 -2
- package/dist/generators/utils/generate/generate.utils.d.ts +6 -2
- package/dist/index.js +47 -47
- package/dist/sh.js +64 -64
- package/package.json +3 -1
- package/src/assets/react-query.types.ts +24 -0
- package/src/assets/rest-client.ts +107 -0
- package/src/assets/rest-interceptor.ts +22 -0
- package/src/generators/templates/app-rest-client.hbs +7 -0
- package/src/generators/templates/endpoints.hbs +2 -2
- package/dist/generators/const/template.const.d.ts +0 -10
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# OpenAPI code generation CLI
|
|
2
2
|
|
|
3
|
-
**NOTE:** This CLI tool is
|
|
3
|
+
**NOTE:** This CLI tool is primarily designed for use within our organization. The generated code output aligns with our internal template. If you are using this tool without our internal template, make sure to use it in standalone mode.
|
|
4
4
|
|
|
5
|
-
Use this tool to generate code (Zod schemas, API definitions and React queries) from OpenAPI v3 specification. API definitions are
|
|
5
|
+
Use this tool to generate code (Zod schemas, TypeScript types, API definitions, and React queries) from an OpenAPI v3 specification. API definitions are generated to use a REST client wrapper that utilizes Axios. React queries are generated in alignment with our code standards, without the need for explicit types.
|
|
6
6
|
|
|
7
7
|
The tool partially leverages code from [openapi-zod-client](https://github.com/astahmer/openapi-zod-client) repository.
|
|
8
8
|
|
|
@@ -18,37 +18,45 @@ yarn add @povio/openapi-codegen-cli
|
|
|
18
18
|
yarn openapi-codegen generate --input http://localhost:3001/docs-json
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
#### Standalone mode
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn openapi-codegen generate --input http://localhost:3001/docs-json --standalone
|
|
25
|
+
```
|
|
26
|
+
|
|
21
27
|
## Options
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
#### Generate command (generates Zod schemas, API definitions and React queries)
|
|
24
30
|
|
|
25
31
|
```sh
|
|
26
|
-
--input Path/
|
|
32
|
+
--input Path/URL to OpenAPI/Swagger document as JSON/YAML
|
|
27
33
|
--output Output path (default: 'output')
|
|
28
34
|
--includeNamespaces Include namespaces inside generated files (default: true)
|
|
29
35
|
--splitByTags Split output into directories based on tags in OpenAPI operations (default: true)
|
|
30
|
-
--defaultTag Default tag name for code shared
|
|
31
|
-
--excludeTags Comma
|
|
32
|
-
--extractEnums
|
|
33
|
-
--removeOperationPrefixEndingWith
|
|
34
|
-
--importPath Import path (default: 'ts', possible: 'ts' | 'relative' | 'absolute')
|
|
35
|
-
--prettier Run
|
|
36
|
+
--defaultTag Default tag name for code shared across multiple tags (default: 'Common')
|
|
37
|
+
--excludeTags Comma-separated list of tags to exclude from the output
|
|
38
|
+
--extractEnums Extract enums as separate Zod schemas (default: true)
|
|
39
|
+
--removeOperationPrefixEndingWith Remove prefixes that end with the specified value from operation names (default: 'Controller_')
|
|
40
|
+
--importPath Import path (default: 'ts', possible values: 'ts' | 'relative' | 'absolute')
|
|
41
|
+
--prettier Run the Prettier command on the output after code generation (default: true)
|
|
36
42
|
--verbose Show log messages during execution
|
|
43
|
+
--standalone Add any missing classes or types—e.g., REST client class, React Query type extensions, etc. (default: false)
|
|
44
|
+
--baseUrl (Standalone mode only) Base URL for the REST client; falls back to the one defined in the OpenAPI spec
|
|
37
45
|
```
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
#### Check command (checks if OpenAPI spec is compliant)
|
|
40
48
|
|
|
41
49
|
```sh
|
|
42
|
-
--input Path/
|
|
50
|
+
--input Path/URL to OpenAPI/Swagger document as JSON/YAML
|
|
43
51
|
--splitByTags Split output into directories based on tags in OpenAPI operations (default: true)
|
|
44
|
-
--defaultTag Default tag name for code shared
|
|
45
|
-
--excludeTags Comma
|
|
52
|
+
--defaultTag Default tag name for code shared across multiple tags (default: 'Common')
|
|
53
|
+
--excludeTags Comma-separated list of tags to exclude from the output
|
|
46
54
|
--verbose Show log messages during execution
|
|
47
55
|
```
|
|
48
56
|
|
|
49
57
|
## Development
|
|
50
58
|
|
|
51
|
-
|
|
59
|
+
#### Test locally
|
|
52
60
|
|
|
53
61
|
```bash
|
|
54
62
|
# prerequisites
|
|
@@ -3,5 +3,5 @@ export type GenerateParams = {
|
|
|
3
3
|
excludeTags: string;
|
|
4
4
|
prettier: boolean;
|
|
5
5
|
verbose: boolean;
|
|
6
|
-
} & Pick<GenerateOptions, "input" | "output" | "includeNamespaces" | "splitByTags" | "defaultTag" | "removeOperationPrefixEndingWith" | "importPath" | "extractEnums">;
|
|
6
|
+
} & Pick<GenerateOptions, "input" | "output" | "includeNamespaces" | "splitByTags" | "defaultTag" | "removeOperationPrefixEndingWith" | "importPath" | "extractEnums" | "standalone" | "baseUrl">;
|
|
7
7
|
export declare function generate({ input, excludeTags, prettier, verbose, ...params }: GenerateParams): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Import } from "../types/generate";
|
|
2
|
-
export declare const
|
|
1
|
+
import { GenerateFile, Import } from "../types/generate";
|
|
2
|
+
export declare const ACL_APP_ABILITY_FILE: GenerateFile;
|
|
3
3
|
export declare const ACL_ALL_ABILITIES = "AllAbilities";
|
|
4
4
|
export declare const CASL_ABILITY_BINDING: {
|
|
5
5
|
abilityTuple: string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GenerateFile } from "../types/generate";
|
|
2
|
+
export declare const APP_REST_CLIENT_NAME = "AppRestClient";
|
|
3
|
+
export declare const QUERY_OPTIONS_TYPES: {
|
|
4
|
+
query: string;
|
|
5
|
+
mutation: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const TEMPLATE_DATA_FILE_PATH = "src/data";
|
|
8
|
+
export declare const TEMPLATE_DATA_TS_PATH = "@/data";
|
|
9
|
+
export declare const TEMPLATE_IMPORT_PATH_APP_REST_CLIENT = "@/util/rest/clients/app-rest-client";
|
|
10
|
+
export declare const TEMPLATE_IMPORT_PATH_QUERY_TYPES = "@/types/react-query";
|
|
11
|
+
export declare enum StandaloneAssetEnum {
|
|
12
|
+
ReactQueryTypes = "reactQueryTypes",
|
|
13
|
+
RestClient = "restClient",
|
|
14
|
+
RestInterceptor = "restInterceptor"
|
|
15
|
+
}
|
|
16
|
+
export declare const STANDALONE_ASSETS: Record<StandaloneAssetEnum, GenerateFile>;
|
|
17
|
+
export declare const STANDALONE_APP_REST_CLIENT_FILE: GenerateFile;
|
|
@@ -52,6 +52,7 @@ export declare class SchemaResolver {
|
|
|
52
52
|
resolveObject<T>(obj: OpenAPIV3.ReferenceObject | T): T;
|
|
53
53
|
isSchemaCircular(ref: string): boolean;
|
|
54
54
|
getCircularSchemaChain(ref: string, currentRef?: string, chain?: never[]): string[];
|
|
55
|
+
getBaseUrl(): string;
|
|
55
56
|
private initialize;
|
|
56
57
|
}
|
|
57
58
|
export {};
|
|
@@ -7,7 +7,7 @@ export interface GenerateParams {
|
|
|
7
7
|
export interface TsTypeBase {
|
|
8
8
|
type: string;
|
|
9
9
|
namespace?: string;
|
|
10
|
-
|
|
10
|
+
importPath?: string;
|
|
11
11
|
}
|
|
12
12
|
export type TsType = TsTypeBase & TsMetaType;
|
|
13
13
|
export type TsPropertyBase = {
|
|
@@ -37,7 +37,7 @@ export type TsMetaType = TsPrimitiveMetaType | TsObjectMetaType | TsArrayMetaTyp
|
|
|
37
37
|
export type ModelMetadata = TsType;
|
|
38
38
|
export type QueryMetadata = {
|
|
39
39
|
name: string;
|
|
40
|
-
|
|
40
|
+
importPath: string;
|
|
41
41
|
namespace?: string;
|
|
42
42
|
isQuery: boolean;
|
|
43
43
|
isMutation: boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GenerateFileData } from "../types/generate";
|
|
2
2
|
export declare function readHbsTemplateSync(fileName: string): string;
|
|
3
|
+
export declare function readAssetSync(fileName: string): string;
|
|
3
4
|
export declare function getOutputFileName({ output, fileName }: {
|
|
4
5
|
output: string;
|
|
5
6
|
fileName: string;
|
|
6
7
|
}): string;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function writeGeneratesFileData(filesData: GenerateFileData[]): void;
|
|
8
|
+
export declare function writeGenerateFileData(filesData: GenerateFileData[]): void;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { GenerateType } from "../../types/generate";
|
|
1
|
+
import { GenerateFile, GenerateType } from "../../types/generate";
|
|
2
2
|
import { GenerateOptions } from "../../types/options";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function getFileNameWithExtension({ fileName, extension }: GenerateFile): string;
|
|
4
|
+
declare function getTagFileNameWithoutExtension({ type, tag, options, includeTagDir, }: {
|
|
4
5
|
type: GenerateType;
|
|
5
6
|
tag: string;
|
|
6
7
|
includeTagDir?: boolean;
|
|
7
8
|
options: GenerateOptions;
|
|
8
9
|
}): string;
|
|
10
|
+
export declare function getTagImportPath(...args: Parameters<typeof getTagFileNameWithoutExtension>): string;
|
|
11
|
+
export declare function getTagFileName(...args: Parameters<typeof getTagFileNameWithoutExtension>): string;
|
|
9
12
|
export declare const getNamespaceName: ({ type, tag, options, }: {
|
|
10
13
|
type: GenerateType;
|
|
11
14
|
tag: string;
|
|
12
15
|
options: GenerateOptions;
|
|
13
16
|
}) => string;
|
|
17
|
+
export {};
|