1+ import requests
2+ from typing import List ,Optional
3+ from sdk .models import shared , operations
4+ from . import utils
5+
6+ class APIEndpoints :
7+ _client : requests .Session
8+ _security_client : requests .Session
9+ _server_url : str
10+ _language : str
11+ _sdk_version : str
12+ _gen_version : str
13+
14+ def __init__ (self , client : requests .Session , security_client : requests .Session , server_url : str , language : str , sdk_version : str , gen_version : str ) -> None :
15+ self ._client = client
16+ self ._security_client = security_client
17+ self ._server_url = server_url
18+ self ._language = language
19+ self ._sdk_version = sdk_version
20+ self ._gen_version = gen_version
21+
22+
23+ def delete_api_endpoint (self , request : operations .DeleteAPIEndpointRequest ) -> operations .DeleteAPIEndpointResponse :
24+ r"""Delete an ApiEndpoint.
25+ Delete an ApiEndpoint. This will also delete all associated Request Logs (if using a Postgres datastore).
26+ """
27+
28+ base_url = self ._server_url
29+
30+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID}" , request .path_params )
31+
32+
33+ client = self ._security_client
34+
35+ r = client .request ("DELETE" , url )
36+ content_type = r .headers .get ("Content-Type" )
37+
38+ res = operations .DeleteAPIEndpointResponse (status_code = r .status_code , content_type = content_type )
39+
40+ if r .status_code == 200 :
41+ pass
42+ else :
43+ if utils .match_content_type (content_type , "application/json" ):
44+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
45+ res .error = out
46+
47+ return res
48+
49+
50+ def find_api_endpoint (self , request : operations .FindAPIEndpointRequest ) -> operations .FindAPIEndpointResponse :
51+ r"""Find an ApiEndpoint via its displayName.
52+ Find an ApiEndpoint via its displayName (set by operationId from a registered OpenAPI schema).
53+ This is useful for finding the ID of an ApiEndpoint to use in the /v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID} endpoints.
54+ """
55+
56+ base_url = self ._server_url
57+
58+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints/find/{displayName}" , request .path_params )
59+
60+
61+ client = self ._security_client
62+
63+ r = client .request ("GET" , url )
64+ content_type = r .headers .get ("Content-Type" )
65+
66+ res = operations .FindAPIEndpointResponse (status_code = r .status_code , content_type = content_type )
67+
68+ if r .status_code == 200 :
69+ if utils .match_content_type (content_type , "application/json" ):
70+ out = utils .unmarshal_json (r .text , Optional [shared .APIEndpoint ])
71+ res .api_endpoint = out
72+ else :
73+ if utils .match_content_type (content_type , "application/json" ):
74+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
75+ res .error = out
76+
77+ return res
78+
79+
80+ def generate_open_api_spec_for_api_endpoint (self , request : operations .GenerateOpenAPISpecForAPIEndpointRequest ) -> operations .GenerateOpenAPISpecForAPIEndpointResponse :
81+ r"""Generate an OpenAPI specification for a particular ApiEndpoint.
82+ This endpoint will generate a new operation in any registered OpenAPI document if the operation does not already exist in the document.
83+ Returns the original document and the newly generated document allowing a diff to be performed to see what has changed.
84+ """
85+
86+ base_url = self ._server_url
87+
88+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID}/generate/openapi" , request .path_params )
89+
90+
91+ client = self ._security_client
92+
93+ r = client .request ("GET" , url )
94+ content_type = r .headers .get ("Content-Type" )
95+
96+ res = operations .GenerateOpenAPISpecForAPIEndpointResponse (status_code = r .status_code , content_type = content_type )
97+
98+ if r .status_code == 200 :
99+ if utils .match_content_type (content_type , "application/json" ):
100+ out = utils .unmarshal_json (r .text , Optional [shared .GenerateOpenAPISpecDiff ])
101+ res .generate_open_api_spec_diff = out
102+ else :
103+ if utils .match_content_type (content_type , "application/json" ):
104+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
105+ res .error = out
106+
107+ return res
108+
109+
110+ def generate_postman_collection_for_api_endpoint (self , request : operations .GeneratePostmanCollectionForAPIEndpointRequest ) -> operations .GeneratePostmanCollectionForAPIEndpointResponse :
111+ r"""Generate a Postman collection for a particular ApiEndpoint.
112+ Generates a postman collection that allows the endpoint to be called from postman variables produced for any path/query/header parameters included in the OpenAPI document.
113+ """
114+
115+ base_url = self ._server_url
116+
117+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID}/generate/postman" , request .path_params )
118+
119+
120+ client = self ._security_client
121+
122+ r = client .request ("GET" , url )
123+ content_type = r .headers .get ("Content-Type" )
124+
125+ res = operations .GeneratePostmanCollectionForAPIEndpointResponse (status_code = r .status_code , content_type = content_type )
126+
127+ if r .status_code == 200 :
128+ if utils .match_content_type (content_type , "application/json" ):
129+ out = utils .unmarshal_json (r .text , Optional [bytes ])
130+ res .postman_collection = out
131+ else :
132+ if utils .match_content_type (content_type , "application/json" ):
133+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
134+ res .error = out
135+
136+ return res
137+
138+
139+ def get_all_api_endpoints (self , request : operations .GetAllAPIEndpointsRequest ) -> operations .GetAllAPIEndpointsResponse :
140+ r"""Get all Api endpoints for a particular apiID.
141+ """
142+
143+ base_url = self ._server_url
144+
145+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/api_endpoints" , request .path_params )
146+
147+
148+ client = self ._security_client
149+
150+ r = client .request ("GET" , url )
151+ content_type = r .headers .get ("Content-Type" )
152+
153+ res = operations .GetAllAPIEndpointsResponse (status_code = r .status_code , content_type = content_type )
154+
155+ if r .status_code == 200 :
156+ if utils .match_content_type (content_type , "application/json" ):
157+ out = utils .unmarshal_json (r .text , Optional [List [shared .APIEndpoint ]])
158+ res .api_endpoints = out
159+ else :
160+ if utils .match_content_type (content_type , "application/json" ):
161+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
162+ res .error = out
163+
164+ return res
165+
166+
167+ def get_all_for_version_api_endpoints (self , request : operations .GetAllForVersionAPIEndpointsRequest ) -> operations .GetAllForVersionAPIEndpointsResponse :
168+ r"""Get all ApiEndpoints for a particular apiID and versionID.
169+ """
170+
171+ base_url = self ._server_url
172+
173+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints" , request .path_params )
174+
175+
176+ client = self ._security_client
177+
178+ r = client .request ("GET" , url )
179+ content_type = r .headers .get ("Content-Type" )
180+
181+ res = operations .GetAllForVersionAPIEndpointsResponse (status_code = r .status_code , content_type = content_type )
182+
183+ if r .status_code == 200 :
184+ if utils .match_content_type (content_type , "application/json" ):
185+ out = utils .unmarshal_json (r .text , Optional [List [shared .APIEndpoint ]])
186+ res .api_endpoints = out
187+ else :
188+ if utils .match_content_type (content_type , "application/json" ):
189+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
190+ res .error = out
191+
192+ return res
193+
194+
195+ def get_api_endpoint (self , request : operations .GetAPIEndpointRequest ) -> operations .GetAPIEndpointResponse :
196+ r"""Get an ApiEndpoint.
197+ """
198+
199+ base_url = self ._server_url
200+
201+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID}" , request .path_params )
202+
203+
204+ client = self ._security_client
205+
206+ r = client .request ("GET" , url )
207+ content_type = r .headers .get ("Content-Type" )
208+
209+ res = operations .GetAPIEndpointResponse (status_code = r .status_code , content_type = content_type )
210+
211+ if r .status_code == 200 :
212+ if utils .match_content_type (content_type , "application/json" ):
213+ out = utils .unmarshal_json (r .text , Optional [shared .APIEndpoint ])
214+ res .api_endpoint = out
215+ else :
216+ if utils .match_content_type (content_type , "application/json" ):
217+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
218+ res .error = out
219+
220+ return res
221+
222+
223+ def upsert_api_endpoint (self , request : operations .UpsertAPIEndpointRequest ) -> operations .UpsertAPIEndpointResponse :
224+ r"""Upsert an ApiEndpoint.
225+ Upsert an ApiEndpoint. If the ApiEndpoint does not exist it will be created, otherwise it will be updated.
226+ """
227+
228+ base_url = self ._server_url
229+
230+ url = utils .generate_url (base_url , "/v1/apis/{apiID}/version/{versionID}/api_endpoints/{apiEndpointID}" , request .path_params )
231+
232+ headers = {}
233+ req_content_type , data , form = utils .serialize_request_body (request )
234+ if req_content_type != "multipart/form-data" and req_content_type != "multipart/mixed" :
235+ headers ["content-type" ] = req_content_type
236+ if data is None and form is None :
237+ raise Exception ('request body is required' )
238+
239+ client = self ._security_client
240+
241+ r = client .request ("PUT" , url , data = data , files = form , headers = headers )
242+ content_type = r .headers .get ("Content-Type" )
243+
244+ res = operations .UpsertAPIEndpointResponse (status_code = r .status_code , content_type = content_type )
245+
246+ if r .status_code == 200 :
247+ if utils .match_content_type (content_type , "application/json" ):
248+ out = utils .unmarshal_json (r .text , Optional [shared .APIEndpoint ])
249+ res .api_endpoint = out
250+ else :
251+ if utils .match_content_type (content_type , "application/json" ):
252+ out = utils .unmarshal_json (r .text , Optional [shared .Error ])
253+ res .error = out
254+
255+ return res
256+
257+
0 commit comments