MCPcopy
hub / github.com/AndrewWalsh/openapi-devtools / endpointsToOAI31

Function endpointsToOAI31

src/lib/endpoints-to-oai31.ts:24–108  ·  view source on GitHub ↗
(
  endpoints: Array<Endpoint>,
  options: Options = defaultOptions,
)

Source from the content-addressed store, hash-verified

22import { AuthTypeString, Endpoint } from "../utils/types.js";
23
24const endpointsToOAI31 = (
25 endpoints: Array<Endpoint>,
26 options: Options = defaultOptions,
27): OpenApiBuilder => {
28 const builder = createBuilderAndDocRoot(endpoints);
29 const uniqueHosts = new Set<string>();
30 const uniqueAuth = new Map<AuthTypeString, SecuritySchemeObject>();
31
32 for (const endpoint of endpoints) {
33 const fullPath = `/${endpoint.parts.map((p) => p.part).join("/")}`;
34 const pathParameterObjects = createPathParameterTypes(endpoint);
35 uniqueHosts.add(endpoint.host);
36
37 const auth = endpoint.data.authentication;
38 if (auth) {
39 Object.values(auth).forEach((value) => {
40 const securitySchema = createSecuritySchemeTypes(value);
41 if (securitySchema) {
42 uniqueAuth.set(formatAuthType(value.authType), securitySchema);
43 }
44 });
45 }
46
47 for (const method of Object.keys(endpoint.data.methods)) {
48 const methodLower = method.toLowerCase();
49 const endpointMethod = endpoint.data.methods[method]!;
50 const queryParameterObjects = createQueryParameterTypes(
51 endpointMethod.queryParameters,
52 );
53 const requestBody = createRequestTypes(endpointMethod.request, options);
54 const responses = createResponseTypes(
55 endpointMethod.response,
56 endpointMethod.responseHeaders,
57 options,
58 );
59 const security: SecurityRequirementObject[] = [];
60 if (!isEmpty(endpoint.data.authentication)) {
61 Object.values(endpoint.data.authentication).forEach((value) => {
62 security.push({ [formatAuthType(value.authType)]: [] });
63 });
64 }
65 const operation: OperationObject = {
66 summary: fullPath,
67 description: `**Host**: http://${endpoint.host}`,
68 responses,
69 ...(security && { security }),
70 };
71 const allParameterObjects = [
72 ...pathParameterObjects,
73 ...queryParameterObjects,
74 ];
75 if (allParameterObjects.length) {
76 operation.parameters = allParameterObjects;
77 }
78 if (requestBody && shouldIncludeRequestBody(method)) {
79 operation.requestBody = requestBody;
80 }
81 // The method (e.g. get) and the operation on it

Callers 2

MainFunction · 0.85

Calls 8

createBuilderAndDocRootFunction · 0.85
createPathParameterTypesFunction · 0.85
formatAuthTypeFunction · 0.85
createRequestTypesFunction · 0.85
createResponseTypesFunction · 0.85
shouldIncludeRequestBodyFunction · 0.85

Tested by

no test coverage detected