@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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # OpenAPI code generation CLI
2
2
 
3
- **NOTE:** This CLI tool is specifically designed for custom usage within our organization. The generated code output is in alignment with our internal templates.
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 customized to fit the REST client wrapper used in our Next.js template. React queries are generated in alignment with our code standards, without the need for explicit types.
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
- ### Generate command (generates Zod schemas, API definitions and React queries)
29
+ #### Generate command (generates Zod schemas, API definitions and React queries)
24
30
 
25
31
  ```sh
26
- --input Path/url to OpenAPI/Swagger document as json/yaml
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 accross multiple tags (default: 'Common')
31
- --excludeTags Comma separated list of tags excluded from the output
32
- --extractEnums Enums are extracted as seperate Zod schemas (default: true)
33
- --removeOperationPrefixEndingWith Removes prefix that ends with value from operation names (default: 'Controller_')
34
- --importPath Import path (default: 'ts', possible: 'ts' | 'relative' | 'absolute')
35
- --prettier Run prettier command on output after code generation (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
+ --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
- ### Check command (checks if OpenAPI spec is compliant)
47
+ #### Check command (checks if OpenAPI spec is compliant)
40
48
 
41
49
  ```sh
42
- --input Path/url to OpenAPI/Swagger document as json/yaml
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 accross multiple tags (default: 'Common')
45
- --excludeTags Comma separated list of tags excluded from the output
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
- ### Test locally
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 ACL_APP_ABILITY_FILENAME = "acl/app.ability";
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 {};
@@ -0,0 +1,2 @@
1
+ import { SchemaResolver } from "../core/SchemaResolver.class";
2
+ export declare function generateAppRestClient(resolver: SchemaResolver): string;
@@ -4,6 +4,10 @@ export interface Import {
4
4
  bindings: string[];
5
5
  from: string;
6
6
  }
7
+ export interface GenerateFile {
8
+ fileName: string;
9
+ extension: string;
10
+ }
7
11
  export declare enum GenerateType {
8
12
  Models = "models",
9
13
  Endpoints = "endpoints",
@@ -7,7 +7,7 @@ export interface GenerateParams {
7
7
  export interface TsTypeBase {
8
8
  type: string;
9
9
  namespace?: string;
10
- filePath?: string;
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
- filePath: string;
40
+ importPath: string;
41
41
  namespace?: string;
42
42
  isQuery: boolean;
43
43
  isMutation: boolean;
@@ -0,0 +1,3 @@
1
+ import { GenerateOptions } from "src/generators/types/options";
2
+ export declare function getAppRestClientImportPath(options: GenerateOptions): string;
3
+ export declare function getQueryTypesImportPath(options: GenerateOptions): string;
@@ -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 writeTsFileSync({ fileName, content }: GenerateFileData): void;
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 getTagFileName({ type, tag, options, includeTagDir, }: {
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 {};