@povio/openapi-codegen-cli 0.5.7 → 0.6.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/README.md +16 -10
- package/dist/commands/generate.d.ts +1 -1
- package/dist/generators/const/deps.const.d.ts +1 -0
- package/dist/generators/const/query.const.d.ts +9 -0
- package/dist/generators/core/SchemaResolver.class.d.ts +12 -4
- package/dist/generators/core/zod/getZodSchemasFromOpenAPIDoc.d.ts +6 -2
- package/dist/generators/core/zod/{updateEnumZodSchemaData.d.ts → updateExtractedEnumZodSchemaData.d.ts} +3 -3
- package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +1 -1
- package/dist/generators/utils/generate/generate.query.utils.d.ts +1 -0
- package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +2 -1
- package/dist/generators/utils/{queries.utils.d.ts → query.utils.d.ts} +1 -0
- package/dist/index.js +47 -47
- package/dist/sh.js +64 -64
- package/package.json +1 -1
- package/src/assets/react-query.types.ts +21 -3
- package/src/generators/templates/partials/endpoint-params.hbs +1 -1
- package/src/generators/templates/partials/query-js-docs.hbs +13 -1
- package/src/generators/templates/partials/query-keys.hbs +5 -0
- package/src/generators/templates/partials/query-use-infinite-query.hbs +15 -0
- package/src/generators/templates/queries.hbs +6 -0
package/README.md
CHANGED
|
@@ -31,28 +31,34 @@ yarn openapi-codegen generate --input http://localhost:3001/docs-json --standalo
|
|
|
31
31
|
```sh
|
|
32
32
|
--input Path/URL to OpenAPI/Swagger document as JSON/YAML
|
|
33
33
|
--output Output path (default: 'output')
|
|
34
|
-
--includeNamespaces Include namespaces inside generated files (default: true)
|
|
35
|
-
--splitByTags Split output into directories based on tags in OpenAPI operations (default: true)
|
|
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
34
|
--prettier Run the Prettier command on the output after code generation (default: true)
|
|
42
35
|
--verbose Show log messages during execution
|
|
43
|
-
|
|
44
|
-
--
|
|
36
|
+
|
|
37
|
+
--splitByTags Split output into directories based on tags in OpenAPI operations (default: true)
|
|
38
|
+
--defaultTag (Requires `splitByTags`) Default tag name for code shared across multiple tags (default: 'Common')
|
|
39
|
+
--excludeTags (Requires `splitByTags`) Comma-separated list of tags to exclude from the output
|
|
40
|
+
|
|
41
|
+
--tsNamespaces Include Typescript namespaces inside generated files (default: true)
|
|
42
|
+
--importPath Import path (default: 'ts', possible values: 'ts' | 'relative' | 'absolute')
|
|
43
|
+
--removeOperationPrefixEndingWith Remove prefixes that end with the specified value from operation names (default: 'Controller_')
|
|
44
|
+
--extractEnums Extract enums as separate Zod schemas (default: true)
|
|
45
45
|
--replaceOptionalWithNullish Replace all `.optional()` zod chains wtih `.nullish()`
|
|
46
|
+
|
|
47
|
+
--infiniteQueries Generates infinite queries for API definitions that support pagination (default: false)
|
|
48
|
+
|
|
49
|
+
--standalone Add any missing classes or types—e.g., REST client class, React Query type extensions, etc. (default: false)
|
|
50
|
+
--baseUrl (Requires `standalone`) Base URL for the REST client; falls back to the one defined in the OpenAPI spec
|
|
46
51
|
```
|
|
47
52
|
|
|
48
53
|
#### Check command (checks if OpenAPI spec is compliant)
|
|
49
54
|
|
|
50
55
|
```sh
|
|
51
56
|
--input Path/URL to OpenAPI/Swagger document as JSON/YAML
|
|
57
|
+
--verbose Show log messages during execution
|
|
58
|
+
|
|
52
59
|
--splitByTags Split output into directories based on tags in OpenAPI operations (default: true)
|
|
53
60
|
--defaultTag Default tag name for code shared across multiple tags (default: 'Common')
|
|
54
61
|
--excludeTags Comma-separated list of tags to exclude from the output
|
|
55
|
-
--verbose Show log messages during execution
|
|
56
62
|
```
|
|
57
63
|
|
|
58
64
|
## Development
|
|
@@ -3,5 +3,5 @@ export type GenerateParams = {
|
|
|
3
3
|
excludeTags: string;
|
|
4
4
|
prettier: boolean;
|
|
5
5
|
verbose: boolean;
|
|
6
|
-
} & Pick<GenerateOptions, "input" | "output" | "
|
|
6
|
+
} & Pick<GenerateOptions, "input" | "output" | "tsNamespaces" | "splitByTags" | "defaultTag" | "removeOperationPrefixEndingWith" | "importPath" | "extractEnums" | "standalone" | "baseUrl" | "replaceOptionalWithNullish" | "infiniteQueries">;
|
|
7
7
|
export declare function generate({ input, excludeTags, prettier, verbose, ...params }: GenerateParams): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import { GenerateFile } from "../types/generate";
|
|
|
2
2
|
export declare const APP_REST_CLIENT_NAME = "AppRestClient";
|
|
3
3
|
export declare const QUERY_OPTIONS_TYPES: {
|
|
4
4
|
query: string;
|
|
5
|
+
infiniteQuery: string;
|
|
5
6
|
mutation: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const TEMPLATE_DATA_FILE_PATH = "src/data";
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { Import } from "../types/generate";
|
|
2
2
|
export declare const QUERY_HOOKS: {
|
|
3
3
|
query: string;
|
|
4
|
+
infiniteQuery: string;
|
|
4
5
|
mutation: string;
|
|
5
6
|
queryClient: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const QUERY_IMPORT: Import;
|
|
9
|
+
export declare const INFINITE_QUERY_PARAMS: {
|
|
10
|
+
pageParamName: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const INFINITE_QUERY_RESPONSE_PARAMS: {
|
|
13
|
+
pageParamName: string;
|
|
14
|
+
totalItemsName: string;
|
|
15
|
+
limitParamName: string;
|
|
16
|
+
};
|
|
@@ -11,6 +11,11 @@ interface SchemaData {
|
|
|
11
11
|
tags: string[];
|
|
12
12
|
}
|
|
13
13
|
export interface EnumZodSchemaData {
|
|
14
|
+
code: string;
|
|
15
|
+
zodSchemaName: string;
|
|
16
|
+
tag?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ExtractedEnumZodSchemaData {
|
|
14
19
|
code: string;
|
|
15
20
|
zodSchemaName?: string;
|
|
16
21
|
tag?: string;
|
|
@@ -27,10 +32,11 @@ export declare class SchemaResolver {
|
|
|
27
32
|
private readonly schemaData;
|
|
28
33
|
private readonly zodSchemaData;
|
|
29
34
|
private readonly compositeZodSchemaData;
|
|
30
|
-
readonly enumZodSchemaData: EnumZodSchemaData[];
|
|
31
35
|
readonly dependencyGraph: DependencyGraph;
|
|
36
|
+
readonly enumZodSchemas: EnumZodSchemaData[];
|
|
32
37
|
readonly operationsByTag: Record<string, OperationObject[]>;
|
|
33
38
|
readonly operationNames: string[];
|
|
39
|
+
extractedEnumZodSchemaData: ExtractedEnumZodSchemaData[];
|
|
34
40
|
readonly validationErrors: ValidationError[];
|
|
35
41
|
private get docSchemas();
|
|
36
42
|
private get schemaRefs();
|
|
@@ -47,15 +53,17 @@ export declare class SchemaResolver {
|
|
|
47
53
|
getCompositeZodSchemaByZodSchemaName(zodSchemaName: string): ZodSchema | undefined;
|
|
48
54
|
getSchemaByCompositeZodSchemaName(compositeZodSchemaName: string): OpenAPIV3.SchemaObject | undefined;
|
|
49
55
|
getEnumZodSchemaDataByCode(code: string): EnumZodSchemaData | undefined;
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
getExtractedEnumZodSchemaDataByCode(code: string): ExtractedEnumZodSchemaData | undefined;
|
|
57
|
+
getExtractedEnumZodSchemaDataByName(enumZodSchemaName: string): ExtractedEnumZodSchemaData | undefined;
|
|
58
|
+
getExtractedEnumZodSchemaNamesReferencedBySchemaRef(schemaRef: string): string[];
|
|
52
59
|
getZodSchemas(): {};
|
|
53
|
-
|
|
60
|
+
getExtractedEnumZodSchemas(): {};
|
|
54
61
|
resolveObject<T>(obj: OpenAPIV3.ReferenceObject | T): T;
|
|
55
62
|
isSchemaCircular(ref: string): boolean;
|
|
56
63
|
getCircularSchemaChain(ref: string, currentRef?: string, chain?: never[]): string[];
|
|
57
64
|
getBaseUrl(): string;
|
|
58
65
|
getZodSchemaObj(zodSchemaName: string): OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject | undefined;
|
|
59
66
|
private initialize;
|
|
67
|
+
private handleDuplicateEnumZodSchemas;
|
|
60
68
|
}
|
|
61
69
|
export {};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import { SchemaResolver } from "../SchemaResolver.class";
|
|
2
|
-
export declare function getZodSchemasFromOpenAPIDoc(resolver: SchemaResolver):
|
|
1
|
+
import { EnumZodSchemaData, SchemaResolver } from "../SchemaResolver.class";
|
|
2
|
+
export declare function getZodSchemasFromOpenAPIDoc(resolver: SchemaResolver): {
|
|
3
|
+
zodSchemas: Record<string, string>;
|
|
4
|
+
enumZodSchemas: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export declare function getEnumZodSchemasFromOpenAPIDoc(resolver: SchemaResolver): EnumZodSchemaData[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAPIV3 } from "openapi-types";
|
|
2
2
|
import { SchemaResolver } from "../SchemaResolver.class";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function updateExtractedEnumZodSchemaData({ schema, nameSegments, includeSelf, ...params }: {
|
|
4
4
|
resolver: SchemaResolver;
|
|
5
5
|
schema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject | undefined;
|
|
6
6
|
schemaRef?: string;
|
|
@@ -9,5 +9,5 @@ export declare function updateEnumZodSchemaData({ schema, nameSegments, includeS
|
|
|
9
9
|
nameSegments?: string[];
|
|
10
10
|
includeSelf?: boolean;
|
|
11
11
|
}): void;
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
12
|
+
export declare function resolveExtractedEnumZodSchemaNames(resolver: SchemaResolver): void;
|
|
13
|
+
export declare function resolveExtractedEnumZodSchemaTags(resolver: SchemaResolver): void;
|
|
@@ -6,7 +6,7 @@ export declare const getEndpointName: (endpoint: Endpoint) => string;
|
|
|
6
6
|
export declare function getImportedEndpointName(endpoint: Endpoint, options: GenerateOptions): string;
|
|
7
7
|
export declare const getEndpointPath: (endpoint: Endpoint) => string;
|
|
8
8
|
export declare function getEndpointTag(endpoint: Endpoint, options: GenerateOptions): string;
|
|
9
|
-
export declare function mapEndpointParamsToFunctionParams(resolver: SchemaResolver, endpoint: Endpoint): {
|
|
9
|
+
export declare function mapEndpointParamsToFunctionParams(resolver: SchemaResolver, endpoint: Endpoint, extra?: "removePageParam" | "replacePageParam"): {
|
|
10
10
|
name: string;
|
|
11
11
|
type: string;
|
|
12
12
|
paramType: "Body" | "Query" | "Header" | "Path";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { SchemaResolver } from "src/generators/core/SchemaResolver.class";
|
|
2
|
+
export declare function registerPartialsHbsHelpers(resolver: SchemaResolver): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Endpoint } from "../types/endpoint";
|
|
2
2
|
export declare const isQuery: (endpoint: Endpoint) => boolean;
|
|
3
3
|
export declare const isMutation: (endpoint: Endpoint) => boolean;
|
|
4
|
+
export declare const isInfiniteQuery: (endpoint: Endpoint, infiniteQueryParams: string[]) => boolean;
|