vite-plugin-openapi-codegen 3.3.0 → 4.0.0

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/dist/cli.mjs CHANGED
@@ -57,11 +57,11 @@ function renderAccessPoliciesSource(entries, generatedHeader) {
57
57
  const lines = [
58
58
  ...generatedHeader,
59
59
  "",
60
- "export type AccessPolicyKind = \"authenticated\" | \"internal\" | \"public\" | \"role\";",
60
+ "export type AccessPolicyKind = \"authenticated\" | \"internal\" | \"public\" | \"permission\";",
61
61
  "",
62
62
  "export interface AccessPolicy {",
63
63
  " kind: AccessPolicyKind;",
64
- " roles?: readonly string[];",
64
+ " permissions?: readonly string[];",
65
65
  "}",
66
66
  "",
67
67
  "export interface OperationAccessPolicy extends AccessPolicy {",
@@ -80,7 +80,7 @@ function renderAccessPoliciesSource(entries, generatedHeader) {
80
80
  lines.push(` method: ${JSON.stringify(entry.methodUpper)},`);
81
81
  lines.push(` operationId: ${JSON.stringify(entry.operationId)},`);
82
82
  lines.push(` path: ${JSON.stringify(entry.strippedPath)},`);
83
- if (entry.roles.length > 0) lines.push(` roles: [${entry.roles.map((role) => JSON.stringify(role)).join(", ")}],`);
83
+ if (entry.permissions.length > 0) lines.push(` permissions: [${entry.permissions.map((permission) => JSON.stringify(permission)).join(", ")}],`);
84
84
  lines.push(" },");
85
85
  }
86
86
  lines.push("} as const satisfies Record<string, OperationAccessPolicy>;", "", "export type AccessPolicyKey = keyof typeof accessPolicies;", "");
@@ -323,10 +323,10 @@ function readSecurityRequirement(entry, securitySchemes, topLevelSecurity) {
323
323
  const scheme = securitySchemes?.[schemeName];
324
324
  if (scheme?.type === "apiKey" && scheme.in === "header") return { kind: "internal" };
325
325
  if (scheme?.type === "http" || scheme?.type === "apiKey" && scheme.in === "cookie") {
326
- const roles = readSecurityScopes(entry, schemeName, scopes);
327
- return roles.length === 0 ? { kind: "authenticated" } : {
328
- kind: "role",
329
- roles
326
+ const permissions = readSecurityScopes(entry, schemeName, scopes);
327
+ return permissions.length === 0 ? { kind: "authenticated" } : {
328
+ kind: "permission",
329
+ permissions
330
330
  };
331
331
  }
332
332
  }
@@ -334,12 +334,12 @@ function readSecurityRequirement(entry, securitySchemes, topLevelSecurity) {
334
334
  }
335
335
  function readSecurityScopes(entry, schemeName, scopes) {
336
336
  if (!Array.isArray(scopes)) throw new Error(`Operation "${entry.operationId}" has non-array scopes for security scheme "${schemeName}"`);
337
- const roles = [];
337
+ const permissions = [];
338
338
  for (const scope of scopes) {
339
339
  if (typeof scope !== "string") throw new Error(`Operation "${entry.operationId}" has a non-string scope for security scheme "${schemeName}"`);
340
- roles.push(scope);
340
+ permissions.push(scope);
341
341
  }
342
- return roles;
342
+ return permissions;
343
343
  }
344
344
  function isRecord(value) {
345
345
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -732,7 +732,7 @@ function createAccessPolicyEntries(operations, securitySchemes, topLevelSecurity
732
732
  kind: accessPolicy.kind,
733
733
  methodUpper: entry.method.toUpperCase(),
734
734
  operationId: entry.operationId,
735
- roles: accessPolicy.roles ?? [],
735
+ permissions: accessPolicy.permissions ?? [],
736
736
  strippedPath: entry.strippedPath
737
737
  }];
738
738
  });
package/dist/index.mjs CHANGED
@@ -55,11 +55,11 @@ function renderAccessPoliciesSource(entries, generatedHeader) {
55
55
  const lines = [
56
56
  ...generatedHeader,
57
57
  "",
58
- "export type AccessPolicyKind = \"authenticated\" | \"internal\" | \"public\" | \"role\";",
58
+ "export type AccessPolicyKind = \"authenticated\" | \"internal\" | \"public\" | \"permission\";",
59
59
  "",
60
60
  "export interface AccessPolicy {",
61
61
  " kind: AccessPolicyKind;",
62
- " roles?: readonly string[];",
62
+ " permissions?: readonly string[];",
63
63
  "}",
64
64
  "",
65
65
  "export interface OperationAccessPolicy extends AccessPolicy {",
@@ -78,7 +78,7 @@ function renderAccessPoliciesSource(entries, generatedHeader) {
78
78
  lines.push(` method: ${JSON.stringify(entry.methodUpper)},`);
79
79
  lines.push(` operationId: ${JSON.stringify(entry.operationId)},`);
80
80
  lines.push(` path: ${JSON.stringify(entry.strippedPath)},`);
81
- if (entry.roles.length > 0) lines.push(` roles: [${entry.roles.map((role) => JSON.stringify(role)).join(", ")}],`);
81
+ if (entry.permissions.length > 0) lines.push(` permissions: [${entry.permissions.map((permission) => JSON.stringify(permission)).join(", ")}],`);
82
82
  lines.push(" },");
83
83
  }
84
84
  lines.push("} as const satisfies Record<string, OperationAccessPolicy>;", "", "export type AccessPolicyKey = keyof typeof accessPolicies;", "");
@@ -321,10 +321,10 @@ function readSecurityRequirement(entry, securitySchemes, topLevelSecurity) {
321
321
  const scheme = securitySchemes?.[schemeName];
322
322
  if (scheme?.type === "apiKey" && scheme.in === "header") return { kind: "internal" };
323
323
  if (scheme?.type === "http" || scheme?.type === "apiKey" && scheme.in === "cookie") {
324
- const roles = readSecurityScopes(entry, schemeName, scopes);
325
- return roles.length === 0 ? { kind: "authenticated" } : {
326
- kind: "role",
327
- roles
324
+ const permissions = readSecurityScopes(entry, schemeName, scopes);
325
+ return permissions.length === 0 ? { kind: "authenticated" } : {
326
+ kind: "permission",
327
+ permissions
328
328
  };
329
329
  }
330
330
  }
@@ -332,12 +332,12 @@ function readSecurityRequirement(entry, securitySchemes, topLevelSecurity) {
332
332
  }
333
333
  function readSecurityScopes(entry, schemeName, scopes) {
334
334
  if (!Array.isArray(scopes)) throw new Error(`Operation "${entry.operationId}" has non-array scopes for security scheme "${schemeName}"`);
335
- const roles = [];
335
+ const permissions = [];
336
336
  for (const scope of scopes) {
337
337
  if (typeof scope !== "string") throw new Error(`Operation "${entry.operationId}" has a non-string scope for security scheme "${schemeName}"`);
338
- roles.push(scope);
338
+ permissions.push(scope);
339
339
  }
340
- return roles;
340
+ return permissions;
341
341
  }
342
342
  function isRecord(value) {
343
343
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -730,7 +730,7 @@ function createAccessPolicyEntries(operations, securitySchemes, topLevelSecurity
730
730
  kind: accessPolicy.kind,
731
731
  methodUpper: entry.method.toUpperCase(),
732
732
  operationId: entry.operationId,
733
- roles: accessPolicy.roles ?? [],
733
+ permissions: accessPolicy.permissions ?? [],
734
734
  strippedPath: entry.strippedPath
735
735
  }];
736
736
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-openapi-codegen",
3
- "version": "3.3.0",
3
+ "version": "4.0.0",
4
4
  "description": "Vite plugin that generates typed API clients and route builders from OpenAPI specs",
5
5
  "keywords": [
6
6
  "api-client",