@thymian/plugin-openapi 0.0.0-PLACEHOLDER

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 (114) hide show
  1. package/README.md +59 -0
  2. package/dist/cli/commands/openapi/info.d.ts +11 -0
  3. package/dist/cli/commands/openapi/info.d.ts.map +1 -0
  4. package/dist/cli/commands/openapi/info.js +36 -0
  5. package/dist/cli/commands/openapi/info.js.map +1 -0
  6. package/dist/cli/commands/openapi/load.d.ts +11 -0
  7. package/dist/cli/commands/openapi/load.d.ts.map +1 -0
  8. package/dist/cli/commands/openapi/load.js +33 -0
  9. package/dist/cli/commands/openapi/load.js.map +1 -0
  10. package/dist/cli/commands/openapi/validate.d.ts +11 -0
  11. package/dist/cli/commands/openapi/validate.d.ts.map +1 -0
  12. package/dist/cli/commands/openapi/validate.js +29 -0
  13. package/dist/cli/commands/openapi/validate.js.map +1 -0
  14. package/dist/cli/spec-search-hook.d.ts +4 -0
  15. package/dist/cli/spec-search-hook.d.ts.map +1 -0
  16. package/dist/cli/spec-search-hook.js +11 -0
  17. package/dist/cli/spec-search-hook.js.map +1 -0
  18. package/dist/error.d.ts +4 -0
  19. package/dist/error.d.ts.map +1 -0
  20. package/dist/error.js +4 -0
  21. package/dist/error.js.map +1 -0
  22. package/dist/http-filter-expression-to-operation-filter.d.ts +14 -0
  23. package/dist/http-filter-expression-to-operation-filter.d.ts.map +1 -0
  24. package/dist/http-filter-expression-to-operation-filter.js +221 -0
  25. package/dist/http-filter-expression-to-operation-filter.js.map +1 -0
  26. package/dist/index.d.ts +44 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +63 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/load-openapi.d.ts +31 -0
  31. package/dist/load-openapi.d.ts.map +1 -0
  32. package/dist/load-openapi.js +159 -0
  33. package/dist/load-openapi.js.map +1 -0
  34. package/dist/loc-mapper/json-loc-mapper.d.ts +15 -0
  35. package/dist/loc-mapper/json-loc-mapper.d.ts.map +1 -0
  36. package/dist/loc-mapper/json-loc-mapper.js +105 -0
  37. package/dist/loc-mapper/json-loc-mapper.js.map +1 -0
  38. package/dist/loc-mapper/loc-mapper-for-file.d.ts +4 -0
  39. package/dist/loc-mapper/loc-mapper-for-file.d.ts.map +1 -0
  40. package/dist/loc-mapper/loc-mapper-for-file.js +20 -0
  41. package/dist/loc-mapper/loc-mapper-for-file.js.map +1 -0
  42. package/dist/loc-mapper/loc-mapper.d.ts +9 -0
  43. package/dist/loc-mapper/loc-mapper.d.ts.map +1 -0
  44. package/dist/loc-mapper/loc-mapper.js +22 -0
  45. package/dist/loc-mapper/loc-mapper.js.map +1 -0
  46. package/dist/loc-mapper/noop-loc-mapper.d.ts +6 -0
  47. package/dist/loc-mapper/noop-loc-mapper.d.ts.map +1 -0
  48. package/dist/loc-mapper/noop-loc-mapper.js +10 -0
  49. package/dist/loc-mapper/noop-loc-mapper.js.map +1 -0
  50. package/dist/loc-mapper/yaml-loc-mapper.d.ts +13 -0
  51. package/dist/loc-mapper/yaml-loc-mapper.d.ts.map +1 -0
  52. package/dist/loc-mapper/yaml-loc-mapper.js +105 -0
  53. package/dist/loc-mapper/yaml-loc-mapper.js.map +1 -0
  54. package/dist/processors/extract-server-info.d.ts +10 -0
  55. package/dist/processors/extract-server-info.d.ts.map +1 -0
  56. package/dist/processors/extract-server-info.js +40 -0
  57. package/dist/processors/extract-server-info.js.map +1 -0
  58. package/dist/processors/headers-object.processor.d.ts +4 -0
  59. package/dist/processors/headers-object.processor.d.ts.map +1 -0
  60. package/dist/processors/headers-object.processor.js +20 -0
  61. package/dist/processors/headers-object.processor.js.map +1 -0
  62. package/dist/processors/json-schema.processor.d.ts +19 -0
  63. package/dist/processors/json-schema.processor.d.ts.map +1 -0
  64. package/dist/processors/json-schema.processor.js +40 -0
  65. package/dist/processors/json-schema.processor.js.map +1 -0
  66. package/dist/processors/link-object.processor.d.ts +5 -0
  67. package/dist/processors/link-object.processor.d.ts.map +1 -0
  68. package/dist/processors/link-object.processor.js +58 -0
  69. package/dist/processors/link-object.processor.js.map +1 -0
  70. package/dist/processors/media-type-object.processor.d.ts +9 -0
  71. package/dist/processors/media-type-object.processor.d.ts.map +1 -0
  72. package/dist/processors/media-type-object.processor.js +43 -0
  73. package/dist/processors/media-type-object.processor.js.map +1 -0
  74. package/dist/processors/openapi.processor.d.ts +27 -0
  75. package/dist/processors/openapi.processor.d.ts.map +1 -0
  76. package/dist/processors/openapi.processor.js +166 -0
  77. package/dist/processors/openapi.processor.js.map +1 -0
  78. package/dist/processors/parameter-object.processor.d.ts +6 -0
  79. package/dist/processors/parameter-object.processor.d.ts.map +1 -0
  80. package/dist/processors/parameter-object.processor.js +90 -0
  81. package/dist/processors/parameter-object.processor.js.map +1 -0
  82. package/dist/processors/request-body-object.processor.d.ts +14 -0
  83. package/dist/processors/request-body-object.processor.d.ts.map +1 -0
  84. package/dist/processors/request-body-object.processor.js +61 -0
  85. package/dist/processors/request-body-object.processor.js.map +1 -0
  86. package/dist/processors/response-object.processor.d.ts +12 -0
  87. package/dist/processors/response-object.processor.d.ts.map +1 -0
  88. package/dist/processors/response-object.processor.js +44 -0
  89. package/dist/processors/response-object.processor.js.map +1 -0
  90. package/dist/processors/responses-object.processor.d.ts +5 -0
  91. package/dist/processors/responses-object.processor.d.ts.map +1 -0
  92. package/dist/processors/responses-object.processor.js +27 -0
  93. package/dist/processors/responses-object.processor.js.map +1 -0
  94. package/dist/processors/runtime-expression.processor.d.ts +4 -0
  95. package/dist/processors/runtime-expression.processor.d.ts.map +1 -0
  96. package/dist/processors/runtime-expression.processor.js +24 -0
  97. package/dist/processors/runtime-expression.processor.js.map +1 -0
  98. package/dist/processors/security-scheme-object.processor.d.ts +4 -0
  99. package/dist/processors/security-scheme-object.processor.d.ts.map +1 -0
  100. package/dist/processors/security-scheme-object.processor.js +50 -0
  101. package/dist/processors/security-scheme-object.processor.js.map +1 -0
  102. package/dist/processors/utils.d.ts +9 -0
  103. package/dist/processors/utils.d.ts.map +1 -0
  104. package/dist/processors/utils.js +21 -0
  105. package/dist/processors/utils.js.map +1 -0
  106. package/dist/runtime-expression.d.ts +8 -0
  107. package/dist/runtime-expression.d.ts.map +1 -0
  108. package/dist/runtime-expression.js +2 -0
  109. package/dist/runtime-expression.js.map +1 -0
  110. package/dist/search-for-openapi-files.d.ts +8 -0
  111. package/dist/search-for-openapi-files.d.ts.map +1 -0
  112. package/dist/search-for-openapi-files.js +44 -0
  113. package/dist/search-for-openapi-files.js.map +1 -0
  114. package/package.json +61 -0
@@ -0,0 +1,31 @@
1
+ import { type HttpFilterExpression, type Logger, type ThymianFormat } from '@thymian/core';
2
+ import type { OpenAPI, OpenAPIV3_1 } from 'openapi-types';
3
+ import type { ServerInfo } from './processors/extract-server-info.js';
4
+ export type LoadResult = {
5
+ document: OpenAPIV3_1.Document;
6
+ original: OpenAPI.Document;
7
+ filePath?: string;
8
+ };
9
+ export declare function loadOpenApi(value: string, cwd?: string): Promise<{
10
+ document: object;
11
+ filePath: string | undefined;
12
+ }>;
13
+ export declare function loadAndUpgrade(value: string, cwd: string | undefined, logger: Logger): Promise<LoadResult>;
14
+ export declare function openapiToThymianFormat(document: OpenAPIV3_1.Document, options: {
15
+ logger?: Logger;
16
+ serverInfo: ServerInfo;
17
+ filter: HttpFilterExpression;
18
+ filePath?: string;
19
+ format?: ThymianFormat;
20
+ sourceName?: string;
21
+ cwd?: string;
22
+ }): Promise<ThymianFormat>;
23
+ export declare function loadAndTransform(value: string, options: {
24
+ logger: Logger;
25
+ serverInfo: ServerInfo;
26
+ cwd: string;
27
+ filter: HttpFilterExpression;
28
+ format?: ThymianFormat;
29
+ sourceName?: string;
30
+ }): Promise<[OpenAPI.Document, ThymianFormat, string | undefined]>;
31
+ //# sourceMappingURL=load-openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-openapi.d.ts","sourceRoot":"","sources":["../src/load-openapi.ts"],"names":[],"mappings":"AAYA,OAAO,EAC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AAoB,CAAC;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAkBhE"}
@@ -0,0 +1,159 @@
1
+ import { access } from 'node:fs/promises';
2
+ import { isAbsolute, join, relative } from 'node:path';
3
+ import { bundle } from '@scalar/json-magic/bundle';
4
+ import { fetchUrls, parseJson, parseYaml, readFiles, } from '@scalar/json-magic/bundle/plugins/node';
5
+ import { dereference, validate } from '@scalar/openapi-parser';
6
+ import { upgrade } from '@scalar/openapi-upgrader';
7
+ import { NoopLogger, ThymianBaseError, } from '@thymian/core';
8
+ import { locMapperForFile } from './loc-mapper/loc-mapper-for-file.js';
9
+ import { NoopLocMapper } from './loc-mapper/noop-loc-mapper.js';
10
+ import { OpenapiProcessor } from './processors/openapi.processor.js';
11
+ function getRelativePath(filePath, cwd) {
12
+ try {
13
+ return relative(cwd, filePath);
14
+ }
15
+ catch {
16
+ return filePath;
17
+ }
18
+ }
19
+ function formatSourceLabel(relativePath) {
20
+ return relativePath ? `'${relativePath}'` : 'the OpenAPI document';
21
+ }
22
+ async function fileExists(path) {
23
+ try {
24
+ await access(path);
25
+ return true;
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
31
+ export async function loadOpenApi(value, cwd = process.cwd()) {
32
+ const readFilesPlugin = readFiles();
33
+ // the validate function of the readFiles plugin returns undefined if the value is not a local file
34
+ const isFileValue = readFilesPlugin.validate(value);
35
+ const finalValue = !isFileValue || (isFileValue && isAbsolute(value))
36
+ ? value
37
+ : join(cwd, value);
38
+ const relativePath = isFileValue
39
+ ? getRelativePath(finalValue, cwd)
40
+ : undefined;
41
+ const plugins = [parseJson(), parseYaml(), readFilesPlugin, fetchUrls()];
42
+ try {
43
+ return {
44
+ document: await bundle(finalValue, {
45
+ plugins,
46
+ treeShake: false,
47
+ }),
48
+ filePath: isFileValue ? finalValue : undefined,
49
+ };
50
+ }
51
+ catch (e) {
52
+ if (isFileValue && !(await fileExists(finalValue))) {
53
+ throw new ThymianBaseError(`OpenAPI file not found: ${relativePath ?? value}`, {
54
+ name: 'OpenAPIFileNotFoundError',
55
+ ref: 'https://thymian.dev/references/errors/openapi-file-not-found-error/',
56
+ cause: e,
57
+ suggestions: [
58
+ `Verify the file path is correct: ${relativePath ?? value}`,
59
+ 'Check file permissions and ensure the file is readable',
60
+ ],
61
+ });
62
+ }
63
+ const sourceLabel = relativePath ? `'${relativePath}'` : 'the document';
64
+ throw new ThymianBaseError(`Failed to read or parse ${sourceLabel}.`, {
65
+ name: 'OpenAPILoadError',
66
+ cause: e,
67
+ suggestions: [
68
+ 'Ensure the content is valid YAML or JSON',
69
+ ...(isFileValue
70
+ ? [
71
+ `Verify the file path is correct: ${relativePath ?? value}`,
72
+ 'Check file permissions and ensure the file is readable',
73
+ ]
74
+ : []),
75
+ ],
76
+ });
77
+ }
78
+ }
79
+ export async function loadAndUpgrade(value, cwd = process.cwd(), logger) {
80
+ const { document, filePath } = await loadOpenApi(value, cwd);
81
+ const relativePath = filePath ? getRelativePath(filePath, cwd) : undefined;
82
+ const sourceLabel = formatSourceLabel(relativePath);
83
+ logger.info(`Loading ${sourceLabel}.`);
84
+ const validationResult = await validate(document, { throwOnError: false });
85
+ if (!validationResult.valid && validationResult.errors) {
86
+ const refErrors = validationResult.errors.filter((err) => err.code === 'INVALID_REFERENCE');
87
+ if (refErrors.length > 0) {
88
+ throw new ThymianBaseError(`Invalid $ref${refErrors.length > 1 ? 's' : ''} found: ${refErrors.map((err) => err.message).join(', ')}`, {
89
+ name: 'OpenAPIDereferenceError',
90
+ ref: 'https://thymian.dev/references/errors/openapi-dereference-error/',
91
+ cause: new Error(validationResult?.errors?.map((e) => e.message).join('; ') ?? ''),
92
+ suggestions: [
93
+ 'Ensure all $refs are valid and resolve to a valid non-external location.',
94
+ ],
95
+ });
96
+ }
97
+ throw new ThymianBaseError(`Schema validation for ${sourceLabel} failed.`, {
98
+ name: 'OpenAPIValidationError',
99
+ ref: 'https://thymian.dev/references/errors/openapi-validation-error/',
100
+ cause: new Error(validationResult.errors.map((e) => e.message).join('; ')),
101
+ suggestions: [
102
+ 'This indicates that your OpenAPI document does not match the OpenAPI specification. Use `thymian openapi:validate` to get detailed validation errors',
103
+ 'Ensure all required fields are present (openapi, info, paths)',
104
+ ],
105
+ });
106
+ }
107
+ logger.debug(`Successfully validated ${sourceLabel}.`);
108
+ const upgradedObject = upgrade(structuredClone(document), '3.1');
109
+ logger.debug(`Upgraded ${sourceLabel} to version 3.1.`);
110
+ const dereferencedResult = dereference(upgradedObject, {
111
+ throwOnError: false,
112
+ });
113
+ if (dereferencedResult?.errors?.length || !dereferencedResult.schema) {
114
+ logger.debug(`Cannot dereference ${sourceLabel}.`);
115
+ throw new ThymianBaseError(`Dereferencing all internal references in ${sourceLabel} failed.`, {
116
+ name: 'OpenAPIDereferenceError',
117
+ ref: 'https://thymian.dev/references/errors/openapi-dereference-error/',
118
+ cause: new Error(dereferencedResult?.errors?.map((e) => e.message).join('; ') ?? ''),
119
+ suggestions: [
120
+ 'Ensure all $refs are valid and resolve to a valid non-external location.',
121
+ ],
122
+ });
123
+ }
124
+ return {
125
+ document: dereferencedResult.schema,
126
+ original: document,
127
+ filePath: filePath ? filePath : undefined,
128
+ };
129
+ }
130
+ export async function openapiToThymianFormat(document, options) {
131
+ const sourceLabel = options.filePath
132
+ ? formatSourceLabel(getRelativePath(options.filePath, options.cwd ?? process.cwd()))
133
+ : formatSourceLabel(undefined);
134
+ if (typeof document.openapi !== 'string' ||
135
+ !document.openapi.startsWith('3.1')) {
136
+ throw new ThymianBaseError(`Only OpenAPI 3.1.x documents are supported (found in ${sourceLabel}).`, {
137
+ name: 'OpenAPIDocumentVersionError',
138
+ });
139
+ }
140
+ const locMapper = typeof options.filePath === 'string'
141
+ ? await locMapperForFile(options.filePath)
142
+ : new NoopLocMapper();
143
+ return new OpenapiProcessor(options.logger ?? new NoopLogger(), options.serverInfo, locMapper, options.format).process(document, options.filter, options.sourceName);
144
+ }
145
+ export async function loadAndTransform(value, options) {
146
+ const loadResult = await loadAndUpgrade(value, options.cwd, options.logger);
147
+ const relativePath = loadResult.filePath
148
+ ? getRelativePath(loadResult.filePath, options.cwd)
149
+ : undefined;
150
+ const result = await openapiToThymianFormat(loadResult.document, {
151
+ ...options,
152
+ filePath: loadResult.filePath,
153
+ filter: options.filter,
154
+ cwd: options.cwd,
155
+ });
156
+ options.logger.debug(`Transformed ${formatSourceLabel(relativePath)} into Thymian format.`);
157
+ return [loadResult.original, result, loadResult.filePath];
158
+ }
159
+ //# sourceMappingURL=load-openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-openapi.js","sourceRoot":"","sources":["../src/load-openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,GACV,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAGL,UAAU,EACV,gBAAgB,GAEjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,SAAS,eAAe,CAAC,QAAgB,EAAE,GAAW;IACpD,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,GAAG,EAAE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OAAO,CAAC,GAAG;KACjB,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,eAAe,iBAAiB,CAAC,YAAY,CAAC,uBAAuB,CACtE,CAAC;IAEF,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { ThymianFormatPosition } from '@thymian/core';
2
+ import { LocMapper } from './loc-mapper.js';
3
+ export declare class JsonLocMapper extends LocMapper {
4
+ private readonly root;
5
+ private readonly lineStarts;
6
+ constructor(jsonText: string, path: string);
7
+ positionForOperationId(operationId: string): ThymianFormatPosition | undefined;
8
+ lineForOperationId(operationId: string): number | undefined;
9
+ private findOperationIdProperty;
10
+ private sliceNodeText;
11
+ private offsetToLineCol;
12
+ private static computeLineStarts;
13
+ private static unquote;
14
+ }
15
+ //# sourceMappingURL=json-loc-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-loc-mapper.d.ts","sourceRoot":"","sources":["../../src/loc-mapper/json-loc-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;gBAE1B,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAMnC,sBAAsB,CAC3B,WAAW,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS;IAmB7B,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAKlE,OAAO,CAAC,uBAAuB;IA4B/B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,eAAe;IAuBvB,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAgBhC,OAAO,CAAC,MAAM,CAAC,OAAO;CAUvB"}
@@ -0,0 +1,105 @@
1
+ import { parseTree } from 'jsonc-parser';
2
+ import { LocMapper } from './loc-mapper.js';
3
+ export class JsonLocMapper extends LocMapper {
4
+ root;
5
+ lineStarts;
6
+ constructor(jsonText, path) {
7
+ super(jsonText, path);
8
+ this.root = parseTree(jsonText);
9
+ this.lineStarts = JsonLocMapper.computeLineStarts(jsonText);
10
+ }
11
+ positionForOperationId(operationId) {
12
+ if (!this.root) {
13
+ return undefined;
14
+ }
15
+ const opIdProp = this.findOperationIdProperty(this.root, operationId);
16
+ if (!opIdProp) {
17
+ return undefined;
18
+ }
19
+ const operationObject = opIdProp.parent;
20
+ const methodProp = operationObject?.parent;
21
+ if (methodProp && methodProp.type === 'property') {
22
+ return this.offsetToLineCol(methodProp.offset);
23
+ }
24
+ return this.offsetToLineCol(opIdProp.offset);
25
+ }
26
+ lineForOperationId(operationId) {
27
+ const pos = this.positionForOperationId(operationId);
28
+ return pos ? pos.line : undefined;
29
+ }
30
+ findOperationIdProperty(node, wanted) {
31
+ const stack = [node];
32
+ while (stack.length) {
33
+ const cur = stack.pop();
34
+ if (cur.type === 'property' &&
35
+ cur.children &&
36
+ cur.children.length === 2) {
37
+ const [keyNode, valueNode] = cur.children;
38
+ const keyText = this.sliceNodeText(keyNode);
39
+ if (JsonLocMapper.unquote(keyText) === 'operationId') {
40
+ const valText = this.sliceNodeText(valueNode);
41
+ if (JsonLocMapper.unquote(valText) === wanted) {
42
+ return cur;
43
+ }
44
+ }
45
+ }
46
+ if (cur.children) {
47
+ stack.push(...cur.children);
48
+ }
49
+ }
50
+ return undefined;
51
+ }
52
+ sliceNodeText(n) {
53
+ return this.text.slice(n.offset, n.offset + n.length);
54
+ }
55
+ offsetToLineCol(offset) {
56
+ let low = 0, high = this.lineStarts.length - 1;
57
+ while (low <= high) {
58
+ const mid = (low + high) >> 1;
59
+ const start = this.lineStarts[mid];
60
+ const nextStart = mid + 1 < this.lineStarts.length
61
+ ? this.lineStarts[mid + 1]
62
+ : this.text.length + 1;
63
+ if (offset < start) {
64
+ high = mid - 1;
65
+ }
66
+ else if (offset >= nextStart) {
67
+ low = mid + 1;
68
+ }
69
+ else {
70
+ const line = mid + 1;
71
+ const column = offset - start + 1;
72
+ return { line, column, offset };
73
+ }
74
+ }
75
+ return { line: 1, column: offset + 1, offset };
76
+ }
77
+ static computeLineStarts(s) {
78
+ const starts = [0];
79
+ for (let i = 0; i < s.length; i++) {
80
+ const ch = s.charCodeAt(i);
81
+ if (ch === 13) {
82
+ if (i + 1 < s.length && s.charCodeAt(i + 1) === 10) {
83
+ i++;
84
+ }
85
+ starts.push(i + 1);
86
+ }
87
+ else if (ch === 10) {
88
+ starts.push(i + 1);
89
+ }
90
+ }
91
+ return starts;
92
+ }
93
+ static unquote(text) {
94
+ if (text.length >= 2 && text.startsWith('"') && text.endsWith('"')) {
95
+ try {
96
+ return JSON.parse(text);
97
+ }
98
+ catch {
99
+ return text.slice(1, -1);
100
+ }
101
+ }
102
+ return text;
103
+ }
104
+ }
105
+ //# sourceMappingURL=json-loc-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-loc-mapper.js","sourceRoot":"","sources":["../../src/loc-mapper/json-loc-mapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,SAAS,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IACzB,IAAI,CAAuB;IAC3B,UAAU,CAAW;IAEtC,YAAY,QAAgB,EAAE,IAAY;QACxC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAE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AAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACnE,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { LocMapper } from './loc-mapper.js';
2
+ export declare function isJson(str: string): boolean;
3
+ export declare function locMapperForFile(path: string): Promise<LocMapper>;
4
+ //# sourceMappingURL=loc-mapper-for-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loc-mapper-for-file.d.ts","sourceRoot":"","sources":["../../src/loc-mapper/loc-mapper-for-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO3C;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAMvE"}
@@ -0,0 +1,20 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { JsonLocMapper } from './json-loc-mapper.js';
3
+ import { LocMapper } from './loc-mapper.js';
4
+ import { YamlLocMapper } from './yaml-loc-mapper.js';
5
+ export function isJson(str) {
6
+ try {
7
+ JSON.parse(str);
8
+ return true;
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ export async function locMapperForFile(path) {
15
+ const text = await readFile(path, 'utf-8');
16
+ return isJson(text)
17
+ ? new JsonLocMapper(text, path)
18
+ : new YamlLocMapper(text, path);
19
+ }
20
+ //# sourceMappingURL=loc-mapper-for-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loc-mapper-for-file.js","sourceRoot":"","sources":["../../src/loc-mapper/loc-mapper-for-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY;IACjD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,IAAI,CAAC;QACjB,CAAC,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC;QAC/B,CAAC,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ThymianFormatLocation, ThymianFormatPosition } from '@thymian/core';
2
+ export declare abstract class LocMapper {
3
+ protected readonly text: string;
4
+ protected readonly path: string;
5
+ protected constructor(text: string, path: string);
6
+ abstract positionForOperationId(operationId: string): ThymianFormatPosition | undefined;
7
+ locationForOperationId(operationId: string): ThymianFormatLocation | undefined;
8
+ }
9
+ //# sourceMappingURL=loc-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loc-mapper.d.ts","sourceRoot":"","sources":["../../src/loc-mapper/loc-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAEvB,8BAAsB,SAAS;IAE3B,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAC/B,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAFjC,SAAS,aACY,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM;IAGjC,QAAQ,CAAC,sBAAsB,CAC7B,WAAW,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS;IAEpC,sBAAsB,CACpB,WAAW,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS;CAcrC"}
@@ -0,0 +1,22 @@
1
+ export class LocMapper {
2
+ text;
3
+ path;
4
+ constructor(text, path) {
5
+ this.text = text;
6
+ this.path = path;
7
+ }
8
+ locationForOperationId(operationId) {
9
+ const pos = this.positionForOperationId(operationId);
10
+ return pos
11
+ ? {
12
+ path: this.path,
13
+ position: {
14
+ line: pos.line,
15
+ column: pos.column,
16
+ offset: pos.offset,
17
+ },
18
+ }
19
+ : undefined;
20
+ }
21
+ }
22
+ //# sourceMappingURL=loc-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loc-mapper.js","sourceRoot":"","sources":["../../src/loc-mapper/loc-mapper.ts"],"names":[],"mappings":"AAKA,MAAM,OAAgB,SAAS;IAER;IACA;IAFrB,YACqB,IAAY,EACZ,IAAY;QADZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;IAC9B,CAAC;IAMJ,sBAAsB,CACpB,WAAmB;QAEnB,MAAM,GAAG,GAAG,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;QAErD,OAAO,GAAG;YACR,CAAC,CAAC;gBACE,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE;oBACR,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,MAAM,EAAE,GAAG,CAAC,MAAM;iBACnB;aACF;YACH,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { LocMapper } from './loc-mapper.js';
2
+ export declare class NoopLocMapper extends LocMapper {
3
+ constructor();
4
+ positionForOperationId(): undefined;
5
+ }
6
+ //# sourceMappingURL=noop-loc-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-loc-mapper.d.ts","sourceRoot":"","sources":["../../src/loc-mapper/noop-loc-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,aAAc,SAAQ,SAAS;;IAK1C,sBAAsB,IAAI,SAAS;CAGpC"}
@@ -0,0 +1,10 @@
1
+ import { LocMapper } from './loc-mapper.js';
2
+ export class NoopLocMapper extends LocMapper {
3
+ constructor() {
4
+ super('', '');
5
+ }
6
+ positionForOperationId() {
7
+ return undefined;
8
+ }
9
+ }
10
+ //# sourceMappingURL=noop-loc-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-loc-mapper.js","sourceRoot":"","sources":["../../src/loc-mapper/noop-loc-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C;QACE,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAChB,CAAC;IAED,sBAAsB;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import type { ThymianFormatPosition } from '@thymian/core';
2
+ import { LocMapper } from './loc-mapper.js';
3
+ export declare class YamlLocMapper extends LocMapper {
4
+ private readonly lineCounter;
5
+ private readonly doc;
6
+ constructor(text: string, path: string);
7
+ positionForOperationId(operationId: string): ThymianFormatPosition | undefined;
8
+ lineForOperationId(operationId: string): number | null;
9
+ private getTopLevelMap;
10
+ private findStringProperty;
11
+ private positionFromNode;
12
+ }
13
+ //# sourceMappingURL=yaml-loc-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml-loc-mapper.d.ts","sourceRoot":"","sources":["../../src/loc-mapper/yaml-loc-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAW3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAe5C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAmC;gBAE3C,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAM/B,sBAAsB,CAC3B,WAAW,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS;IAiD7B,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAK7D,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,gBAAgB;CAczB"}
@@ -0,0 +1,105 @@
1
+ import { isMap, LineCounter, Pair, parseDocument, Scalar, YAMLMap, } from 'yaml';
2
+ import { LocMapper } from './loc-mapper.js';
3
+ const HTTP_METHODS = [
4
+ 'get',
5
+ 'put',
6
+ 'post',
7
+ 'delete',
8
+ 'options',
9
+ 'head',
10
+ 'patch',
11
+ 'trace',
12
+ ];
13
+ export class YamlLocMapper extends LocMapper {
14
+ lineCounter;
15
+ doc;
16
+ constructor(text, path) {
17
+ super(text, path);
18
+ this.lineCounter = new LineCounter();
19
+ this.doc = parseDocument(text, { lineCounter: this.lineCounter });
20
+ }
21
+ positionForOperationId(operationId) {
22
+ const pathsMap = this.getTopLevelMap('paths');
23
+ if (!pathsMap) {
24
+ return undefined;
25
+ }
26
+ for (const pathPair of pathsMap.items) {
27
+ const pathKeyScalar = pathPair.key;
28
+ const pathVal = pathPair.value;
29
+ if (!pathKeyScalar || !isMap(pathVal)) {
30
+ continue;
31
+ }
32
+ for (const methodPair of pathVal.items) {
33
+ const methodKey = methodPair.key?.value;
34
+ if (!methodKey ||
35
+ !HTTP_METHODS.includes(String(methodKey))) {
36
+ continue;
37
+ }
38
+ const opObj = methodPair.value;
39
+ if (!isMap(opObj)) {
40
+ continue;
41
+ }
42
+ const opIdPair = this.findStringProperty(opObj, 'operationId', operationId);
43
+ if (opIdPair) {
44
+ const methodKeyNode = methodPair.key;
45
+ const posMethod = this.positionFromNode(methodKeyNode);
46
+ if (posMethod) {
47
+ return posMethod;
48
+ }
49
+ const opIdKeyNode = opIdPair.key;
50
+ const posOpId = this.positionFromNode(opIdKeyNode);
51
+ if (posOpId) {
52
+ return posOpId;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ lineForOperationId(operationId) {
60
+ const pos = this.positionForOperationId(operationId);
61
+ return pos ? pos.line : null;
62
+ }
63
+ getTopLevelMap(key) {
64
+ const contents = this.doc.contents;
65
+ if (!isMap(contents)) {
66
+ return null;
67
+ }
68
+ for (const p of contents.items) {
69
+ const k = p.key?.value;
70
+ if (k === key && isMap(p.value)) {
71
+ return p.value;
72
+ }
73
+ }
74
+ return null;
75
+ }
76
+ findStringProperty(map, propName, expectedValue) {
77
+ for (const p of map.items) {
78
+ const keyVal = p.key?.value;
79
+ if (keyVal !== propName) {
80
+ continue;
81
+ }
82
+ if (expectedValue === undefined) {
83
+ return p;
84
+ }
85
+ const valNode = p.value;
86
+ const valStr = valNode?.value;
87
+ if (typeof valStr === 'string' && valStr === expectedValue) {
88
+ return p;
89
+ }
90
+ }
91
+ return null;
92
+ }
93
+ positionFromNode(node) {
94
+ if (!node || !Array.isArray(node.range)) {
95
+ return null;
96
+ }
97
+ const [start] = node.range;
98
+ if (typeof start !== 'number') {
99
+ return null;
100
+ }
101
+ const { line, col } = this.lineCounter.linePos(start);
102
+ return { line, column: col, offset: start };
103
+ }
104
+ }
105
+ //# sourceMappingURL=yaml-loc-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml-loc-mapper.js","sourceRoot":"","sources":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,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { OpenAPIV3_1 as OpenApiV31 } from 'openapi-types';
2
+ export type ServerInfo = {
3
+ port: number;
4
+ host: string;
5
+ protocol: 'http' | 'https';
6
+ basePath: string;
7
+ };
8
+ export declare const defaultServerInfo: ServerInfo;
9
+ export declare function extractServerInfo(serverObjects?: OpenApiV31.ServerObject[], defaultInfo?: ServerInfo): ServerInfo;
10
+ //# sourceMappingURL=extract-server-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-server-info.d.ts","sourceRoot":"","sources":["../../src/processors/extract-server-info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,UAK/B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,aAAa,GAAE,UAAU,CAAC,YAAY,EAAO,EAC7C,WAAW,GAAE,UAA8B,GAC1C,UAAU,CA8CZ"}
@@ -0,0 +1,40 @@
1
+ export const defaultServerInfo = {
2
+ basePath: '',
3
+ host: 'localhost',
4
+ port: 8080,
5
+ protocol: 'http',
6
+ };
7
+ export function extractServerInfo(serverObjects = [], defaultInfo = defaultServerInfo) {
8
+ const serverInfo = {
9
+ ...defaultInfo,
10
+ };
11
+ const localServer = serverObjects.find((serverObject) => {
12
+ serverObject.url.includes('localhost');
13
+ }) ?? serverObjects[0];
14
+ if (localServer) {
15
+ const urlWithVariables = localServer.url.replaceAll(/\{(.*?)}/g, (match, variable) => {
16
+ if (localServer?.variables?.[variable]) {
17
+ return (localServer.variables[variable].default ??
18
+ localServer.variables[variable].enum?.[0] ??
19
+ match);
20
+ }
21
+ return match;
22
+ });
23
+ try {
24
+ const url = new URL(urlWithVariables);
25
+ serverInfo.host = url.hostname;
26
+ serverInfo.port = url.port
27
+ ? parseInt(url.port)
28
+ : url.protocol === 'https:'
29
+ ? 443
30
+ : 80;
31
+ serverInfo.protocol = url.protocol.replace(':', '');
32
+ serverInfo.basePath = url.pathname;
33
+ }
34
+ catch (_) {
35
+ /**/
36
+ }
37
+ }
38
+ return serverInfo;
39
+ }
40
+ //# sourceMappingURL=extract-server-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-server-info.js","sourceRoot":"","sources":["../../src/processors/extract-server-info.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,iBAAiB,GAAe;IAC3C,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,MAAM;CACjB,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAC/B,gBAA2C,EAAE,EAC7C,cAA0B,iBAAiB;IAE3C,MAAM,UAAU,GAAe;QAC7B,GAAG,WAAW;KACf,CAAC;IAEF,MAAM,WAAW,GACf,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;QAClC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;IAEzB,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CACjD,WAAW,EACX,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAClB,IAAI,WAAW,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACvC,OAAO,CACL,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO;oBACvC,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