@scalar/oas-utils 0.2.3 → 0.2.4

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/entities/workspace/collection/collection.d.ts +51 -17
  3. package/dist/entities/workspace/collection/collection.d.ts.map +1 -1
  4. package/dist/entities/workspace/collection/collection.js +27 -0
  5. package/dist/entities/workspace/cookie/cookie.d.ts +2 -2
  6. package/dist/entities/workspace/environment/environment.d.ts +3 -3
  7. package/dist/entities/workspace/folder/folder.d.ts +4 -4
  8. package/dist/entities/workspace/security/index.d.ts +3 -0
  9. package/dist/entities/workspace/security/index.d.ts.map +1 -0
  10. package/dist/entities/workspace/security/index.js +2 -0
  11. package/dist/entities/workspace/security/security-requirement.d.ts +13 -0
  12. package/dist/entities/workspace/security/security-requirement.d.ts.map +1 -0
  13. package/dist/entities/workspace/security/security-requirement.js +15 -0
  14. package/dist/entities/workspace/security/security-schemes.d.ts +664 -0
  15. package/dist/entities/workspace/security/security-schemes.d.ts.map +1 -0
  16. package/dist/entities/workspace/security/security-schemes.js +146 -0
  17. package/dist/entities/workspace/server/server.d.ts +6 -6
  18. package/dist/entities/workspace/spec/request-examples.d.ts +18 -18
  19. package/dist/entities/workspace/spec/requests.d.ts +23 -11
  20. package/dist/entities/workspace/spec/requests.d.ts.map +1 -1
  21. package/dist/entities/workspace/spec/requests.js +9 -0
  22. package/dist/entities/workspace/workspace.d.ts +6 -6
  23. package/dist/helpers/index.d.ts +2 -1
  24. package/dist/helpers/index.d.ts.map +1 -1
  25. package/dist/helpers/index.js +2 -1
  26. package/dist/helpers/object.d.ts +10 -0
  27. package/dist/helpers/object.d.ts.map +1 -0
  28. package/dist/helpers/{objectMerge.js → object.js} +6 -1
  29. package/dist/helpers/string.d.ts +10 -0
  30. package/dist/helpers/string.d.ts.map +1 -0
  31. package/dist/helpers/string.js +14 -0
  32. package/dist/transforms/import-spec.d.ts +8 -3
  33. package/dist/transforms/import-spec.d.ts.map +1 -1
  34. package/dist/transforms/import-spec.js +13 -0
  35. package/package.json +4 -4
  36. package/dist/entities/workspace/security-schemes/index.d.ts +0 -2
  37. package/dist/entities/workspace/security-schemes/index.d.ts.map +0 -1
  38. package/dist/entities/workspace/security-schemes/index.js +0 -1
  39. package/dist/entities/workspace/security-schemes/security-schemes.d.ts +0 -19
  40. package/dist/entities/workspace/security-schemes/security-schemes.d.ts.map +0 -1
  41. package/dist/entities/workspace/security-schemes/security-schemes.js +0 -15
  42. package/dist/helpers/objectMerge.d.ts +0 -5
  43. package/dist/helpers/objectMerge.d.ts.map +0 -1
@@ -70,6 +70,7 @@ const importSpecToWorkspace = async (spec) => {
70
70
  tags: operation.tags || ['default'],
71
71
  description: operation.description,
72
72
  operationId: operation.operationId,
73
+ security: operation.security,
73
74
  summary: operation.summary,
74
75
  externalDocs: operation.externalDocs,
75
76
  requestBody: operation.requestBody,
@@ -110,14 +111,26 @@ const importSpecToWorkspace = async (spec) => {
110
111
  },
111
112
  ];
112
113
  const servers = unparsedServers.map((server) => createServer(server));
114
+ // Select initial security
115
+ const firstSecurityKey = Object.keys(parsedSpec.components?.securitySchemes ?? {})?.[0];
116
+ const firstScheme = parsedSpec.components?.securitySchemes?.[firstSecurityKey ?? ''];
117
+ // In the case of oauth2 we need to select the flow as well
118
+ const flowKey = firstScheme?.type === 'oauth2'
119
+ ? Object.keys(firstScheme.flows ?? {})[0]
120
+ : undefined;
121
+ const selectedSecuritySchemes = firstSecurityKey
122
+ ? [{ uid: firstSecurityKey, ...(flowKey ? { flowKey } : {}) }]
123
+ : [];
113
124
  const collection = createCollection({
114
125
  spec: {
115
126
  openapi: parsedSpec.openapi,
116
127
  info: schema?.info,
128
+ security: parsedSpec.security,
117
129
  externalDocs: schema?.externalDocs,
118
130
  serverUids: servers.map(({ uid }) => uid),
119
131
  tags,
120
132
  },
133
+ selectedSecuritySchemes,
121
134
  selectedServerUid: servers[0].uid,
122
135
  // We default to having all the requests in the root folder
123
136
  childUids: folders.map(({ uid }) => uid),
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.2.3",
19
+ "version": "0.2.4",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -59,9 +59,9 @@
59
59
  "import": "./dist/entities/workspace/server/index.js",
60
60
  "types": "./dist/entities/workspace/server/index.d.ts"
61
61
  },
62
- "./entities/workspace/security-schemes": {
63
- "import": "./dist/entities/workspace/security-schemes/index.js",
64
- "types": "./dist/entities/workspace/security-schemes/index.d.ts"
62
+ "./entities/workspace/security": {
63
+ "import": "./dist/entities/workspace/security/index.js",
64
+ "types": "./dist/entities/workspace/security/index.d.ts"
65
65
  },
66
66
  "./entities/workspace/folder": {
67
67
  "import": "./dist/entities/workspace/folder/index.js",
@@ -1,2 +0,0 @@
1
- export * from './security-schemes.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/entities/workspace/security-schemes/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -1 +0,0 @@
1
- export { createSecurityScheme } from './security-schemes.js';
@@ -1,19 +0,0 @@
1
- import { z } from 'zod';
2
- declare const securityScheme: z.ZodObject<{
3
- /** REQUIRED. The type of the security scheme. Valid values are "apiKey", "http", "mutualTLS", "oauth2",
4
- * "openIdConnect". */
5
- type: z.ZodDefault<z.ZodOptional<z.ZodEnum<["apiKey", "http", "mutualTLS", "oauth2"]>>>;
6
- }, "strip", z.ZodTypeAny, {
7
- type: "apiKey" | "http" | "mutualTLS" | "oauth2";
8
- }, {
9
- type?: "apiKey" | "http" | "mutualTLS" | "oauth2" | undefined;
10
- }>;
11
- /** Folders will correspond to the x- */
12
- export type SecurityScheme = z.infer<typeof securityScheme>;
13
- export type SecuritySchemePayload = z.input<typeof securityScheme>;
14
- /** Create Security Scheme with defaults */
15
- export declare const createSecurityScheme: (payload: SecuritySchemePayload) => {
16
- type: "apiKey" | "http" | "mutualTLS" | "oauth2";
17
- };
18
- export {};
19
- //# sourceMappingURL=security-schemes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security-schemes.d.ts","sourceRoot":"","sources":["../../../../src/entities/workspace/security-schemes/security-schemes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,QAAA,MAAM,cAAc;IAClB;0BACsB;;;;;;EAKtB,CAAA;AAEF,wCAAwC;AACxC,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AAC3D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AAElE,2CAA2C;AAC3C,eAAO,MAAM,oBAAoB,YAAa,qBAAqB;;CACrB,CAAA"}
@@ -1,15 +0,0 @@
1
- import { z } from 'zod';
2
- import { deepMerge } from '../../../helpers/deepMerge.js';
3
-
4
- const securityScheme = z.object({
5
- /** REQUIRED. The type of the security scheme. Valid values are "apiKey", "http", "mutualTLS", "oauth2",
6
- * "openIdConnect". */
7
- type: z
8
- .enum(['apiKey', 'http', 'mutualTLS', 'oauth2'])
9
- .optional()
10
- .default('apiKey'),
11
- });
12
- /** Create Security Scheme with defaults */
13
- const createSecurityScheme = (payload) => deepMerge(securityScheme.parse({}), payload);
14
-
15
- export { createSecurityScheme };
@@ -1,5 +0,0 @@
1
- /**
2
- * Overwrite a target object a new replacement object handling removed keys
3
- **/
4
- export declare function objectMerge<A extends object, B extends object>(target: A, replacement: B): B;
5
- //# sourceMappingURL=objectMerge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"objectMerge.d.ts","sourceRoot":"","sources":["../../src/helpers/objectMerge.ts"],"names":[],"mappings":"AACA;;IAEI;AACJ,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC5D,MAAM,EAAE,CAAC,EACT,WAAW,EAAE,CAAC,KAYf"}