@povio/openapi-codegen-cli 0.16.0 → 1.0.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
@@ -2,6 +2,8 @@
2
2
 
3
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
+ **NOTE:** Version 1+ requires zod v4 and is not compatible with zod v3.
6
+
5
7
  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
8
 
7
9
  The tool partially leverages code from [openapi-zod-client](https://github.com/astahmer/openapi-zod-client) repository.
@@ -84,7 +86,6 @@ yarn openapi-codegen generate --config my-config.ts
84
86
  --importPath Module import style for generated files (default: 'ts'; options: 'ts' | 'relative' | 'absolute')
85
87
  --removeOperationPrefixEndingWith Remove operation name prefixes that end with the specified string (Default: 'Controller_')
86
88
  --extractEnums Extract enums into separate Zod schemas (default: true)
87
- --branded Apply branded types to ambiguous Zod schemas (default: true)
88
89
  --replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
89
90
 
90
91
  --axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
@@ -4,4 +4,4 @@ export type CheckParams = {
4
4
  excludeTags?: string;
5
5
  verbose?: boolean;
6
6
  } & Partial<Pick<GenerateOptions, "input" | "splitByTags" | "defaultTag">>;
7
- export declare function check({ verbose, ...params }: CheckParams): Promise<void>;
7
+ export declare function check({ verbose, config: configParam, excludeTags: excludeTagsParam, ...params }: CheckParams): Promise<void>;
@@ -4,5 +4,5 @@ export type GenerateParams = {
4
4
  excludeTags?: string;
5
5
  prettier?: boolean;
6
6
  verbose?: boolean;
7
- } & Partial<Pick<GenerateOptions, "input" | "output" | "tsNamespaces" | "splitByTags" | "defaultTag" | "removeOperationPrefixEndingWith" | "importPath" | "extractEnums" | "acl" | "checkAcl" | "standalone" | "baseUrl" | "branded" | "replaceOptionalWithNullish" | "infiniteQueries" | "axiosRequestConfig" | "mutationEffects" | "parseRequestParams">>;
8
- export declare function generate({ prettier, verbose, ...params }: GenerateParams): Promise<void>;
7
+ } & Partial<Pick<GenerateOptions, "input" | "output" | "tsNamespaces" | "splitByTags" | "defaultTag" | "removeOperationPrefixEndingWith" | "importPath" | "extractEnums" | "acl" | "checkAcl" | "standalone" | "baseUrl" | "replaceOptionalWithNullish" | "infiniteQueries" | "axiosRequestConfig" | "mutationEffects" | "parseRequestParams">>;
8
+ export declare function generate({ prettier, verbose, config: configParam, ...params }: GenerateParams): Promise<void>;
@@ -36,12 +36,11 @@ export declare const MUTATION_EFFECTS: {
36
36
  runFunctionName: string;
37
37
  };
38
38
  export declare const MUTATION_EFFECTS_FILE: GenerateFile;
39
- export declare const ZOD_UTILS: {
39
+ export declare const ZOD_EXTENDED: {
40
40
  namespace: string;
41
41
  exports: {
42
42
  parse: string;
43
43
  sortExp: string;
44
- brand: string;
45
44
  };
46
45
  };
47
- export declare const ZOD_UTILS_FILE: GenerateFile;
46
+ export declare const ZOD_EXTENDED_FILE: GenerateFile;
@@ -8,5 +8,11 @@ export declare const ERROR_RESPONSE_SCHEMA_SUFFIX = "ErrorResponse";
8
8
  export declare const VOID_SCHEMA = "z.void()";
9
9
  export declare const BLOB_SCHEMA = "z.instanceof(Blob)";
10
10
  export declare const ENUM_SCHEMA = "z.enum";
11
+ export declare const INT_SCHEMA = "z.int()";
12
+ export declare const NUMBER_SCHEMA = "z.number()";
11
13
  export declare const STRING_SCHEMA = "z.string()";
14
+ export declare const EMAIL_SCHEMA = "z.email()";
15
+ export declare const URL_SCHEMA = "z.url()";
16
+ export declare const UUID_SCHEMA = "z.uuid()";
17
+ export declare const DATETIME_SCHEMA = "z.iso.datetime({ offset: true })";
12
18
  export declare const ZOD_IMPORT: Import;
@@ -0,0 +1,7 @@
1
+ import { GenerateOptions } from "src/generators/types/options";
2
+ export declare function resolveConfig({ fileConfig, params: { excludeTags, ...options }, }: {
3
+ fileConfig?: Partial<GenerateOptions> | null;
4
+ params: Partial<Omit<GenerateOptions, "excludeTags"> & {
5
+ excludeTags: string;
6
+ }>;
7
+ }): GenerateOptions;
@@ -0,0 +1,2 @@
1
+ import { SchemaResolver } from "src/generators/core/SchemaResolver.class";
2
+ export declare function generateZodExtended(resolver: SchemaResolver): string;
@@ -0,0 +1,27 @@
1
+ export type ObjectLiteral<T = any> = Record<string, T>;
2
+ export type List<A = any> = ReadonlyArray<A>;
3
+ export type Length<L extends List> = L["length"];
4
+ /**
5
+ Represents an array of strings split using a given character or character set.
6
+
7
+ Use-case: Defining the return type of a method like `String.prototype.split`.
8
+
9
+ @example
10
+ ```
11
+ declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
12
+
13
+ type Item = 'foo' | 'bar' | 'baz' | 'waldo';
14
+ const items = 'foo,bar,baz,waldo';
15
+ let array: Item[];
16
+
17
+ array = split(items, ',');
18
+ ```
19
+
20
+ @category String
21
+ @category Template literal
22
+ */
23
+ export type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : S extends Delimiter ? [] : [S];
24
+ export type HasNestedPath<Path extends string> = Length<Split<Path, ".">> extends 1 ? false : true;
25
+ export type WithRequired<T, K extends keyof T> = T & {
26
+ [P in K]-?: T[P];
27
+ };
@@ -0,0 +1,47 @@
1
+ import { OpenAPIV3 } from "openapi-types";
2
+ import { OperationAclInfo, ParameterObject } from "./openapi";
3
+ export interface EndpointParameter {
4
+ name: string;
5
+ description?: string;
6
+ type: "Query" | "Body" | "Header" | "Path";
7
+ zodSchema: string;
8
+ parameterObject?: ParameterObject;
9
+ parameterSortingEnumSchemaName?: string;
10
+ bodyObject?: OpenAPIV3.RequestBodyObject;
11
+ }
12
+ interface EndpointError {
13
+ status: number | "default";
14
+ description?: string;
15
+ zodSchema: string;
16
+ }
17
+ export interface AclConditionsPropertyType {
18
+ name: string;
19
+ type?: string;
20
+ zodSchemaName?: string;
21
+ required?: boolean;
22
+ info?: string;
23
+ }
24
+ export type EndpointAclInfo = OperationAclInfo & {
25
+ conditionsTypes?: AclConditionsPropertyType[];
26
+ };
27
+ export interface Endpoint {
28
+ method: OpenAPIV3.HttpMethods;
29
+ path: string;
30
+ operationName: string;
31
+ description?: string;
32
+ summary?: string;
33
+ tags?: string[];
34
+ requestFormat: string;
35
+ responseFormat?: string;
36
+ parameters: Array<EndpointParameter>;
37
+ status?: number;
38
+ response: string;
39
+ responseObject?: OpenAPIV3.ResponseObject;
40
+ responseDescription?: string;
41
+ errors: Array<EndpointError>;
42
+ responseStatusCodes: string[];
43
+ acl?: EndpointAclInfo[];
44
+ mediaUpload?: boolean;
45
+ mediaDownload?: boolean;
46
+ }
47
+ export {};
@@ -15,7 +15,6 @@ export interface GenerateZodSchemaData {
15
15
  isCiruclar: boolean;
16
16
  isEnum: boolean;
17
17
  schemaObj?: OpenAPIV3.SchemaObject;
18
- hasBrand: boolean;
19
18
  }
20
19
  export declare enum GenerateType {
21
20
  Models = "models",
@@ -0,0 +1,22 @@
1
+ import { OpenAPIV3 } from "openapi-types";
2
+ export type CompositeType = "oneOf" | "anyOf" | "allOf" | "enum" | "array" | "empty-object" | "object" | "record";
3
+ export type SingleType = Exclude<OpenAPIV3.SchemaObject["type"], any[] | undefined>;
4
+ export type PrimitiveType = "string" | "number" | "integer" | "boolean";
5
+ export interface OperationAclInfo {
6
+ action: string;
7
+ subject: string;
8
+ conditions?: Record<string, string>;
9
+ description?: string;
10
+ }
11
+ interface OperationObjectAdditions {
12
+ "x-acl"?: OperationAclInfo[];
13
+ "x-media-upload"?: any;
14
+ "x-media-download"?: any;
15
+ }
16
+ export type OperationObject = OpenAPIV3.OperationObject<OperationObjectAdditions>;
17
+ interface ParameterObjectAdditions {
18
+ "x-enumNames"?: string[];
19
+ }
20
+ export type ParameterObject = OpenAPIV3.ParameterObject & ParameterObjectAdditions;
21
+ export type SortingParameterObject = OpenAPIV3.ParameterObject & Required<Pick<ParameterObjectAdditions, "x-enumNames">>;
22
+ export {};
@@ -0,0 +1,48 @@
1
+ import { GenerateType } from "./generate";
2
+ interface ZodGenerateOptions {
3
+ schemaSuffix: string;
4
+ enumSuffix: string;
5
+ withImplicitRequiredProps?: boolean;
6
+ withDefaultValues?: boolean;
7
+ withDescription?: boolean;
8
+ allReadonly?: boolean;
9
+ extractEnums?: boolean;
10
+ replaceOptionalWithNullish?: boolean;
11
+ }
12
+ interface EndpointsGenerateOptions {
13
+ restClientImportPath: string;
14
+ errorHandlingImportPath: string;
15
+ withDeprecatedEndpoints?: boolean;
16
+ removeOperationPrefixEndingWith?: string;
17
+ parseRequestParams?: boolean;
18
+ }
19
+ interface QueriesGenerateOptions {
20
+ queryTypesImportPath: string;
21
+ axiosRequestConfig?: boolean;
22
+ infiniteQueries?: boolean;
23
+ mutationEffects?: boolean;
24
+ checkAcl?: boolean;
25
+ }
26
+ interface GenerateConfig {
27
+ outputFileNameSuffix: string;
28
+ namespaceSuffix: string;
29
+ }
30
+ interface BaseGenerateOptions {
31
+ input: string;
32
+ output: string;
33
+ splitByTags: boolean;
34
+ defaultTag: string;
35
+ excludeTags: string[];
36
+ excludePathRegex: string;
37
+ excludeRedundantZodSchemas: boolean;
38
+ tsNamespaces: boolean;
39
+ importPath: "ts" | "relative" | "absolute";
40
+ configs: Record<GenerateType, GenerateConfig>;
41
+ acl: boolean;
42
+ standalone: boolean;
43
+ baseUrl: string;
44
+ abilityContextImportPath: string;
45
+ abilityContextGenericAppAbilities: boolean;
46
+ }
47
+ export type GenerateOptions = BaseGenerateOptions & ZodGenerateOptions & EndpointsGenerateOptions & QueriesGenerateOptions;
48
+ export {};
@@ -0,0 +1,5 @@
1
+ export type ValidationErrorType = "invalid-schema" | "invalid-operation-id" | "missing-path-parameter" | "not-allowed-inline-enum" | "not-allowed-circular-schema" | "missing-acl-condition-property" | "missing-status-code" | "invalid-status-code" | "multiple-success-status-codes";
2
+ export interface ValidationError {
3
+ type: ValidationErrorType;
4
+ message: string;
5
+ }
@@ -19,6 +19,6 @@ export declare function getQueryTypesImportPath(options: GenerateOptions): strin
19
19
  export declare function getQueryModulesImportPath(options: GenerateOptions): string;
20
20
  export declare function getMutationEffectsImportPath(options: GenerateOptions): string;
21
21
  export declare function getAclCheckImportPath(options: GenerateOptions): string;
22
- export declare function getZodUtilsImportPath(options: GenerateOptions): string;
22
+ export declare function getZodExtendedImportPath(options: GenerateOptions): string;
23
23
  export declare function getAppAbilitiesImportPath(options: GenerateOptions): string;
24
24
  export {};
@@ -3,4 +3,4 @@ import { GenerateData, GenerateFileData } from "src/generators/types/generate";
3
3
  export declare function getAclFiles(appAclTags: string[], resolver: SchemaResolver): GenerateFileData[];
4
4
  export declare function getMutationEffectsFiles(data: GenerateData, resolver: SchemaResolver): GenerateFileData[];
5
5
  export declare function getStandaloneFiles(resolver: SchemaResolver): GenerateFileData[];
6
- export declare function getZodUtilsFiles(data: GenerateData, resolver: SchemaResolver): GenerateFileData[];
6
+ export declare function getZodExtendedFiles(data: GenerateData, resolver: SchemaResolver): GenerateFileData[];