@thymian/plugin-openapi 0.1.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.
Files changed (118) hide show
  1. package/README.md +11 -0
  2. package/dist/cli/commands/openapi/info.d.ts +10 -0
  3. package/dist/cli/commands/openapi/info.d.ts.map +1 -0
  4. package/dist/cli/commands/openapi/info.js +35 -0
  5. package/dist/cli/commands/openapi/info.js.map +1 -0
  6. package/dist/cli/commands/openapi/load.d.ts +10 -0
  7. package/dist/cli/commands/openapi/load.d.ts.map +1 -0
  8. package/dist/cli/commands/openapi/load.js +32 -0
  9. package/dist/cli/commands/openapi/load.js.map +1 -0
  10. package/dist/cli/commands/openapi/validate.d.ts +10 -0
  11. package/dist/cli/commands/openapi/validate.d.ts.map +1 -0
  12. package/dist/cli/commands/openapi/validate.js +28 -0
  13. package/dist/cli/commands/openapi/validate.js.map +1 -0
  14. package/dist/cli/init-hook.d.ts +5 -0
  15. package/dist/cli/init-hook.d.ts.map +1 -0
  16. package/dist/cli/init-hook.js +55 -0
  17. package/dist/cli/init-hook.js.map +1 -0
  18. package/dist/cli/spec-search-hook.d.ts +4 -0
  19. package/dist/cli/spec-search-hook.d.ts.map +1 -0
  20. package/dist/cli/spec-search-hook.js +11 -0
  21. package/dist/cli/spec-search-hook.js.map +1 -0
  22. package/dist/error.d.ts +4 -0
  23. package/dist/error.d.ts.map +1 -0
  24. package/dist/error.js +4 -0
  25. package/dist/error.js.map +1 -0
  26. package/dist/http-filter-expression-to-operation-filter.d.ts +14 -0
  27. package/dist/http-filter-expression-to-operation-filter.d.ts.map +1 -0
  28. package/dist/http-filter-expression-to-operation-filter.js +221 -0
  29. package/dist/http-filter-expression-to-operation-filter.js.map +1 -0
  30. package/dist/index.d.ts +51 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +116 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/load-openapi.d.ts +27 -0
  35. package/dist/load-openapi.d.ts.map +1 -0
  36. package/dist/load-openapi.js +76 -0
  37. package/dist/load-openapi.js.map +1 -0
  38. package/dist/loc-mapper/json-loc-mapper.d.ts +15 -0
  39. package/dist/loc-mapper/json-loc-mapper.d.ts.map +1 -0
  40. package/dist/loc-mapper/json-loc-mapper.js +105 -0
  41. package/dist/loc-mapper/json-loc-mapper.js.map +1 -0
  42. package/dist/loc-mapper/loc-mapper-for-file.d.ts +4 -0
  43. package/dist/loc-mapper/loc-mapper-for-file.d.ts.map +1 -0
  44. package/dist/loc-mapper/loc-mapper-for-file.js +20 -0
  45. package/dist/loc-mapper/loc-mapper-for-file.js.map +1 -0
  46. package/dist/loc-mapper/loc-mapper.d.ts +9 -0
  47. package/dist/loc-mapper/loc-mapper.d.ts.map +1 -0
  48. package/dist/loc-mapper/loc-mapper.js +22 -0
  49. package/dist/loc-mapper/loc-mapper.js.map +1 -0
  50. package/dist/loc-mapper/noop-loc-mapper.d.ts +6 -0
  51. package/dist/loc-mapper/noop-loc-mapper.d.ts.map +1 -0
  52. package/dist/loc-mapper/noop-loc-mapper.js +10 -0
  53. package/dist/loc-mapper/noop-loc-mapper.js.map +1 -0
  54. package/dist/loc-mapper/yaml-loc-mapper.d.ts +13 -0
  55. package/dist/loc-mapper/yaml-loc-mapper.d.ts.map +1 -0
  56. package/dist/loc-mapper/yaml-loc-mapper.js +105 -0
  57. package/dist/loc-mapper/yaml-loc-mapper.js.map +1 -0
  58. package/dist/processors/extract-server-info.d.ts +10 -0
  59. package/dist/processors/extract-server-info.d.ts.map +1 -0
  60. package/dist/processors/extract-server-info.js +40 -0
  61. package/dist/processors/extract-server-info.js.map +1 -0
  62. package/dist/processors/headers-object.processor.d.ts +4 -0
  63. package/dist/processors/headers-object.processor.d.ts.map +1 -0
  64. package/dist/processors/headers-object.processor.js +20 -0
  65. package/dist/processors/headers-object.processor.js.map +1 -0
  66. package/dist/processors/json-schema.processor.d.ts +19 -0
  67. package/dist/processors/json-schema.processor.d.ts.map +1 -0
  68. package/dist/processors/json-schema.processor.js +40 -0
  69. package/dist/processors/json-schema.processor.js.map +1 -0
  70. package/dist/processors/link-object.processor.d.ts +5 -0
  71. package/dist/processors/link-object.processor.d.ts.map +1 -0
  72. package/dist/processors/link-object.processor.js +58 -0
  73. package/dist/processors/link-object.processor.js.map +1 -0
  74. package/dist/processors/media-type-object.processor.d.ts +9 -0
  75. package/dist/processors/media-type-object.processor.d.ts.map +1 -0
  76. package/dist/processors/media-type-object.processor.js +43 -0
  77. package/dist/processors/media-type-object.processor.js.map +1 -0
  78. package/dist/processors/openapi.processor.d.ts +27 -0
  79. package/dist/processors/openapi.processor.d.ts.map +1 -0
  80. package/dist/processors/openapi.processor.js +166 -0
  81. package/dist/processors/openapi.processor.js.map +1 -0
  82. package/dist/processors/parameter-object.processor.d.ts +6 -0
  83. package/dist/processors/parameter-object.processor.d.ts.map +1 -0
  84. package/dist/processors/parameter-object.processor.js +90 -0
  85. package/dist/processors/parameter-object.processor.js.map +1 -0
  86. package/dist/processors/request-body-object.processor.d.ts +14 -0
  87. package/dist/processors/request-body-object.processor.d.ts.map +1 -0
  88. package/dist/processors/request-body-object.processor.js +61 -0
  89. package/dist/processors/request-body-object.processor.js.map +1 -0
  90. package/dist/processors/response-object.processor.d.ts +12 -0
  91. package/dist/processors/response-object.processor.d.ts.map +1 -0
  92. package/dist/processors/response-object.processor.js +44 -0
  93. package/dist/processors/response-object.processor.js.map +1 -0
  94. package/dist/processors/responses-object.processor.d.ts +5 -0
  95. package/dist/processors/responses-object.processor.d.ts.map +1 -0
  96. package/dist/processors/responses-object.processor.js +27 -0
  97. package/dist/processors/responses-object.processor.js.map +1 -0
  98. package/dist/processors/runtime-expression.processor.d.ts +4 -0
  99. package/dist/processors/runtime-expression.processor.d.ts.map +1 -0
  100. package/dist/processors/runtime-expression.processor.js +24 -0
  101. package/dist/processors/runtime-expression.processor.js.map +1 -0
  102. package/dist/processors/security-scheme-object.processor.d.ts +4 -0
  103. package/dist/processors/security-scheme-object.processor.d.ts.map +1 -0
  104. package/dist/processors/security-scheme-object.processor.js +50 -0
  105. package/dist/processors/security-scheme-object.processor.js.map +1 -0
  106. package/dist/processors/utils.d.ts +9 -0
  107. package/dist/processors/utils.d.ts.map +1 -0
  108. package/dist/processors/utils.js +21 -0
  109. package/dist/processors/utils.js.map +1 -0
  110. package/dist/runtime-expression.d.ts +8 -0
  111. package/dist/runtime-expression.d.ts.map +1 -0
  112. package/dist/runtime-expression.js +2 -0
  113. package/dist/runtime-expression.js.map +1 -0
  114. package/dist/search-for-openapi-files.d.ts +8 -0
  115. package/dist/search-for-openapi-files.d.ts.map +1 -0
  116. package/dist/search-for-openapi-files.js +44 -0
  117. package/dist/search-for-openapi-files.js.map +1 -0
  118. package/package.json +43 -0
@@ -0,0 +1,61 @@
1
+ import {} from '@thymian/core';
2
+ import { processMediaTypeObject } from './media-type-object.processor.js';
3
+ export function processRequestBodyObjet(requestBodyObject, parameters, locMapper, context) {
4
+ if (!requestBodyObject) {
5
+ return [
6
+ {
7
+ type: 'http-request',
8
+ host: context.host,
9
+ port: context.port,
10
+ protocol: context.protocol,
11
+ path: context.path,
12
+ method: context.method,
13
+ mediaType: '',
14
+ extensions: {
15
+ openapi: {
16
+ operationId: context.operationId,
17
+ },
18
+ },
19
+ ...parameters,
20
+ },
21
+ ];
22
+ }
23
+ return (Object.entries(requestBodyObject.content ?? {})
24
+ // form encoded content as well as multipart types are very complex to handle and will be skipped at first
25
+ .filter(([mediaType]) => !/^multipart\/.*/i.test(mediaType) &&
26
+ mediaType !== 'application/x-www-form-urlencoded')
27
+ .map(([mediaType, mediaTypeObject]) => {
28
+ const isMultipart = /^multipart\/.*/i.test(mediaType);
29
+ const addEncoding = mediaType === 'application/x-www-form-urlencoded' || isMultipart;
30
+ const { schema } = processMediaTypeObject(mediaTypeObject, addEncoding, isMultipart);
31
+ const sourceLocation = context.operationId
32
+ ? locMapper.locationForOperationId(context.operationId)
33
+ : undefined;
34
+ return {
35
+ type: 'http-request',
36
+ host: context.host,
37
+ port: context.port,
38
+ protocol: context.protocol,
39
+ path: context.path,
40
+ method: context.method,
41
+ description: requestBodyObject.description,
42
+ bodyRequired: requestBodyObject.required ?? false,
43
+ body: schema,
44
+ mediaType,
45
+ extensions: {
46
+ openapi: {
47
+ operationId: context.operationId,
48
+ },
49
+ },
50
+ sourceLocation,
51
+ queryParameters: parameters.queryParameters,
52
+ cookies: parameters.cookies,
53
+ pathParameters: parameters.pathParameters,
54
+ headers: {
55
+ ...parameters.headers,
56
+ // ...headers, TODO
57
+ },
58
+ };
59
+ }));
60
+ }
61
+ //# sourceMappingURL=request-body-object.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-body-object.processor.js","sourceRoot":"","sources":["../../src/processors/request-body-object.processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,MAAM,eAAe,CAAC;AAIxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAG1E,MAAM,UAAU,uBAAuB,CACrC,iBAA2D,EAC3D,UAAsB,EACtB,SAAoB,EACpB,OAQC;IAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO;YACL;gBACE,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,SAAS,EAAE,EAAE;gBACb,UAAU,EAAE;oBACV,OAAO,EAAE;wBACP,WAAW,EAAE,OAAO,CAAC,WAAW;qBACjC;iBACF;gBACD,GAAG,UAAU;aACd;SACF,CAAC;IACJ,CAAC;IAED,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,IAAI,EAAE,CAAC;QAC7C,0GAA0G;SACzG,MAAM,CACL,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CACd,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@thymian/core';
2
+ import type { OpenAPIV3_1 as OpenApiV31 } from 'openapi-types';
3
+ import type { Parameters } from './utils.js';
4
+ export type ResponsesWithLinks = {
5
+ responses: PartialBy<ThymianHttpResponse, 'label' | 'sourceName'>[];
6
+ links: {
7
+ name: string;
8
+ linkObj: OpenApiV31.LinkObject;
9
+ }[];
10
+ };
11
+ export declare function processResponseObject(responseObject: OpenApiV31.ResponseObject, statusCode: number, parameters: Parameters): ResponsesWithLinks;
12
+ //# sourceMappingURL=response-object.processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-object.processor.d.ts","sourceRoot":"","sources":["../../src/processors/response-object.processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAI/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,SAAS,CAAC,mBAAmB,EAAE,OAAO,GAAG,YAAY,CAAC,EAAE,CAAC;IACpE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAA;KAAE,EAAE,CAAC;CAC3D,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,UAAU,CAAC,cAAc,EACzC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,GACrB,kBAAkB,CAoDpB"}
@@ -0,0 +1,44 @@
1
+ import {} from '@thymian/core';
2
+ import { processHeadersObject } from './headers-object.processor.js';
3
+ import { processMediaTypeObject } from './media-type-object.processor.js';
4
+ export function processResponseObject(responseObject, statusCode, parameters) {
5
+ const headerParameters = processHeadersObject(responseObject.headers);
6
+ const links = Object.entries(responseObject.links ?? {}).map(([name, linkObj]) => ({ name, linkObj }));
7
+ const responses = [];
8
+ if (responseObject.content) {
9
+ responses.push(...Object.entries(responseObject.content)
10
+ .filter(([mediaType]) => !/^multipart\/.*/i.test(mediaType) &&
11
+ mediaType !== 'application/x-www-form-urlencoded')
12
+ .map(([mediaType, mediaTypeObject]) => {
13
+ const { schema } = processMediaTypeObject(mediaTypeObject);
14
+ return {
15
+ type: 'http-response',
16
+ description: responseObject.description,
17
+ headers: {
18
+ ...parameters.headers,
19
+ ...headerParameters,
20
+ },
21
+ mediaType,
22
+ statusCode,
23
+ schema,
24
+ };
25
+ }));
26
+ }
27
+ else {
28
+ responses.push({
29
+ type: 'http-response',
30
+ description: responseObject.description,
31
+ headers: {
32
+ ...parameters.headers,
33
+ ...headerParameters,
34
+ },
35
+ mediaType: '',
36
+ statusCode,
37
+ });
38
+ }
39
+ return {
40
+ responses,
41
+ links,
42
+ };
43
+ }
44
+ //# sourceMappingURL=response-object.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-object.processor.js","sourceRoot":"","sources":["../../src/processors/response-object.processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,MAAM,eAAe,CAAC;AAGzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAQ1E,MAAM,UAAU,qBAAqB,CACnC,cAAyC,EACzC,UAAkB,EAClB,UAAsB;IAEtB,MAAM,gBAAgB,GAAG,oBAAoB,CAC3C,cAAc,CAAC,OAAkD,CAClE,CAAC;IACF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAC1D,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACa,CAAC;IAExD,MAAM,SAAS,GACb,EAAE,CAAC;IAEL,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;QAC3B,SAAS,CAAC,IAAI,CACZ,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC;aACtC,MAAM,CACL,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CACd,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC;YAClC,SAAS,KAAK,mCAAmC,CACpD;aACA,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE;YACpC,MAAM,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC,eAAe,CAAC,CAAC;YAE3D,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,cAAc,CAAC,WAAW;gBACvC,OAAO,EAAE;oBACP,GAAG,UAAU,CAAC,OAAO;oBACrB,GAAG,gBAAgB;iBACpB;gBACD,SAAS;gBACT,UAAU;gBACV,MAAM;aAC0D,CAAC;QACrE,CAAC,CAAC,CACL,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,SAAS,CAAC,IAAI,CAAC;YACb,IAAI,EAAE,eAAe;YACrB,WAAW,EAAE,cAAc,CAAC,WAAW;YACvC,OAAO,EAAE;gBACP,GAAG,UAAU,CAAC,OAAO;gBACrB,GAAG,gBAAgB;aACpB;YACD,SAAS,EAAE,EAAE;YACb,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,SAAS;QACT,KAAK;KACN,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { OpenAPIV3_1 as OpenApiV31 } from 'openapi-types';
2
+ import { type ResponsesWithLinks } from './response-object.processor.js';
3
+ import type { Parameters } from './utils.js';
4
+ export declare function processResponsesObject(responsesObject: OpenApiV31.ResponsesObject | undefined, parameters: Parameters): ResponsesWithLinks[];
5
+ //# sourceMappingURL=responses-object.processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses-object.processor.d.ts","sourceRoot":"","sources":["../../src/processors/responses-object.processor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,sBAAsB,CACpC,eAAe,EAAE,UAAU,CAAC,eAAe,GAAG,SAAS,EACvD,UAAU,EAAE,UAAU,GACrB,kBAAkB,EAAE,CA4CtB"}
@@ -0,0 +1,27 @@
1
+ import { httpStatusCodeRanges, isHttpStatusCodeRange } from '@thymian/core';
2
+ import { processResponseObject, } from './response-object.processor.js';
3
+ export function processResponsesObject(responsesObject, parameters) {
4
+ const responses = {};
5
+ for (const [statusCode, responseObject] of Object.entries(responsesObject ?? {})) {
6
+ if (statusCode === 'default') {
7
+ /* ignored */
8
+ }
9
+ else if (isHttpStatusCodeRange(statusCode)) {
10
+ httpStatusCodeRanges[statusCode].forEach((code) => {
11
+ const strCode = String(code);
12
+ if (!Object.hasOwn(responses, strCode)) {
13
+ responses[strCode] = processResponseObject(responseObject, code, parameters);
14
+ }
15
+ });
16
+ }
17
+ else {
18
+ const statusCodeNumber = +statusCode;
19
+ if (statusCodeNumber < 100 || statusCodeNumber > 599) {
20
+ throw new Error(`Invalid status code. Status code must be a valid http status code or status code range (e.g. 2XX), but is ${statusCode}.`);
21
+ }
22
+ responses[statusCode] = processResponseObject(responseObject, statusCodeNumber, parameters);
23
+ }
24
+ }
25
+ return Object.values(responses).flat();
26
+ }
27
+ //# sourceMappingURL=responses-object.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses-object.processor.js","sourceRoot":"","sources":["../../src/processors/responses-object.processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG5E,OAAO,EACL,qBAAqB,GAEtB,MAAM,gCAAgC,CAAC;AAGxC,MAAM,UAAU,sBAAsB,CACpC,eAAuD,EACvD,UAAsB;IAEtB,MAAM,SAAS,GAMX,EAAE,CAAC;IAEP,KAAK,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CACvD,eAAe,IAAI,EAAE,CACtB,EAAE,CAAC;QACF,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,aAAa;QACf,CAAC;aAAM,IAAI,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,oBAAoB,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBAChD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;gBAE7B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;oBACvC,SAAS,CAAC,OAAO,CAAC,GAAG,qBAAqB,CACxC,cAA2C,EAC3C,IAAI,EACJ,UAAU,CACX,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,MAAM,gBAAgB,GAAG,CAAC,UAAU,CAAC;YAErC,IAAI,gBAAgB,GAAG,GAAG,IAAI,gBAAgB,GAAG,GAAG,EAAE,CAAC;gBACrD,MAAM,IAAI,KAAK,CACb,6GAA6G,UAAU,GAAG,CAC3H,CAAC;YACJ,CAAC;YAED,SAAS,CAAC,UAAU,CAAC,GAAG,qBAAqB,CAC3C,cAA2C,EAC3C,gBAAgB,EAChB,UAAU,CACX,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RunExpression } from '../runtime-expression.js';
2
+ export declare function processOpenApiRuntimeExpression(expression: RunExpression): string;
3
+ export declare function isOpenApiRuntimeExpression(expression: unknown): expression is RunExpression;
4
+ //# sourceMappingURL=runtime-expression.processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-expression.processor.d.ts","sourceRoot":"","sources":["../../src/processors/runtime-expression.processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,aAAa,GACxB,MAAM,CAsBR;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,OAAO,GAClB,UAAU,IAAI,aAAa,CAK7B"}
@@ -0,0 +1,24 @@
1
+ export function processOpenApiRuntimeExpression(expression) {
2
+ if (expression === '$url') {
3
+ return '$request/url';
4
+ }
5
+ if (expression === '$method') {
6
+ return '$request/method';
7
+ }
8
+ if (expression === '$statusCode') {
9
+ return '$response/statusCode';
10
+ }
11
+ let ptr = expression.replace(/\./, '/');
12
+ if (/^\$(request|response)\/body#?/.test(ptr)) {
13
+ ptr = ptr.replace(/body#?/, 'body');
14
+ }
15
+ else {
16
+ ptr = ptr.replace(/\./, '/');
17
+ }
18
+ return ptr;
19
+ }
20
+ export function isOpenApiRuntimeExpression(expression) {
21
+ return (typeof expression === 'string' &&
22
+ /^\$(url|method|statusCode|request|response)/gm.test(expression));
23
+ }
24
+ //# sourceMappingURL=runtime-expression.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-expression.processor.js","sourceRoot":"","sources":["../../src/processors/runtime-expression.processor.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,+BAA+B,CAC7C,UAAyB;IAEzB,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC1B,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;QACjC,OAAO,sBAAsB,CAAC;IAChC,CAAC;IAED,IAAI,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAExC,IAAI,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,UAAmB;IAEnB,OAAO,CACL,OAAO,UAAU,KAAK,QAAQ;QAC9B,+CAA+C,CAAC,IAAI,CAAC,UAAU,CAAC,CACjE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { PartialBy, SecurityScheme } from '@thymian/core';
2
+ import type { OpenAPIV3_1 as OpenApiV31 } from 'openapi-types';
3
+ export declare function processSecuritySchemes(schemes: Record<string, OpenApiV31.SecuritySchemeObject>): PartialBy<SecurityScheme, 'label' | 'sourceName'>[];
4
+ //# sourceMappingURL=security-scheme-object.processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security-scheme-object.processor.d.ts","sourceRoot":"","sources":["../../src/processors/security-scheme-object.processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,SAAS,EACT,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,oBAAoB,CAAC,GACvD,SAAS,CAAC,cAAc,EAAE,OAAO,GAAG,YAAY,CAAC,EAAE,CA8CrD"}
@@ -0,0 +1,50 @@
1
+ export function processSecuritySchemes(schemes) {
2
+ return Object.entries(schemes)
3
+ .filter(([, scheme]) => scheme.type === 'http' || scheme.type === 'apiKey')
4
+ .map(([name, schemeObj]) => {
5
+ if (schemeObj.type === 'apiKey') {
6
+ return {
7
+ type: 'security-scheme',
8
+ scheme: 'api-key',
9
+ in: schemeObj.in,
10
+ extensions: {
11
+ openapi: {
12
+ schemeName: name,
13
+ },
14
+ },
15
+ };
16
+ }
17
+ else if ('scheme' in schemeObj) {
18
+ if (schemeObj.scheme === 'basic') {
19
+ return {
20
+ type: 'security-scheme',
21
+ scheme: 'basic',
22
+ extensions: {
23
+ openapi: {
24
+ schemeName: name,
25
+ },
26
+ },
27
+ };
28
+ }
29
+ else if (schemeObj.scheme === 'bearer') {
30
+ return {
31
+ type: 'security-scheme',
32
+ scheme: 'bearer',
33
+ bearerFormat: schemeObj.bearerFormat,
34
+ extensions: {
35
+ openapi: {
36
+ schemeName: name,
37
+ },
38
+ },
39
+ };
40
+ }
41
+ else {
42
+ throw new Error(`Scheme ${schemeObj.scheme} not supported.`);
43
+ }
44
+ }
45
+ else {
46
+ throw new Error('Property "scheme" is required for security scheme type "http".');
47
+ }
48
+ });
49
+ }
50
+ //# sourceMappingURL=security-scheme-object.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security-scheme-object.processor.js","sourceRoot":"","sources":["../../src/processors/security-scheme-object.processor.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,sBAAsB,CACpC,OAAwD;IAExD,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAC3B,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;SAC1E,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE;QACzB,IAAI,SAAS,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO;gBACL,IAAI,EAAE,iBAAiB;gBACvB,MAAM,EAAE,SAAS;gBACjB,EAAE,EAAE,SAAS,CAAC,EAAE;gBAChB,UAAU,EAAE;oBACV,OAAO,EAAE;wBACP,UAAU,EAAE,IAAI;qBACjB;iBACF;aACgE,CAAC;QACtE,CAAC;aAAM,IAAI,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,SAAS,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;gBACjC,OAAO;oBACL,IAAI,EAAE,iBAAiB;oBACvB,MAAM,EAAE,OAAO;oBACf,UAAU,EAAE;wBACV,OAAO,EAAE;4BACP,UAAU,EAAE,IAAI;yBACjB;qBACF;iBAC+D,CAAC;YACrE,CAAC;iBAAM,IAAI,SAAS,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzC,OAAO;oBACL,IAAI,EAAE,iBAAiB;oBACvB,MAAM,EAAE,QAAQ;oBAChB,YAAY,EAAE,SAAS,CAAC,YAAY;oBACpC,UAAU,EAAE;wBACV,OAAO,EAAE;4BACP,UAAU,EAAE,IAAI;yBACjB;qBACF;iBACgE,CAAC;YACtE,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,UAAU,SAAS,CAAC,MAAM,iBAAiB,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Parameter } from '@thymian/core';
2
+ export type Parameters = {
3
+ headers: Record<string, Parameter>;
4
+ cookies: Record<string, Parameter>;
5
+ pathParameters: Record<string, Parameter>;
6
+ queryParameters: Record<string, Parameter>;
7
+ };
8
+ export declare function mergeParameters(from: Parameters, to: Parameters): Parameters;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/processors/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1C,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CAC5C,CAAC;AAEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,GAAG,UAAU,CAmB5E"}
@@ -0,0 +1,21 @@
1
+ export function mergeParameters(from, to) {
2
+ return {
3
+ cookies: {
4
+ ...from.cookies,
5
+ ...to.cookies,
6
+ },
7
+ pathParameters: {
8
+ ...from.pathParameters,
9
+ ...to.pathParameters,
10
+ },
11
+ queryParameters: {
12
+ ...from.queryParameters,
13
+ ...to.queryParameters,
14
+ },
15
+ headers: {
16
+ ...from.headers,
17
+ ...to.headers,
18
+ },
19
+ };
20
+ }
21
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/processors/utils.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,EAAc;IAC9D,OAAO;QACL,OAAO,EAAE;YACP,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,EAAE,CAAC,OAAO;SACd;QACD,cAAc,EAAE;YACd,GAAG,IAAI,CAAC,cAAc;YACtB,GAAG,EAAE,CAAC,cAAc;SACrB;QACD,eAAe,EAAE;YACf,GAAG,IAAI,CAAC,eAAe;YACvB,GAAG,EAAE,CAAC,eAAe;SACtB;QACD,OAAO,EAAE;YACP,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,EAAE,CAAC,OAAO;SACd;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type HeaderReference = `header.${string}`;
2
+ export type QueryReference = `query.${string}`;
3
+ export type PathReference = `path.${string}`;
4
+ export type JsonPointer = `${'/'}${string}`;
5
+ export type BodyReference = `body${`#${JsonPointer}` | ''}`;
6
+ export type Source = HeaderReference | QueryReference | PathReference | BodyReference;
7
+ export type RunExpression = `$url` | `$method` | `$statusCode` | `$request.${Source}` | `$response.${Source}`;
8
+ //# sourceMappingURL=runtime-expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-expression.d.ts","sourceRoot":"","sources":["../src/runtime-expression.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,UAAU,MAAM,EAAE,CAAC;AACjD,MAAM,MAAM,cAAc,GAAG,SAAS,MAAM,EAAE,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG,QAAQ,MAAM,EAAE,CAAC;AAC7C,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE,CAAC;AAC5C,MAAM,MAAM,aAAa,GAAG,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC;AAC5D,MAAM,MAAM,MAAM,GACd,eAAe,GACf,cAAc,GACd,aAAa,GACb,aAAa,CAAC;AAElB,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,SAAS,GACT,aAAa,GACb,YAAY,MAAM,EAAE,GACpB,aAAa,MAAM,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime-expression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-expression.js","sourceRoot":"","sources":["../src/runtime-expression.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Search for OpenAPI/Swagger specification files in the given directory.
3
+ *
4
+ * Scans all `.json`, `.yaml`, and `.yml` files and checks the first lines
5
+ * for a `swagger` or `openapi` version header.
6
+ */
7
+ export declare function searchForOpenApiFiles(cwd: string): Promise<string[]>;
8
+ //# sourceMappingURL=search-for-openapi-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-for-openapi-files.d.ts","sourceRoot":"","sources":["../src/search-for-openapi-files.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwC1E"}
@@ -0,0 +1,44 @@
1
+ import * as fs from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import * as readline from 'node:readline';
4
+ import { glob } from 'tinyglobby';
5
+ /**
6
+ * Search for OpenAPI/Swagger specification files in the given directory.
7
+ *
8
+ * Scans all `.json`, `.yaml`, and `.yml` files and checks the first lines
9
+ * for a `swagger` or `openapi` version header.
10
+ */
11
+ export async function searchForOpenApiFiles(cwd) {
12
+ const found = [];
13
+ const matches = await glob('**/*.{json,yaml,yml}', {
14
+ cwd,
15
+ });
16
+ for (const match of matches) {
17
+ const filePath = join(cwd, match);
18
+ let fileStream = null;
19
+ let rl = null;
20
+ try {
21
+ fileStream = fs.createReadStream(filePath, { encoding: 'utf8' });
22
+ rl = readline.createInterface({
23
+ input: fileStream,
24
+ });
25
+ for await (const line of rl) {
26
+ if (/^\s*"?swagger"?\s*:\s*("?2\.0\.0"?)/i.test(line) ||
27
+ /^\s*"?openapi"?\s*:\s*("?3\.(0|1)\.\d+"?)/i.test(line)) {
28
+ found.push(match);
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ finally {
34
+ if (rl) {
35
+ rl.close();
36
+ }
37
+ if (fileStream) {
38
+ fileStream.destroy();
39
+ }
40
+ }
41
+ }
42
+ return found;
43
+ }
44
+ //# sourceMappingURL=search-for-openapi-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-for-openapi-files.js","sourceRoot":"","sources":["../src/search-for-openapi-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,OAAO,EA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": {
6
+ "access": "public"
7
+ },
8
+ "files": [
9
+ "dist",
10
+ "!**/*.tsbuildinfo"
11
+ ],
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "typings": "./dist/index.d.ts",
15
+ "devDependencies": {
16
+ "@types/traverse": "^0.6.37",
17
+ "openapi-types": "^12.1.3"
18
+ },
19
+ "dependencies": {
20
+ "@scalar/openapi-parser": "^0.23.2",
21
+ "@scalar/openapi-upgrader": "^0.1.4",
22
+ "@thymian/common-cli": "0.1.0",
23
+ "@thymian/core": "0.1.0",
24
+ "jsonc-parser": "^3.2.0",
25
+ "tinyglobby": "^0.2.14",
26
+ "traverse": "^0.6.11",
27
+ "yaml": "^2.8.0"
28
+ },
29
+ "oclif": {
30
+ "commands": "./dist/cli/commands",
31
+ "bin": "thymian",
32
+ "topicSeparator": " ",
33
+ "hooks": {
34
+ "thymian-plugin.init": "./dist/cli/init-hook",
35
+ "thymian.spec-search": "./dist/cli/spec-search-hook"
36
+ },
37
+ "topics": {
38
+ "openapi": {
39
+ "description": "Work directly with OpenAPI files within Thymian."
40
+ }
41
+ }
42
+ }
43
+ }