@povio/openapi-codegen-cli 0.10.0 → 0.10.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 +79 -1
- package/dist/commands/generate.d.ts +2 -1
- package/dist/generators/const/deps.const.d.ts +4 -2
- package/dist/index.js +41 -41
- package/dist/sh.js +59 -59
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenAPI code generation CLI
|
|
2
2
|
|
|
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.
|
|
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
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
|
|
|
@@ -53,6 +53,9 @@ yarn openapi-codegen generate --input http://localhost:3001/docs-json --standalo
|
|
|
53
53
|
|
|
54
54
|
--standalone Generate any missing supporting classes/types, e.g., REST client class, React Query type extensions, etc. (default: false)
|
|
55
55
|
--baseUrl (Requires `--standalone`) Base URL for the REST client; falls back to the OpenAPI spec if not provided
|
|
56
|
+
|
|
57
|
+
# Command args designed specifically for use within our organization
|
|
58
|
+
--monorepo Configure output structure and imports adjusted for monorepo architecture
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
#### Check command (checks if OpenAPI spec is compliant)
|
|
@@ -92,3 +95,78 @@ yarn build
|
|
|
92
95
|
yarn start --help
|
|
93
96
|
yarn start:dist generate --input ./test/petstore.yaml --verbose
|
|
94
97
|
```
|
|
98
|
+
|
|
99
|
+
## Common Issues
|
|
100
|
+
|
|
101
|
+
### Enums
|
|
102
|
+
|
|
103
|
+
If you're using Enums in your backend DTOs with `@Expose()` and `@IsEnum`, they may still not appear correctly in the OpenAPI schema unless you also provide both `enum` **and** `enumName` to `@ApiProperty`.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
enum Status {
|
|
107
|
+
ACTIVE = "active",
|
|
108
|
+
INACTIVE = "inactive",
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class ExampleDto {
|
|
112
|
+
@ApiProperty({ enum: Status, enumName: "Status" })
|
|
113
|
+
@Expose()
|
|
114
|
+
@IsEnum(Status)
|
|
115
|
+
status: Status;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
enum Status {
|
|
121
|
+
ACTIVE = "active",
|
|
122
|
+
INACTIVE = "inactive",
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export class ExampleDto {
|
|
126
|
+
@ApiProperty({ enum: Status, enumName: "Status", isArray: true })
|
|
127
|
+
@Expose()
|
|
128
|
+
@IsEnum(Status, { each: true })
|
|
129
|
+
@IsArray()
|
|
130
|
+
status: Status[];
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
### Nested objects
|
|
137
|
+
|
|
138
|
+
When using nested DTOs, ensure you explicitly specify the type using `@ApiProperty({ type: NestedDto })`:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
export class NestedDto {
|
|
142
|
+
@ApiProperty()
|
|
143
|
+
@Expose()
|
|
144
|
+
name: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export class ParentDto {
|
|
148
|
+
@ApiProperty({ type: NestedDto })
|
|
149
|
+
@Expose()
|
|
150
|
+
@ValidateNested()
|
|
151
|
+
@Type(() => NestedDto)
|
|
152
|
+
@IsObject()
|
|
153
|
+
nested: NestedDto;
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
export class NestedDto {
|
|
159
|
+
@ApiProperty()
|
|
160
|
+
@Expose()
|
|
161
|
+
name: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class ParentDto {
|
|
165
|
+
@ApiProperty({ type: NestedDto, isArray: true })
|
|
166
|
+
@Expose()
|
|
167
|
+
@ValidateNested({ each: true })
|
|
168
|
+
@Type(() => NestedDto)
|
|
169
|
+
@IsArray()
|
|
170
|
+
nestedList: NestedDto[];
|
|
171
|
+
}
|
|
172
|
+
```
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { GenerateOptions } from "src/generators/types/options";
|
|
2
2
|
export type GenerateParams = {
|
|
3
3
|
excludeTags: string;
|
|
4
|
+
monorepo: boolean;
|
|
4
5
|
prettier: boolean;
|
|
5
6
|
verbose: boolean;
|
|
6
7
|
} & Pick<GenerateOptions, "input" | "output" | "tsNamespaces" | "splitByTags" | "defaultTag" | "removeOperationPrefixEndingWith" | "importPath" | "extractEnums" | "standalone" | "baseUrl" | "replaceOptionalWithNullish" | "infiniteQueries" | "axiosRequestConfig" | "invalidateQueryOptions">;
|
|
7
|
-
export declare function generate({ input, excludeTags, prettier, verbose, ...params }: GenerateParams): Promise<void>;
|
|
8
|
+
export declare function generate({ input, excludeTags, monorepo, prettier, verbose, ...params }: GenerateParams): Promise<void>;
|
|
@@ -7,8 +7,10 @@ export declare const QUERY_OPTIONS_TYPES: {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const TEMPLATE_DATA_FILE_PATH = "src/data";
|
|
9
9
|
export declare const TEMPLATE_DATA_TS_PATH = "@/data";
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
10
|
+
export declare const TEMPLATE_IMPORTS: Record<string, {
|
|
11
|
+
template: string;
|
|
12
|
+
monorepoTemplate: string;
|
|
13
|
+
}>;
|
|
12
14
|
export declare enum StandaloneAssetEnum {
|
|
13
15
|
ReactQueryTypes = "reactQueryTypes",
|
|
14
16
|
RestClient = "restClient",
|