๐Ÿ“ฆ directus / docs

๐Ÿ“„ derefOperations.ts ยท 24 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24import type { OpenAPIObject, OperationObject, ParameterObject } from 'openapi3-ts/oas30';

/**
 * Deref $ref properties in OAS paths
 *
 * @param spec - Full OAS spec
 * @param operations - Operations to deref
 */

export default function<O extends OperationObject>(spec: OpenAPIObject, operations: O[]): (O & { parameters: ParameterObject[] })[] {
	return operations.map((operation) => {
		return {
			...operation,
			parameters: operation.parameters?.map((part) => {
				if ('$ref' in part) {
					return resolveOasRef<ParameterObject>(spec, part.$ref);
				}

				return part;
			}).filter(part => part !== null) ?? [],
		};
	});
}