@speclynx/apidom-reference 2.7.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +197 -0
- package/dist/apidom-reference.browser.js +221 -83
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +25 -25
- package/src/dereference/strategies/arazzo-1/index.cjs +3 -2
- package/src/dereference/strategies/arazzo-1/index.mjs +3 -2
- package/src/dereference/strategies/arazzo-1/{source-description.cjs → source-descriptions.cjs} +94 -29
- package/src/dereference/strategies/arazzo-1/{source-description.mjs → source-descriptions.mjs} +95 -28
- package/src/parse/parsers/arazzo-json-1/index.cjs +3 -2
- package/src/parse/parsers/arazzo-json-1/index.mjs +3 -2
- package/src/parse/parsers/arazzo-json-1/{source-description.cjs → source-descriptions.cjs} +58 -12
- package/src/parse/parsers/arazzo-json-1/{source-description.mjs → source-descriptions.mjs} +57 -11
- package/src/parse/parsers/arazzo-yaml-1/index.cjs +3 -2
- package/src/parse/parsers/arazzo-yaml-1/index.mjs +3 -2
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.cjs +12 -0
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.mjs +7 -0
- package/types/dereference/strategies/arazzo-1/index.d.ts +1 -0
- package/types/dereference/strategies/arazzo-1/source-descriptions.d.ts +41 -0
- package/types/parse/parsers/arazzo-json-1/index.d.ts +1 -0
- package/types/parse/parsers/arazzo-json-1/source-descriptions.d.ts +44 -0
- package/types/parse/parsers/arazzo-yaml-1/index.d.ts +1 -0
- package/types/parse/parsers/arazzo-yaml-1/source-descriptions.d.ts +6 -0
- package/types/dereference/strategies/arazzo-1/source-description.d.ts +0 -8
- package/types/parse/parsers/arazzo-json-1/source-description.d.ts +0 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
3
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.parseSourceDescriptions = parseSourceDescriptions;
|
|
7
7
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
@@ -10,6 +10,7 @@ var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-2");
|
|
|
10
10
|
var _apidomNsOpenapi2 = require("@speclynx/apidom-ns-openapi-3-0");
|
|
11
11
|
var _apidomNsOpenapi3 = require("@speclynx/apidom-ns-openapi-3-1");
|
|
12
12
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
13
|
+
var _File = _interopRequireDefault(require("../../../File.cjs"));
|
|
13
14
|
var url = _interopRequireWildcard(require("../../../util/url.cjs"));
|
|
14
15
|
var _util = require("../../../options/util.cjs");
|
|
15
16
|
var _index = _interopRequireDefault(require("../../index.cjs"));
|
|
@@ -39,7 +40,9 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
39
40
|
parseResult.push(annotation);
|
|
40
41
|
return parseResult;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
|
|
44
|
+
// normalize URI for consistent cycle detection and cache key matching
|
|
45
|
+
const retrievalURI = url.sanitize(url.stripHash(url.resolve(ctx.baseURI, sourceDescriptionURI)));
|
|
43
46
|
|
|
44
47
|
// skip if already visited (cycle detection)
|
|
45
48
|
if (ctx.visitedUrls.has(retrievalURI)) {
|
|
@@ -50,11 +53,14 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
50
53
|
}
|
|
51
54
|
ctx.visitedUrls.add(retrievalURI);
|
|
52
55
|
try {
|
|
53
|
-
const
|
|
56
|
+
const sourceDescriptionParseResult = await (0, _index.default)(retrievalURI, (0, _util.merge)(ctx.options, {
|
|
54
57
|
parse: {
|
|
55
58
|
mediaType: 'text/plain',
|
|
56
59
|
// allow parser plugin detection
|
|
57
60
|
parserOpts: {
|
|
61
|
+
// nested documents should parse all their source descriptions
|
|
62
|
+
// (parent's name filter doesn't apply to nested documents)
|
|
63
|
+
sourceDescriptions: true,
|
|
58
64
|
[ARAZZO_RECURSION_KEY]: {
|
|
59
65
|
sourceDescriptionsDepth: ctx.currentDepth + 1,
|
|
60
66
|
sourceDescriptionsVisitedUrls: ctx.visitedUrls
|
|
@@ -63,7 +69,7 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
63
69
|
}
|
|
64
70
|
}));
|
|
65
71
|
// merge parsed result into our parse result
|
|
66
|
-
for (const item of
|
|
72
|
+
for (const item of sourceDescriptionParseResult) {
|
|
67
73
|
parseResult.push(item);
|
|
68
74
|
}
|
|
69
75
|
} catch (error) {
|
|
@@ -105,10 +111,53 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
/**
|
|
108
|
-
*
|
|
114
|
+
* Parses source descriptions from an Arazzo document's ParseResult.
|
|
115
|
+
*
|
|
116
|
+
* Each source description result is attached to its corresponding
|
|
117
|
+
* SourceDescriptionElement's meta as 'parseResult' for easy access,
|
|
118
|
+
* regardless of success or failure. On failure, the ParseResultElement
|
|
119
|
+
* contains annotations explaining what went wrong.
|
|
120
|
+
*
|
|
121
|
+
* @param parseResult - ParseResult containing an Arazzo specification
|
|
122
|
+
* @param parseResultRetrievalURI - URI from which the parseResult was retrieved
|
|
123
|
+
* @param options - Full ReferenceOptions. Pass `sourceDescriptions` as an array of names
|
|
124
|
+
* in `parse.parserOpts` to filter which source descriptions to process.
|
|
125
|
+
* @param parserName - Parser name for options lookup (defaults to 'arazzo-json-1')
|
|
126
|
+
* @returns Array of ParseResultElements. Returns one ParseResultElement per source description
|
|
127
|
+
* (each with class 'source-description' and name/type metadata).
|
|
128
|
+
* May return early with a single-element array containing a warning annotation when:
|
|
129
|
+
* - The API is not an Arazzo specification
|
|
130
|
+
* - The sourceDescriptions field is missing or not an array
|
|
131
|
+
* - Maximum parse depth is exceeded (error annotation)
|
|
132
|
+
* Returns an empty array when no source description names match the filter.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* import { options, mergeOptions } from '@speclynx/apidom-reference';
|
|
137
|
+
* import { parseSourceDescriptions } from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
138
|
+
*
|
|
139
|
+
* // Parse all source descriptions
|
|
140
|
+
* const results = await parseSourceDescriptions(parseResult, uri, options);
|
|
141
|
+
*
|
|
142
|
+
* // Filter by name
|
|
143
|
+
* const filtered = await parseSourceDescriptions(parseResult, uri, mergeOptions(options, {
|
|
144
|
+
* parse: { parserOpts: { sourceDescriptions: ['petStore'] } }
|
|
145
|
+
* }));
|
|
146
|
+
*
|
|
147
|
+
* // Access parsed document from source description element
|
|
148
|
+
* const sourceDesc = parseResult.api.sourceDescriptions.get(0);
|
|
149
|
+
* const parsedDoc = sourceDesc.meta.get('parseResult');
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
109
152
|
* @public
|
|
110
153
|
*/
|
|
111
|
-
async function parseSourceDescriptions(
|
|
154
|
+
async function parseSourceDescriptions(parseResult, parseResultRetrievalURI, options, parserName = 'arazzo-json-1') {
|
|
155
|
+
const {
|
|
156
|
+
api
|
|
157
|
+
} = parseResult;
|
|
158
|
+
const file = new _File.default({
|
|
159
|
+
uri: url.sanitize(url.stripHash(parseResultRetrievalURI))
|
|
160
|
+
});
|
|
112
161
|
const results = [];
|
|
113
162
|
|
|
114
163
|
/**
|
|
@@ -150,13 +199,8 @@ async function parseSourceDescriptions(parserName, api, file, options) {
|
|
|
150
199
|
visitedUrls
|
|
151
200
|
};
|
|
152
201
|
|
|
153
|
-
// determine which source descriptions to parse
|
|
202
|
+
// determine which source descriptions to parse (array filters by name)
|
|
154
203
|
const sourceDescriptionsOption = options?.parse?.parserOpts?.[parserName]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
|
|
155
|
-
|
|
156
|
-
// handle false or other falsy values - no source descriptions should be parsed
|
|
157
|
-
if (!sourceDescriptionsOption) {
|
|
158
|
-
return results;
|
|
159
|
-
}
|
|
160
204
|
const sourceDescriptions = Array.isArray(sourceDescriptionsOption) ? api.sourceDescriptions.filter(sd => {
|
|
161
205
|
if (!(0, _apidomNsArazzo.isSourceDescriptionElement)(sd)) return false;
|
|
162
206
|
const name = (0, _apidomCore.toValue)(sd.name);
|
|
@@ -166,6 +210,8 @@ async function parseSourceDescriptions(parserName, api, file, options) {
|
|
|
166
210
|
// process sequentially to ensure proper cycle detection with shared visitedUrls
|
|
167
211
|
for (const sourceDescription of sourceDescriptions) {
|
|
168
212
|
const sourceDescriptionParseResult = await parseSourceDescription(sourceDescription, ctx);
|
|
213
|
+
// always attach result (even on failure - contains annotations)
|
|
214
|
+
sourceDescription.meta.set('parseResult', sourceDescriptionParseResult);
|
|
169
215
|
results.push(sourceDescriptionParseResult);
|
|
170
216
|
}
|
|
171
217
|
return results;
|
|
@@ -4,6 +4,7 @@ import { isSwaggerElement } from '@speclynx/apidom-ns-openapi-2';
|
|
|
4
4
|
import { isOpenApi3_0Element } from '@speclynx/apidom-ns-openapi-3-0';
|
|
5
5
|
import { isOpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
|
|
6
6
|
import { toValue } from '@speclynx/apidom-core';
|
|
7
|
+
import File from "../../../File.mjs";
|
|
7
8
|
import * as url from "../../../util/url.mjs";
|
|
8
9
|
import { merge as mergeOptions } from "../../../options/util.mjs";
|
|
9
10
|
import parse from "../../index.mjs"; // shared key for recursion state (works across JSON/YAML parsers)
|
|
@@ -32,7 +33,9 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
32
33
|
parseResult.push(annotation);
|
|
33
34
|
return parseResult;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
// normalize URI for consistent cycle detection and cache key matching
|
|
38
|
+
const retrievalURI = url.sanitize(url.stripHash(url.resolve(ctx.baseURI, sourceDescriptionURI)));
|
|
36
39
|
|
|
37
40
|
// skip if already visited (cycle detection)
|
|
38
41
|
if (ctx.visitedUrls.has(retrievalURI)) {
|
|
@@ -43,11 +46,14 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
43
46
|
}
|
|
44
47
|
ctx.visitedUrls.add(retrievalURI);
|
|
45
48
|
try {
|
|
46
|
-
const
|
|
49
|
+
const sourceDescriptionParseResult = await parse(retrievalURI, mergeOptions(ctx.options, {
|
|
47
50
|
parse: {
|
|
48
51
|
mediaType: 'text/plain',
|
|
49
52
|
// allow parser plugin detection
|
|
50
53
|
parserOpts: {
|
|
54
|
+
// nested documents should parse all their source descriptions
|
|
55
|
+
// (parent's name filter doesn't apply to nested documents)
|
|
56
|
+
sourceDescriptions: true,
|
|
51
57
|
[ARAZZO_RECURSION_KEY]: {
|
|
52
58
|
sourceDescriptionsDepth: ctx.currentDepth + 1,
|
|
53
59
|
sourceDescriptionsVisitedUrls: ctx.visitedUrls
|
|
@@ -56,7 +62,7 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
56
62
|
}
|
|
57
63
|
}));
|
|
58
64
|
// merge parsed result into our parse result
|
|
59
|
-
for (const item of
|
|
65
|
+
for (const item of sourceDescriptionParseResult) {
|
|
60
66
|
parseResult.push(item);
|
|
61
67
|
}
|
|
62
68
|
} catch (error) {
|
|
@@ -98,10 +104,53 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
101
|
-
*
|
|
107
|
+
* Parses source descriptions from an Arazzo document's ParseResult.
|
|
108
|
+
*
|
|
109
|
+
* Each source description result is attached to its corresponding
|
|
110
|
+
* SourceDescriptionElement's meta as 'parseResult' for easy access,
|
|
111
|
+
* regardless of success or failure. On failure, the ParseResultElement
|
|
112
|
+
* contains annotations explaining what went wrong.
|
|
113
|
+
*
|
|
114
|
+
* @param parseResult - ParseResult containing an Arazzo specification
|
|
115
|
+
* @param parseResultRetrievalURI - URI from which the parseResult was retrieved
|
|
116
|
+
* @param options - Full ReferenceOptions. Pass `sourceDescriptions` as an array of names
|
|
117
|
+
* in `parse.parserOpts` to filter which source descriptions to process.
|
|
118
|
+
* @param parserName - Parser name for options lookup (defaults to 'arazzo-json-1')
|
|
119
|
+
* @returns Array of ParseResultElements. Returns one ParseResultElement per source description
|
|
120
|
+
* (each with class 'source-description' and name/type metadata).
|
|
121
|
+
* May return early with a single-element array containing a warning annotation when:
|
|
122
|
+
* - The API is not an Arazzo specification
|
|
123
|
+
* - The sourceDescriptions field is missing or not an array
|
|
124
|
+
* - Maximum parse depth is exceeded (error annotation)
|
|
125
|
+
* Returns an empty array when no source description names match the filter.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* import { options, mergeOptions } from '@speclynx/apidom-reference';
|
|
130
|
+
* import { parseSourceDescriptions } from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
131
|
+
*
|
|
132
|
+
* // Parse all source descriptions
|
|
133
|
+
* const results = await parseSourceDescriptions(parseResult, uri, options);
|
|
134
|
+
*
|
|
135
|
+
* // Filter by name
|
|
136
|
+
* const filtered = await parseSourceDescriptions(parseResult, uri, mergeOptions(options, {
|
|
137
|
+
* parse: { parserOpts: { sourceDescriptions: ['petStore'] } }
|
|
138
|
+
* }));
|
|
139
|
+
*
|
|
140
|
+
* // Access parsed document from source description element
|
|
141
|
+
* const sourceDesc = parseResult.api.sourceDescriptions.get(0);
|
|
142
|
+
* const parsedDoc = sourceDesc.meta.get('parseResult');
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
102
145
|
* @public
|
|
103
146
|
*/
|
|
104
|
-
export async function parseSourceDescriptions(
|
|
147
|
+
export async function parseSourceDescriptions(parseResult, parseResultRetrievalURI, options, parserName = 'arazzo-json-1') {
|
|
148
|
+
const {
|
|
149
|
+
api
|
|
150
|
+
} = parseResult;
|
|
151
|
+
const file = new File({
|
|
152
|
+
uri: url.sanitize(url.stripHash(parseResultRetrievalURI))
|
|
153
|
+
});
|
|
105
154
|
const results = [];
|
|
106
155
|
|
|
107
156
|
/**
|
|
@@ -143,13 +192,8 @@ export async function parseSourceDescriptions(parserName, api, file, options) {
|
|
|
143
192
|
visitedUrls
|
|
144
193
|
};
|
|
145
194
|
|
|
146
|
-
// determine which source descriptions to parse
|
|
195
|
+
// determine which source descriptions to parse (array filters by name)
|
|
147
196
|
const sourceDescriptionsOption = options?.parse?.parserOpts?.[parserName]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
|
|
148
|
-
|
|
149
|
-
// handle false or other falsy values - no source descriptions should be parsed
|
|
150
|
-
if (!sourceDescriptionsOption) {
|
|
151
|
-
return results;
|
|
152
|
-
}
|
|
153
197
|
const sourceDescriptions = Array.isArray(sourceDescriptionsOption) ? api.sourceDescriptions.filter(sd => {
|
|
154
198
|
if (!isSourceDescriptionElement(sd)) return false;
|
|
155
199
|
const name = toValue(sd.name);
|
|
@@ -159,6 +203,8 @@ export async function parseSourceDescriptions(parserName, api, file, options) {
|
|
|
159
203
|
// process sequentially to ensure proper cycle detection with shared visitedUrls
|
|
160
204
|
for (const sourceDescription of sourceDescriptions) {
|
|
161
205
|
const sourceDescriptionParseResult = await parseSourceDescription(sourceDescription, ctx);
|
|
206
|
+
// always attach result (even on failure - contains annotations)
|
|
207
|
+
sourceDescription.meta.set('parseResult', sourceDescriptionParseResult);
|
|
162
208
|
results.push(sourceDescriptionParseResult);
|
|
163
209
|
}
|
|
164
210
|
return results;
|
|
@@ -7,7 +7,8 @@ var _ramda = require("ramda");
|
|
|
7
7
|
var _apidomParserAdapterArazzoYaml = require("@speclynx/apidom-parser-adapter-arazzo-yaml-1");
|
|
8
8
|
var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
|
|
9
9
|
var _Parser = _interopRequireDefault(require("../Parser.cjs"));
|
|
10
|
-
var
|
|
10
|
+
var _sourceDescriptions = require("./source-descriptions.cjs");
|
|
11
|
+
exports.parseSourceDescriptions = _sourceDescriptions.parseSourceDescriptions;
|
|
11
12
|
/**
|
|
12
13
|
* @public
|
|
13
14
|
*/
|
|
@@ -47,7 +48,7 @@ class ArazzoYAML1Parser extends _Parser.default {
|
|
|
47
48
|
const parseResult = await (0, _apidomParserAdapterArazzoYaml.parse)(source, parserOpts);
|
|
48
49
|
const shouldParseSourceDescriptions = options?.parse?.parserOpts?.[this.name]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
|
|
49
50
|
if (shouldParseSourceDescriptions) {
|
|
50
|
-
const sourceDescriptions = await (0,
|
|
51
|
+
const sourceDescriptions = await (0, _sourceDescriptions.parseSourceDescriptions)(parseResult, file.uri, options, this.name);
|
|
51
52
|
parseResult.push(...sourceDescriptions);
|
|
52
53
|
}
|
|
53
54
|
return parseResult;
|
|
@@ -2,7 +2,7 @@ import { pick } from 'ramda';
|
|
|
2
2
|
import { parse, mediaTypes as ArazzoYAML1MediaTypes, detect } from '@speclynx/apidom-parser-adapter-arazzo-yaml-1';
|
|
3
3
|
import ParserError from "../../../errors/ParserError.mjs";
|
|
4
4
|
import Parser from "../Parser.mjs";
|
|
5
|
-
import { parseSourceDescriptions } from "
|
|
5
|
+
import { parseSourceDescriptions } from "./source-descriptions.mjs";
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
@@ -41,7 +41,7 @@ class ArazzoYAML1Parser extends Parser {
|
|
|
41
41
|
const parseResult = await parse(source, parserOpts);
|
|
42
42
|
const shouldParseSourceDescriptions = options?.parse?.parserOpts?.[this.name]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
|
|
43
43
|
if (shouldParseSourceDescriptions) {
|
|
44
|
-
const sourceDescriptions = await parseSourceDescriptions(
|
|
44
|
+
const sourceDescriptions = await parseSourceDescriptions(parseResult, file.uri, options, this.name);
|
|
45
45
|
parseResult.push(...sourceDescriptions);
|
|
46
46
|
}
|
|
47
47
|
return parseResult;
|
|
@@ -52,4 +52,5 @@ class ArazzoYAML1Parser extends Parser {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
export { parseSourceDescriptions } from "./source-descriptions.mjs";
|
|
55
56
|
export default ArazzoYAML1Parser;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.parseSourceDescriptions = void 0;
|
|
5
|
+
var _sourceDescriptions = require("../arazzo-json-1/source-descriptions.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const parseSourceDescriptions = (parseResult, parseResultRetrievalURI, options, parserName = 'arazzo-yaml-1') => {
|
|
10
|
+
return (0, _sourceDescriptions.parseSourceDescriptions)(parseResult, parseResultRetrievalURI, options, parserName);
|
|
11
|
+
};
|
|
12
|
+
exports.parseSourceDescriptions = parseSourceDescriptions;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { parseSourceDescriptions as parseSourceDescriptionsBase } from "../arazzo-json-1/source-descriptions.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export const parseSourceDescriptions = (parseResult, parseResultRetrievalURI, options, parserName = 'arazzo-yaml-1') => {
|
|
6
|
+
return parseSourceDescriptionsBase(parseResult, parseResultRetrievalURI, options, parserName);
|
|
7
|
+
};
|
|
@@ -29,4 +29,5 @@ declare class Arazzo1DereferenceStrategy extends DereferenceStrategy {
|
|
|
29
29
|
}
|
|
30
30
|
export { Arazzo1DereferenceVisitor };
|
|
31
31
|
export { resolveSchema$refField, resolveSchema$idField, maybeRefractToJSONSchemaElement, } from './util.ts';
|
|
32
|
+
export { dereferenceSourceDescriptions } from './source-descriptions.ts';
|
|
32
33
|
export default Arazzo1DereferenceStrategy;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Dereferences source descriptions from an Arazzo document.
|
|
5
|
+
*
|
|
6
|
+
* Each source description result is attached to its corresponding
|
|
7
|
+
* SourceDescriptionElement's meta as 'parseResult' for easy access,
|
|
8
|
+
* regardless of success or failure. On failure, the ParseResultElement
|
|
9
|
+
* contains annotations explaining what went wrong.
|
|
10
|
+
*
|
|
11
|
+
* @param parseResult - ParseResult containing a parsed (optionally dereferenced) Arazzo specification
|
|
12
|
+
* @param parseResultRetrievalURI - URI from which the parseResult was retrieved
|
|
13
|
+
* @param options - Full ReferenceOptions. Pass `sourceDescriptions` as an array of names
|
|
14
|
+
* in `dereference.strategyOpts` to filter which source descriptions to process.
|
|
15
|
+
* @param strategyName - Strategy name for options lookup (defaults to 'arazzo-1')
|
|
16
|
+
* @returns Array of ParseResultElements. Returns one ParseResultElement per source description
|
|
17
|
+
* (each with class 'source-description' and name/type metadata).
|
|
18
|
+
* May return early with a single-element array containing a warning annotation when:
|
|
19
|
+
* - The API is not an Arazzo specification
|
|
20
|
+
* - The sourceDescriptions field is missing or not an array
|
|
21
|
+
* - Maximum dereference depth is exceeded (error annotation)
|
|
22
|
+
* Returns an empty array when no source description names match the filter.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Dereference all source descriptions
|
|
27
|
+
* await dereferenceSourceDescriptions(parseResult, uri, options);
|
|
28
|
+
*
|
|
29
|
+
* // Filter by name
|
|
30
|
+
* await dereferenceSourceDescriptions(parseResult, uri, mergeOptions(options, {
|
|
31
|
+
* dereference: { strategyOpts: { sourceDescriptions: ['petStore'] } },
|
|
32
|
+
* }));
|
|
33
|
+
*
|
|
34
|
+
* // Access dereferenced document from source description element
|
|
35
|
+
* const sourceDesc = parseResult.api.sourceDescriptions.get(0);
|
|
36
|
+
* const dereferencedDoc = sourceDesc.meta.get('parseResult');
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare function dereferenceSourceDescriptions(parseResult: ParseResultElement, parseResultRetrievalURI: string, options: ReferenceOptions, strategyName?: string): Promise<ParseResultElement[]>;
|
|
@@ -18,4 +18,5 @@ declare class ArazzoJSON1Parser extends Parser {
|
|
|
18
18
|
canParse(file: File): Promise<boolean>;
|
|
19
19
|
parse(file: File, options?: ReferenceOptions): Promise<ParseResultElement>;
|
|
20
20
|
}
|
|
21
|
+
export { parseSourceDescriptions } from './source-descriptions.ts';
|
|
21
22
|
export default ArazzoJSON1Parser;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Parses source descriptions from an Arazzo document's ParseResult.
|
|
5
|
+
*
|
|
6
|
+
* Each source description result is attached to its corresponding
|
|
7
|
+
* SourceDescriptionElement's meta as 'parseResult' for easy access,
|
|
8
|
+
* regardless of success or failure. On failure, the ParseResultElement
|
|
9
|
+
* contains annotations explaining what went wrong.
|
|
10
|
+
*
|
|
11
|
+
* @param parseResult - ParseResult containing an Arazzo specification
|
|
12
|
+
* @param parseResultRetrievalURI - URI from which the parseResult was retrieved
|
|
13
|
+
* @param options - Full ReferenceOptions. Pass `sourceDescriptions` as an array of names
|
|
14
|
+
* in `parse.parserOpts` to filter which source descriptions to process.
|
|
15
|
+
* @param parserName - Parser name for options lookup (defaults to 'arazzo-json-1')
|
|
16
|
+
* @returns Array of ParseResultElements. Returns one ParseResultElement per source description
|
|
17
|
+
* (each with class 'source-description' and name/type metadata).
|
|
18
|
+
* May return early with a single-element array containing a warning annotation when:
|
|
19
|
+
* - The API is not an Arazzo specification
|
|
20
|
+
* - The sourceDescriptions field is missing or not an array
|
|
21
|
+
* - Maximum parse depth is exceeded (error annotation)
|
|
22
|
+
* Returns an empty array when no source description names match the filter.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { options, mergeOptions } from '@speclynx/apidom-reference';
|
|
27
|
+
* import { parseSourceDescriptions } from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
28
|
+
*
|
|
29
|
+
* // Parse all source descriptions
|
|
30
|
+
* const results = await parseSourceDescriptions(parseResult, uri, options);
|
|
31
|
+
*
|
|
32
|
+
* // Filter by name
|
|
33
|
+
* const filtered = await parseSourceDescriptions(parseResult, uri, mergeOptions(options, {
|
|
34
|
+
* parse: { parserOpts: { sourceDescriptions: ['petStore'] } }
|
|
35
|
+
* }));
|
|
36
|
+
*
|
|
37
|
+
* // Access parsed document from source description element
|
|
38
|
+
* const sourceDesc = parseResult.api.sourceDescriptions.get(0);
|
|
39
|
+
* const parsedDoc = sourceDesc.meta.get('parseResult');
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseSourceDescriptions(parseResult: ParseResultElement, parseResultRetrievalURI: string, options: ReferenceOptions, parserName?: string): Promise<ParseResultElement[]>;
|
|
@@ -18,4 +18,5 @@ declare class ArazzoYAML1Parser extends Parser {
|
|
|
18
18
|
canParse(file: File): Promise<boolean>;
|
|
19
19
|
parse(file: File, options?: ReferenceOptions): Promise<ParseResultElement>;
|
|
20
20
|
}
|
|
21
|
+
export { parseSourceDescriptions } from './source-descriptions.ts';
|
|
21
22
|
export default ArazzoYAML1Parser;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare const parseSourceDescriptions: (parseResult: ParseResultElement, parseResultRetrievalURI: string, options: ReferenceOptions, parserName?: string) => Promise<ParseResultElement[]>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
-
import Reference from '../../../Reference.ts';
|
|
3
|
-
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
4
|
-
/**
|
|
5
|
-
* Dereferences source descriptions from an Arazzo document.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export declare function dereferenceSourceDescriptions(parseResult: ParseResultElement, reference: Reference, options: ReferenceOptions): Promise<ParseResultElement[]>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Element, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
-
import File from '../../../File.ts';
|
|
3
|
-
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
4
|
-
/**
|
|
5
|
-
* Shared function for parsing source descriptions.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export declare function parseSourceDescriptions(parserName: string, api: Element | undefined, file: File, options: ReferenceOptions): Promise<ParseResultElement[]>;
|