@povio/openapi-codegen-cli 2.0.8-rc.34 → 2.0.8-rc.35

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
@@ -92,7 +92,7 @@ yarn openapi-codegen generate --config my-config.ts
92
92
  --axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
93
93
  --infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
94
94
  --mutationEffects Add mutation effects options to mutation hooks (default: true)
95
- --workspaceContext Allow generated hooks to resolve path/ACL params from OpenApiWorkspaceContext (default: false)
95
+ --workspaceContext Comma-separated list of path/ACL params that generated hooks may resolve from OpenApiWorkspaceContext
96
96
  --inlineEndpoints Inline endpoint implementations into generated query files (default: false)
97
97
  --inlineEndpointsExcludeModules Comma-separated modules/tags to keep as separate API files while inlineEndpoints=true
98
98
  --modelsOnly Generate only model files (default: false)
@@ -196,18 +196,18 @@ export default config;
196
196
 
197
197
  ### OpenApiWorkspaceContext (Path + ACL defaults)
198
198
 
199
- Enable `workspaceContext: true` in codegen config (or pass `--workspaceContext`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params (for example `officeId`).
199
+ Set `workspaceContext` to a list of param names in codegen config (or pass `--workspaceContext officeId,projectId`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params.
200
200
 
201
201
  ```tsx
202
202
  import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli";
203
- // openapi-codegen.config.ts -> { workspaceContext: true }
203
+ // openapi-codegen.config.ts -> { workspaceContext: ["officeId", "projectId"] }
204
204
 
205
205
  <OpenApiWorkspaceContext.Provider values={{ officeId: "office_123" }}>
206
206
  <MyWorkspacePages />
207
207
  </OpenApiWorkspaceContext.Provider>;
208
208
  ```
209
209
 
210
- Generated query/mutation hooks can then omit matching path/ACL params and resolve them from `OpenApiWorkspaceContext`.
210
+ Generated query/mutation hooks can then omit only those matching path/ACL params and resolve them from `OpenApiWorkspaceContext`. Params not listed in `workspaceContext` remain explicit and required.
211
211
 
212
212
  ### Generation Modes
213
213
 
@@ -1,4 +1,4 @@
1
- import { t as GenerateOptions } from "./options-D9TC-n26.mjs";
1
+ import { t as GenerateOptions } from "./options-D3n-bZbj.mjs";
2
2
 
3
3
  //#region src/generators/types/config.d.ts
4
4
  type OpenAPICodegenConfig = Partial<GenerateOptions>;
@@ -1,16 +1,18 @@
1
- import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
1
+ import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-C2niF2V7.mjs";
2
2
  import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
5
5
  //#region src/generators/core/resolveConfig.ts
6
- function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, ...options } }) {
6
+ function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
7
7
  const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
8
8
  ...options,
9
9
  includeTags: includeTags?.split(","),
10
10
  excludeTags: excludeTags?.split(","),
11
- inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(",")
11
+ inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
12
+ workspaceContext: workspaceContext?.split(",")
12
13
  });
13
14
  resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
15
+ resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
14
16
  return resolvedConfig;
15
17
  }
16
18
 
@@ -645,7 +645,7 @@ const DEFAULT_GENERATE_OPTIONS = {
645
645
  queryTypesImportPath: PACKAGE_IMPORT_PATH,
646
646
  axiosRequestConfig: false,
647
647
  mutationEffects: true,
648
- workspaceContext: false,
648
+ workspaceContext: [],
649
649
  prefetchQueries: true,
650
650
  infiniteQueries: false,
651
651
  infiniteQueryParamNames: { page: "page" },
@@ -1248,6 +1248,7 @@ const hasEndpointConfig = (endpoint, resolver) => {
1248
1248
  };
1249
1249
  const getEndpointPath = (endpoint) => endpoint.path.replace(/:([a-zA-Z0-9_]+)/g, "${$1}");
1250
1250
  function mapEndpointParamsToFunctionParams(resolver, endpoint, options) {
1251
+ const optionalPathParams = options?.optionalPathParams ? new Set(options.optionalPathParams) : void 0;
1251
1252
  const params = endpoint.parameters.map((param) => {
1252
1253
  let type = "string";
1253
1254
  if (isNamedZodSchema(param.zodSchema)) type = getImportedZodSchemaInferedTypeName(resolver, param.zodSchema, void 0, options?.modelNamespaceTag);
@@ -1286,7 +1287,7 @@ function mapEndpointParamsToFunctionParams(resolver, endpoint, options) {
1286
1287
  }).filter((param) => (!options?.excludeBodyParam || param.name !== BODY_PARAMETER_NAME) && (!options?.excludePageParam || param.name !== resolver.options.infiniteQueryParamNames.page) && (!options?.includeOnlyRequiredParams || param.required)).map((param) => ({
1287
1288
  ...param,
1288
1289
  name: options?.replacePageParam && param.name === resolver.options.infiniteQueryParamNames.page ? "pageParam" : param.name,
1289
- required: options?.optionalPathParams && param.paramType === "Path" ? false : param.required && (param.paramType === "Path" || !options?.pathParamsRequiredOnly)
1290
+ required: param.paramType === "Path" && optionalPathParams?.has(param.name) ? false : param.required && (param.paramType === "Path" || !options?.pathParamsRequiredOnly)
1290
1291
  }));
1291
1292
  }
1292
1293
  function getEndpointConfig(endpoint) {
@@ -4114,13 +4115,16 @@ function getEndpointParamMapping(resolver, endpoint, options) {
4114
4115
  endpointCache = /* @__PURE__ */ new Map();
4115
4116
  resolverCache.set(endpoint, endpointCache);
4116
4117
  }
4117
- const key = JSON.stringify(Object.entries(options ?? {}).sort(([left], [right]) => left.localeCompare(right)).map(([optionName, optionValue]) => [optionName, Boolean(optionValue)]));
4118
+ const key = JSON.stringify(Object.entries(options ?? {}).sort(([left], [right]) => left.localeCompare(right)).map(([optionName, optionValue]) => [optionName, optionValue]));
4118
4119
  const cached = endpointCache.get(key);
4119
4120
  if (cached) return cached;
4120
4121
  const computed = mapEndpointParamsToFunctionParams(resolver, endpoint, options);
4121
4122
  endpointCache.set(key, computed);
4122
4123
  return computed;
4123
4124
  }
4125
+ function getWorkspaceContextAllowList(workspaceContext) {
4126
+ return new Set(workspaceContext);
4127
+ }
4124
4128
  function renderImport(importData) {
4125
4129
  const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
4126
4130
  const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
@@ -4157,11 +4161,12 @@ function renderEndpointParamDescription(endpointParam) {
4157
4161
  return strs.join(". ");
4158
4162
  }
4159
4163
  function getWorkspaceParamNames(resolver, endpoint) {
4164
+ const allowList = getWorkspaceContextAllowList(resolver.options.workspaceContext);
4160
4165
  const endpointParams = getEndpointParamMapping(resolver, endpoint, {});
4161
4166
  const endpointParamNames = new Set(endpointParams.map((param) => param.name));
4162
4167
  const workspaceParamNames = endpointParams.filter((param) => param.paramType === "Path").map((param) => param.name);
4163
4168
  const aclParamNames = (getAbilityConditionsTypes(endpoint) ?? []).map((condition) => invalidVariableNameCharactersToCamel(condition.name)).filter((name) => endpointParamNames.has(name));
4164
- return getUniqueArray([...workspaceParamNames, ...aclParamNames]);
4169
+ return getUniqueArray([...workspaceParamNames, ...aclParamNames]).filter((name) => allowList.has(name));
4165
4170
  }
4166
4171
  function getWorkspaceParamReplacements(resolver, endpoint) {
4167
4172
  return Object.fromEntries(getWorkspaceParamNames(resolver, endpoint).map((name) => [name, `${name}FromWorkspace`]));
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-D9TC-n26.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-D3n-bZbj.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
3
 
4
4
  //#region src/generators/types/metadata.d.ts
@@ -1,4 +1,4 @@
1
- import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
1
+ import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-C2niF2V7.mjs";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
3
 
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as GeneralErrorCodes, i as ErrorHandlerOptions, n as ErrorEntry, o as SharedErrorHandler, r as ErrorHandler, t as ApplicationException } from "./error-handling-CXeVTk1T.mjs";
2
- import "./options-D9TC-n26.mjs";
3
- import { t as OpenAPICodegenConfig } from "./config-KffSntOs.mjs";
2
+ import "./options-D3n-bZbj.mjs";
3
+ import { t as OpenAPICodegenConfig } from "./config-DqD9ExKp.mjs";
4
4
  import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
5
5
  import { z } from "zod";
6
6
  import "i18next";
@@ -39,7 +39,7 @@ interface QueriesGenerateOptions {
39
39
  queryTypesImportPath: string;
40
40
  axiosRequestConfig?: boolean;
41
41
  mutationEffects?: boolean;
42
- workspaceContext?: boolean;
42
+ workspaceContext?: string[];
43
43
  prefetchQueries?: boolean;
44
44
  }
45
45
  interface InfiniteQueriesGenerateOptions {
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-CTwFD7Th.mjs";
2
+ import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-C2niF2V7.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-QejaDLjW.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import yargs from "yargs";
6
6
  import { hideBin } from "yargs/helpers";
@@ -39,7 +39,7 @@ function logBanner(message) {
39
39
  * Fetch the version from package.json
40
40
  */
41
41
  function getVersion() {
42
- return "2.0.8-rc.34";
42
+ return "2.0.8-rc.35";
43
43
  }
44
44
 
45
45
  //#endregion
@@ -389,10 +389,7 @@ __decorate([YargOption({
389
389
  envAlias: "mutationEffects",
390
390
  type: "boolean"
391
391
  }), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationEffects", void 0);
392
- __decorate([YargOption({
393
- envAlias: "workspaceContext",
394
- type: "boolean"
395
- }), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "workspaceContext", void 0);
392
+ __decorate([YargOption({ envAlias: "workspaceContext" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "workspaceContext", void 0);
396
393
  __decorate([YargOption({
397
394
  envAlias: "parseRequestParams",
398
395
  type: "boolean"
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { r as GenerateFileFormatter } from "./options-D9TC-n26.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-KffSntOs.mjs";
1
+ import { r as GenerateFileFormatter } from "./options-D3n-bZbj.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-DqD9ExKp.mjs";
3
3
  import { Plugin } from "vite";
4
4
 
5
5
  //#region src/vite/openapi-codegen.plugin.d.ts
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
2
- import { t as runGenerate } from "./generate.runner-CTwFD7Th.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-C2niF2V7.mjs";
2
+ import { t as runGenerate } from "./generate.runner-QejaDLjW.mjs";
3
3
  import path from "path";
4
4
 
5
5
  //#region src/vite/openapi-codegen.plugin.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "2.0.8-rc.34",
3
+ "version": "2.0.8-rc.35",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",