@speclynx/apidom-reference 2.8.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 +8 -0
- package/README.md +197 -0
- package/dist/apidom-reference.browser.js +160 -77
- 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/source-descriptions.cjs +30 -15
- package/src/parse/parsers/arazzo-json-1/source-descriptions.mjs +30 -15
- 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/source-descriptions.d.ts +21 -8
- package/types/dereference/strategies/arazzo-1/source-description.d.ts +0 -8
|
@@ -33,7 +33,9 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
33
33
|
parseResult.push(annotation);
|
|
34
34
|
return parseResult;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
// normalize URI for consistent cycle detection and cache key matching
|
|
38
|
+
const retrievalURI = url.sanitize(url.stripHash(url.resolve(ctx.baseURI, sourceDescriptionURI)));
|
|
37
39
|
|
|
38
40
|
// skip if already visited (cycle detection)
|
|
39
41
|
if (ctx.visitedUrls.has(retrievalURI)) {
|
|
@@ -49,6 +51,9 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
49
51
|
mediaType: 'text/plain',
|
|
50
52
|
// allow parser plugin detection
|
|
51
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,
|
|
52
57
|
[ARAZZO_RECURSION_KEY]: {
|
|
53
58
|
sourceDescriptionsDepth: ctx.currentDepth + 1,
|
|
54
59
|
sourceDescriptionsVisitedUrls: ctx.visitedUrls
|
|
@@ -101,27 +106,40 @@ async function parseSourceDescription(sourceDescription, ctx) {
|
|
|
101
106
|
/**
|
|
102
107
|
* Parses source descriptions from an Arazzo document's ParseResult.
|
|
103
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
|
+
*
|
|
104
114
|
* @param parseResult - ParseResult containing an Arazzo specification
|
|
105
115
|
* @param parseResultRetrievalURI - URI from which the parseResult was retrieved
|
|
106
|
-
* @param options - Full ReferenceOptions
|
|
116
|
+
* @param options - Full ReferenceOptions. Pass `sourceDescriptions` as an array of names
|
|
117
|
+
* in `parse.parserOpts` to filter which source descriptions to process.
|
|
107
118
|
* @param parserName - Parser name for options lookup (defaults to 'arazzo-json-1')
|
|
108
|
-
* @returns Array of ParseResultElements.
|
|
109
|
-
*
|
|
119
|
+
* @returns Array of ParseResultElements. Returns one ParseResultElement per source description
|
|
120
|
+
* (each with class 'source-description' and name/type metadata).
|
|
110
121
|
* May return early with a single-element array containing a warning annotation when:
|
|
111
122
|
* - The API is not an Arazzo specification
|
|
112
123
|
* - The sourceDescriptions field is missing or not an array
|
|
113
124
|
* - Maximum parse depth is exceeded (error annotation)
|
|
114
|
-
* Returns an empty array when
|
|
125
|
+
* Returns an empty array when no source description names match the filter.
|
|
115
126
|
*
|
|
116
127
|
* @example
|
|
117
128
|
* ```typescript
|
|
118
129
|
* import { options, mergeOptions } from '@speclynx/apidom-reference';
|
|
119
130
|
* import { parseSourceDescriptions } from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
120
131
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
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');
|
|
125
143
|
* ```
|
|
126
144
|
*
|
|
127
145
|
* @public
|
|
@@ -174,13 +192,8 @@ export async function parseSourceDescriptions(parseResult, parseResultRetrievalU
|
|
|
174
192
|
visitedUrls
|
|
175
193
|
};
|
|
176
194
|
|
|
177
|
-
// determine which source descriptions to parse
|
|
195
|
+
// determine which source descriptions to parse (array filters by name)
|
|
178
196
|
const sourceDescriptionsOption = options?.parse?.parserOpts?.[parserName]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
|
|
179
|
-
|
|
180
|
-
// handle false or other falsy values - no source descriptions should be parsed
|
|
181
|
-
if (!sourceDescriptionsOption) {
|
|
182
|
-
return results;
|
|
183
|
-
}
|
|
184
197
|
const sourceDescriptions = Array.isArray(sourceDescriptionsOption) ? api.sourceDescriptions.filter(sd => {
|
|
185
198
|
if (!isSourceDescriptionElement(sd)) return false;
|
|
186
199
|
const name = toValue(sd.name);
|
|
@@ -190,6 +203,8 @@ export async function parseSourceDescriptions(parseResult, parseResultRetrievalU
|
|
|
190
203
|
// process sequentially to ensure proper cycle detection with shared visitedUrls
|
|
191
204
|
for (const sourceDescription of sourceDescriptions) {
|
|
192
205
|
const sourceDescriptionParseResult = await parseSourceDescription(sourceDescription, ctx);
|
|
206
|
+
// always attach result (even on failure - contains annotations)
|
|
207
|
+
sourceDescription.meta.set('parseResult', sourceDescriptionParseResult);
|
|
193
208
|
results.push(sourceDescriptionParseResult);
|
|
194
209
|
}
|
|
195
210
|
return results;
|
|
@@ -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[]>;
|
|
@@ -3,27 +3,40 @@ import type { ReferenceOptions } from '../../../options/index.ts';
|
|
|
3
3
|
/**
|
|
4
4
|
* Parses source descriptions from an Arazzo document's ParseResult.
|
|
5
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
|
+
*
|
|
6
11
|
* @param parseResult - ParseResult containing an Arazzo specification
|
|
7
12
|
* @param parseResultRetrievalURI - URI from which the parseResult was retrieved
|
|
8
|
-
* @param options - Full ReferenceOptions
|
|
13
|
+
* @param options - Full ReferenceOptions. Pass `sourceDescriptions` as an array of names
|
|
14
|
+
* in `parse.parserOpts` to filter which source descriptions to process.
|
|
9
15
|
* @param parserName - Parser name for options lookup (defaults to 'arazzo-json-1')
|
|
10
|
-
* @returns Array of ParseResultElements.
|
|
11
|
-
*
|
|
16
|
+
* @returns Array of ParseResultElements. Returns one ParseResultElement per source description
|
|
17
|
+
* (each with class 'source-description' and name/type metadata).
|
|
12
18
|
* May return early with a single-element array containing a warning annotation when:
|
|
13
19
|
* - The API is not an Arazzo specification
|
|
14
20
|
* - The sourceDescriptions field is missing or not an array
|
|
15
21
|
* - Maximum parse depth is exceeded (error annotation)
|
|
16
|
-
* Returns an empty array when
|
|
22
|
+
* Returns an empty array when no source description names match the filter.
|
|
17
23
|
*
|
|
18
24
|
* @example
|
|
19
25
|
* ```typescript
|
|
20
26
|
* import { options, mergeOptions } from '@speclynx/apidom-reference';
|
|
21
27
|
* import { parseSourceDescriptions } from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
22
28
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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');
|
|
27
40
|
* ```
|
|
28
41
|
*
|
|
29
42
|
* @public
|
|
@@ -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[]>;
|