-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapiEndpointsGenerateOpenApiSpecForApiEndpoint.ts
141 lines (131 loc) · 3.93 KB
/
apiEndpointsGenerateOpenApiSpecForApiEndpoint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import { SpeakeasyCore } from "../core.js";
import { encodeSimple } from "../lib/encodings.js";
import * as M from "../lib/matchers.js";
import { safeParse } from "../lib/schemas.js";
import { RequestOptions } from "../lib/sdks.js";
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
import { pathToFunc } from "../lib/url.js";
import {
ConnectionError,
InvalidRequestError,
RequestAbortedError,
RequestTimeoutError,
UnexpectedClientError,
} from "../sdk/models/errors/httpclienterrors.js";
import { SDKError } from "../sdk/models/errors/sdkerror.js";
import { SDKValidationError } from "../sdk/models/errors/sdkvalidationerror.js";
import * as operations from "../sdk/models/operations/index.js";
import { Result } from "../sdk/types/fp.js";
/**
* Generate an OpenAPI specification for a particular ApiEndpoint.
*
* @remarks
* This endpoint will generate a new operation in any registered OpenAPI document if the operation does not already exist in the document.
* Returns the original document and the newly generated document allowing a diff to be performed to see what has changed.
*/
export async function apiEndpointsGenerateOpenApiSpecForApiEndpoint(
client: SpeakeasyCore,
request: operations.GenerateOpenApiSpecForApiEndpointRequest,
options?: RequestOptions,
): Promise<
Result<
operations.GenerateOpenApiSpecForApiEndpointResponse,
| SDKError
| SDKValidationError
| UnexpectedClientError
| InvalidRequestError
| RequestAbortedError
| RequestTimeoutError
| ConnectionError
>
> {
const parsed = safeParse(
request,
(value) =>
operations.GenerateOpenApiSpecForApiEndpointRequest$outboundSchema.parse(
value,
),
"Input validation failed",
);
if (!parsed.ok) {
return parsed;
}
const payload = parsed.value;
const body = null;
const pathParams = {
apiEndpointID: encodeSimple("apiEndpointID", payload.apiEndpointID, {
explode: false,
charEncoding: "percent",
}),
apiID: encodeSimple("apiID", payload.apiID, {
explode: false,
charEncoding: "percent",
}),
versionID: encodeSimple("versionID", payload.versionID, {
explode: false,
charEncoding: "percent",
}),
};
const path = pathToFunc(
"/v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID}/generate/openapi",
)(pathParams);
const headers = new Headers({
Accept: "application/json",
});
const securityInput = await extractSecurity(client._options.security);
const context = {
operationID: "generateOpenApiSpecForApiEndpoint",
oAuth2Scopes: [],
securitySource: client._options.security,
};
const requestSecurity = resolveGlobalSecurity(securityInput);
const requestRes = client._createRequest(context, {
security: requestSecurity,
method: "GET",
path: path,
headers: headers,
body: body,
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
}, options);
if (!requestRes.ok) {
return requestRes;
}
const req = requestRes.value;
const doResult = await client._do(req, {
context,
errorCodes: [],
retryConfig: options?.retries
|| client._options.retryConfig,
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
});
if (!doResult.ok) {
return doResult;
}
const response = doResult.value;
const [result] = await M.match<
operations.GenerateOpenApiSpecForApiEndpointResponse,
| SDKError
| SDKValidationError
| UnexpectedClientError
| InvalidRequestError
| RequestAbortedError
| RequestTimeoutError
| ConnectionError
>(
M.json(
"2XX",
operations.GenerateOpenApiSpecForApiEndpointResponse$inboundSchema,
),
M.json(
"4XX",
operations.GenerateOpenApiSpecForApiEndpointResponse$inboundSchema,
),
)(response);
if (!result.ok) {
return result;
}
return result;
}