@povio/openapi-codegen-cli 0.10.0 → 0.10.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/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 TEMPLATE_IMPORT_PATH_APP_REST_CLIENT = "@/util/rest/clients/app-rest-client";
11
- export declare const TEMPLATE_IMPORT_PATH_QUERY_TYPES = "@/types/react-query";
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",
@@ -1,11 +1,17 @@
1
1
  import { OpenAPIV3 } from "openapi-types";
2
2
  import { SchemaResolver } from "../../SchemaResolver.class";
3
+ type SchemaInfo = {
4
+ schemaRef: string;
5
+ schemaInfo?: string;
6
+ } | {
7
+ schemaRef?: string;
8
+ schemaInfo: string;
9
+ };
3
10
  export declare function updateExtractedEnumZodSchemaData({ schema, nameSegments, includeSelf, ...params }: {
4
11
  resolver: SchemaResolver;
5
12
  schema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject | undefined;
6
- schemaRef?: string;
7
- schemaInfo?: string;
8
13
  tags: string[];
9
14
  nameSegments?: string[];
10
15
  includeSelf?: boolean;
11
- }): void;
16
+ } & SchemaInfo): void;
17
+ export {};
@@ -5,7 +5,7 @@ import { ValidationError, ValidationErrorType } from "../types/validation";
5
5
  export declare function getInvalidSchemaError(message: string): ValidationError;
6
6
  export declare function getInvalidOperationIdError(operationId: string): ValidationError;
7
7
  export declare function getMissingPathParameterError(params: EndpointParameter[], path: string): ValidationError;
8
- export declare function getNotAllowedInlineEnumError(message: string): ValidationError;
8
+ export declare function getNotAllowedInlineEnumError(enumProperty: string): ValidationError;
9
9
  export declare function getNotAllowedCircularSchemaError(message: string): ValidationError;
10
10
  export declare function getMissingAclConditionPropertyError(propertyName: string, operation: OperationObject, endpoint: Endpoint): ValidationError;
11
11
  export declare function getMissingStatusCodeError(statusCode: HttpStatusCode, operation: OperationObject, endpoint: Endpoint): ValidationError;