Skip to content

Commit e420f2a

Browse files
authored
Merge pull request #38 from povio/feature/builder-configs
Builder configs generation
2 parents 1fa718b + 2bc0463 commit e420f2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1046
-228
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ yarn openapi-codegen generate --config my-config.ts
7070
#### Generate command (generates Zod schemas, API definitions and React queries)
7171

7272
```sh
73+
--config Path to TS config file (default: 'openapi-codegen.config.ts')
7374
--input Path/URL to OpenAPI JSON/YAML document
7475
--output Output directory path (default: 'output')
7576
--prettier Format the generated code using Prettier (default: true)
@@ -97,13 +98,16 @@ yarn openapi-codegen generate --config my-config.ts
9798
--acl Generate ACL related files (default: true)
9899
--checkAcl Add ACL check to queries (default: true)
99100
101+
--builderConfigs Generate configs for builders (default: false)
102+
100103
--standalone Generate any missing supporting classes/types, e.g., REST client class, React Query type extensions, etc. (default: false)
101104
--baseUrl (Requires `--standalone`) Base URL for the REST client; falls back to the OpenAPI spec if not provided
102105
```
103106
104107
#### Check command (checks if OpenAPI spec is compliant)
105108
106109
```sh
110+
--config Path to TS config file (default: 'openapi-codegen.config.ts')
107111
--input Path/URL to OpenAPI/Swagger document as JSON/YAML
108112
--verbose Show log messages during execution
109113

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"main": "./dist/index.js",
55
"bin": {
66
"openapi-codegen": "./dist/sh.js"

src/commands/generate.command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class GenerateOptions implements GenerateParams {
7171
@YargOption({ envAlias: "axiosRequestConfig", type: "boolean" })
7272
axiosRequestConfig?: boolean;
7373

74+
@YargOption({ envAlias: "builderConfigs", type: "boolean" })
75+
builderConfigs?: boolean;
76+
7477
@YargOption({ envAlias: "prettier", default: true, type: "boolean" })
7578
prettier?: boolean;
7679

src/commands/generate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type GenerateParams = {
3434
| "axiosRequestConfig"
3535
| "mutationEffects"
3636
| "parseRequestParams"
37+
| "builderConfigs"
3738
>
3839
>;
3940

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const BUILD_CONFIG_SUFFIX = "config";

src/generators/const/deps.const.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,20 @@ export const QUERY_OPTIONS_TYPES = {
1010

1111
// Template
1212
export const TEMPLATE_DATA_FILE_PATH = "src/data";
13-
export const TEMPLATE_DATA_TS_PATH = "@/data";
14-
15-
export const TEMPLATE_IMPORTS = {
16-
appRestClient: "@/util/rest/clients/app-rest-client",
17-
queryTypes: "@/types/react-query",
18-
errorHandling: "@/util/vendor/error-handling",
19-
abilityContext: "@/data/acl/ability.context",
20-
};
21-
2213
export const ERROR_HANDLERS = {
2314
ErrorHandler: "ErrorHandler",
2415
SharedErrorHandler: "SharedErrorHandler",
2516
};
26-
export const ERROR_HANDLING_IMPORT: Import = {
17+
export const ERROR_HANDLING_IMPORT: Omit<Import, "from"> = {
2718
bindings: [ERROR_HANDLERS.ErrorHandler, ERROR_HANDLERS.SharedErrorHandler],
28-
from: TEMPLATE_IMPORTS.errorHandling,
2919
};
3020
export const ABILITY_CONTEXT = "AbilityContext";
31-
export const ABILITY_CONTEXT_IMPORT: Import = {
21+
export const ABILITY_CONTEXT_IMPORT: Omit<Import, "from"> = {
3222
bindings: [ABILITY_CONTEXT],
33-
from: TEMPLATE_IMPORTS.abilityContext,
23+
};
24+
export const BUILDERS_UTILS = {
25+
dynamicInputs: "dynamicInputs",
26+
dynamicColumns: "dynamicColumns",
3427
};
3528

3629
// Standalone

src/generators/const/endpoints.const.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Import } from "src/generators/types/generate";
22

3+
export const JSON_APPLICATION_FORMAT = "application/json";
34
export const DEFAULT_HEADERS = {
4-
"Content-Type": "application/json",
5-
Accept: "application/json",
5+
"Content-Type": JSON_APPLICATION_FORMAT,
6+
Accept: JSON_APPLICATION_FORMAT,
67
};
78

89
export const BODY_PARAMETER_NAME = "data";

src/generators/const/openapi.const.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export const ALLOWED_PARAM_MEDIA_TYPES = [
99
];
1010
export const ALLOWED_PATH_IN = ["query", "header", "path"] as Array<OpenAPIV3.ParameterObject["in"]>;
1111
export const ALLOWED_METHODS = [
12-
"get",
13-
"put",
14-
"post",
15-
"delete",
16-
"options",
17-
"head",
18-
"patch",
19-
"trace",
12+
OpenAPIV3.HttpMethods.GET,
13+
OpenAPIV3.HttpMethods.PUT,
14+
OpenAPIV3.HttpMethods.POST,
15+
OpenAPIV3.HttpMethods.DELETE,
16+
OpenAPIV3.HttpMethods.OPTIONS,
17+
OpenAPIV3.HttpMethods.HEAD,
18+
OpenAPIV3.HttpMethods.PATCH,
19+
OpenAPIV3.HttpMethods.TRACE,
2020
] as Array<OpenAPIV3.HttpMethods>;
2121
export const PRIMITIVE_TYPE_LIST = ["string", "number", "integer", "boolean"];
2222
export const COMPOSITE_KEYWORDS = ["allOf", "anyOf", "oneOf"] as (keyof OpenAPIV3.SchemaObject)[];

src/generators/const/options.const.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { GenerateType } from "src/generators/types/generate";
22
import { GenerateOptions } from "src/generators/types/options";
3-
import { TEMPLATE_DATA_TS_PATH, TEMPLATE_IMPORTS } from "./deps.const";
43
import { ENUM_SUFFIX, SCHEMA_SUFFIX } from "./zod.const";
54

65
export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
@@ -13,7 +12,7 @@ export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
1312
excludePathRegex: "",
1413
excludeRedundantZodSchemas: true,
1514
tsNamespaces: true,
16-
tsPath: TEMPLATE_DATA_TS_PATH,
15+
tsPath: "@/data",
1716
importPath: "ts",
1817
configs: {
1918
[GenerateType.Models]: {
@@ -32,6 +31,10 @@ export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
3231
outputFileNameSuffix: "acl",
3332
namespaceSuffix: "Acl",
3433
},
34+
[GenerateType.Configs]: {
35+
outputFileNameSuffix: "configs",
36+
namespaceSuffix: "Configs",
37+
},
3538
},
3639
standalone: false,
3740
baseUrl: "",
@@ -42,18 +45,33 @@ export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
4245
extractEnums: true,
4346
replaceOptionalWithNullish: false,
4447
// Endpoints options
45-
restClientImportPath: TEMPLATE_IMPORTS.appRestClient,
46-
errorHandlingImportPath: TEMPLATE_IMPORTS.errorHandling,
48+
restClientImportPath: "@/util/rest/clients/app-rest-client",
49+
errorHandlingImportPath: "@/util/vendor/error-handling",
4750
removeOperationPrefixEndingWith: "Controller_",
4851
parseRequestParams: true,
4952
// Queries options
50-
queryTypesImportPath: TEMPLATE_IMPORTS.queryTypes,
53+
queryTypesImportPath: "@/types/react-query",
5154
axiosRequestConfig: false,
52-
infiniteQueries: false,
5355
mutationEffects: true,
56+
// Infinite queries options
57+
infiniteQueries: false,
58+
infiniteQueryParamNames: {
59+
page: "page",
60+
},
61+
infiniteQueryResponseParamNames: {
62+
page: "page",
63+
totalItems: "totalItems",
64+
limit: "limit",
65+
},
5466
// ACL options
5567
acl: true,
5668
checkAcl: true,
57-
abilityContextImportPath: TEMPLATE_IMPORTS.abilityContext,
69+
abilityContextImportPath: "@/data/acl/ability.context",
5870
abilityContextGenericAppAbilities: false,
71+
// Builder Configs options
72+
builderConfigs: false,
73+
filterParamName: "filter",
74+
dataResponseParamNames: ["data", "items"],
75+
dynamicInputsImportPath: "@povio/ui",
76+
dynamicColumnsImportPath: "@povio/ui",
5977
};

src/generators/const/queries.const.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,4 @@ export const QUERY_IMPORT: Import = {
1010
from: "@tanstack/react-query",
1111
};
1212

13-
export const INFINITE_QUERY_PARAMS = {
14-
pageParamName: "page",
15-
};
16-
export const INFINITE_QUERY_RESPONSE_PARAMS = {
17-
pageParamName: "page",
18-
totalItemsName: "totalItems",
19-
limitParamName: "limit",
20-
};
21-
2213
export const QUERIES_MODULE_NAME = "moduleName";

0 commit comments

Comments
 (0)