@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
package/dist/index.js ADDED
@@ -0,0 +1,116 @@
1
+ import { constant, ThymianFormat, } from '@thymian/core';
2
+ import { loadAndTransform } from './load-openapi.js';
3
+ export const defaultServerInfo = {
4
+ port: 8080,
5
+ host: 'localhost',
6
+ protocol: 'http',
7
+ basePath: '',
8
+ };
9
+ export const openApiPlugin = {
10
+ name: '@thymian/plugin-openapi',
11
+ version: '0.x',
12
+ options: {
13
+ // ### for reference documentation ###
14
+ title: 'Plugin Options',
15
+ description: 'Configuration options for the OpenAPI plugin',
16
+ // ###################################
17
+ type: 'object',
18
+ additionalProperties: false,
19
+ properties: {
20
+ descriptions: {
21
+ type: 'array',
22
+ nullable: true,
23
+ items: {
24
+ type: 'object',
25
+ additionalProperties: false,
26
+ required: ['source'],
27
+ properties: {
28
+ source: {
29
+ type: 'string',
30
+ nullable: false,
31
+ },
32
+ sourceName: {
33
+ type: 'string',
34
+ nullable: true,
35
+ },
36
+ serverInfo: {
37
+ type: 'object',
38
+ nullable: true,
39
+ required: ['host', 'port', 'basePath', 'protocol'],
40
+ properties: {
41
+ basePath: {
42
+ type: 'string',
43
+ nullable: false,
44
+ },
45
+ port: {
46
+ type: 'integer',
47
+ nullable: false,
48
+ },
49
+ host: {
50
+ type: 'string',
51
+ nullable: false,
52
+ },
53
+ protocol: {
54
+ type: 'string',
55
+ nullable: false,
56
+ enum: ['http', 'https'],
57
+ },
58
+ },
59
+ },
60
+ },
61
+ },
62
+ },
63
+ },
64
+ },
65
+ plugin: async (emitter, logger, opts) => {
66
+ emitter.onAction('openapi.transform', async ({ content, filter }, ctx) => {
67
+ const [, thymianFormat] = await loadAndTransform(content, {
68
+ logger,
69
+ serverInfo: defaultServerInfo,
70
+ cwd: opts.cwd,
71
+ filter: filter ?? constant(true),
72
+ });
73
+ ctx.reply(thymianFormat.export());
74
+ });
75
+ emitter.onAction('core.format.load', async ({ inputs }, ctx) => {
76
+ let format = new ThymianFormat();
77
+ const descriptions = inputs.length
78
+ ? inputs
79
+ .filter((input) => input.type === 'openapi')
80
+ .map((input) => ({
81
+ source: String(input.location),
82
+ sourceName: typeof input.options?.['sourceName'] === 'string'
83
+ ? input.options['sourceName']
84
+ : undefined,
85
+ serverInfo: typeof input.options?.['serverInfo'] === 'object' &&
86
+ input.options['serverInfo'] !== null
87
+ ? input.options['serverInfo']
88
+ : undefined,
89
+ }))
90
+ : (opts.descriptions ?? []);
91
+ if (descriptions.length === 0) {
92
+ ctx.reply(format.export());
93
+ return;
94
+ }
95
+ for (const description of descriptions) {
96
+ const [document, thymianFormat, filePath] = await loadAndTransform(description.source, {
97
+ logger,
98
+ format,
99
+ serverInfo: description.serverInfo ?? defaultServerInfo,
100
+ sourceName: description.sourceName,
101
+ cwd: opts.cwd,
102
+ filter: constant(true),
103
+ });
104
+ format = thymianFormat;
105
+ emitter.emit('openapi.document', {
106
+ document,
107
+ filePath,
108
+ });
109
+ }
110
+ ctx.reply(format.export());
111
+ });
112
+ },
113
+ };
114
+ export default openApiPlugin;
115
+ export { searchForOpenApiFiles } from './search-for-openapi-files.js';
116
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,E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{ 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<[object, string | undefined]>;
10
+ export declare function loadAndUpgrade(value: string, cwd: string | undefined, logger: Logger): Promise<LoadResult>;
11
+ export declare function openapiToThymianFormat(document: OpenAPIV3_1.Document, options: {
12
+ logger?: Logger;
13
+ serverInfo: ServerInfo;
14
+ filter: HttpFilterExpression;
15
+ filePath?: string;
16
+ format?: ThymianFormat;
17
+ sourceName?: string;
18
+ }): Promise<ThymianFormat>;
19
+ export declare function loadAndTransform(value: string, options: {
20
+ logger: Logger;
21
+ serverInfo: ServerInfo;
22
+ cwd: string;
23
+ filter: HttpFilterExpression;
24
+ format?: ThymianFormat;
25
+ sourceName?: string;
26
+ }): Promise<[OpenAPI.Document, ThymianFormat, string | undefined]>;
27
+ //# 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":"AAWA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,MAAM,EAGX,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAGtE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC;IAC/B,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAkBvC;AAED,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,YAAgB,EAC3B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,CAoCrB;AAED,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAC9B,OAAO,EAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,aAAa,CAAC,CAkBxB;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,oBAAoB,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,CAYhE"}
@@ -0,0 +1,76 @@
1
+ import { isAbsolute, join } from 'node:path';
2
+ import { bundle } from '@scalar/json-magic/bundle';
3
+ import { fetchUrls, parseJson, parseYaml, readFiles, } from '@scalar/json-magic/bundle/plugins/node';
4
+ import { dereference, validate } from '@scalar/openapi-parser';
5
+ import { upgrade } from '@scalar/openapi-upgrader';
6
+ import { NoopLogger, ThymianBaseError, } from '@thymian/core';
7
+ import { locMapperForFile } from './loc-mapper/loc-mapper-for-file.js';
8
+ import { NoopLocMapper } from './loc-mapper/noop-loc-mapper.js';
9
+ import { OpenapiProcessor } from './processors/openapi.processor.js';
10
+ export async function loadOpenApi(value, cwd = process.cwd()) {
11
+ const readFilesPlugin = readFiles();
12
+ // the validate function of the readFiles plugin returns undefined if the value is not a local file
13
+ const isFileValue = readFilesPlugin.validate(value);
14
+ const finalValue = !isFileValue || (isFileValue && isAbsolute(value))
15
+ ? value
16
+ : join(cwd, value);
17
+ const plugins = [parseJson(), parseYaml(), readFilesPlugin, fetchUrls()];
18
+ return [
19
+ await bundle(finalValue, {
20
+ plugins,
21
+ treeShake: false,
22
+ }),
23
+ isFileValue ? finalValue : undefined,
24
+ ];
25
+ }
26
+ export async function loadAndUpgrade(value, cwd = process.cwd(), logger) {
27
+ try {
28
+ const [result, filePath] = await loadOpenApi(value, cwd);
29
+ logger.debug(`Loaded OpenAPI document.`);
30
+ await validate(result, { throwOnError: true });
31
+ logger.debug(`Successfully validated OpenAPI document.`);
32
+ const upgradedObject = upgrade(structuredClone(result), '3.1');
33
+ logger.debug(`Upgraded OpenAPI document.`);
34
+ const dereferenced = dereference(upgradedObject, {
35
+ throwOnError: true,
36
+ }).schema;
37
+ logger.debug(`Dereferenced OpenAPI document.`);
38
+ return {
39
+ document: dereferenced,
40
+ original: result,
41
+ filePath: filePath,
42
+ };
43
+ }
44
+ catch (e) {
45
+ throw new ThymianBaseError(`Error while loading OpenAPI document.`, {
46
+ name: 'OpenAPILoadError',
47
+ ref: 'https://thymian.dev/references/errors/openapi-load-error/',
48
+ cause: e,
49
+ suggestions: [
50
+ 'Currently, only files without external references are supported. Do your OpenAPI documents contain any external references?',
51
+ 'You can validate your OpenAPI document using the `thymian openapi:validate` command.',
52
+ ],
53
+ });
54
+ }
55
+ }
56
+ export async function openapiToThymianFormat(document, options) {
57
+ if (typeof document.openapi !== 'string' ||
58
+ !document.openapi.startsWith('3.1')) {
59
+ throw new ThymianBaseError('Only OpenAPI 3.1.x documents are supported.');
60
+ }
61
+ const locMapper = typeof options.filePath === 'string'
62
+ ? await locMapperForFile(options.filePath)
63
+ : new NoopLocMapper();
64
+ return new OpenapiProcessor(options.logger ?? new NoopLogger(), options.serverInfo, locMapper, options.format).process(document, options.filter, options.sourceName);
65
+ }
66
+ export async function loadAndTransform(value, options) {
67
+ const loadResult = await loadAndUpgrade(value, options.cwd, options.logger);
68
+ const result = await openapiToThymianFormat(loadResult.document, {
69
+ ...options,
70
+ filePath: loadResult.filePath,
71
+ filter: options.filter,
72
+ });
73
+ options.logger.debug('Transformed OpenAPI document into Thymian format.');
74
+ return [loadResult.original, result, loadResult.filePath];
75
+ }
76
+ //# 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,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE7C,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;AAQrE,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAa,EACb,MAAc,OAAO,CAAC,GAAG,EAAE;IAE3B,MAAM,eAAe,GAAG,SAAS,EAAE,CAAC;IACpC,mGAAmG;IACnG,MAAM,WAAW,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,UAAU,GACd,CAAC,WAAW,IAA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AAC;IAEH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAE1E,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;IAEM,sBAAsB,CAC3B,WAAmB;QAEnB,IAAI,CAAC,IAAI,CAAC,IAAI,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AC;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":["../../src/loc-mapper/yaml-loc-mapper.ts"],"names":[],"mappings":"AACA,OAAO,EACL,K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AAE,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"}