add pat and service user docs + remove empty lines from examples

This commit is contained in:
Pascal Fischer
2023-05-08 18:46:40 +02:00
parent c20cecf972
commit 4c51e12888
26 changed files with 946 additions and 1187 deletions

View File

@@ -62,13 +62,13 @@ export const title = '<%- tag %>'
<Col sticky>
<CodeGroup title="Request" tag="<%- operation.operation.toUpperCase() %>" label="<%- operation.path %>">
\`\`\`bash {{ title: 'cURL' }}
<% if(true){ -%>
curl -X <%- operation.operation.toUpperCase() %> <%- operation.fullPath %> \\
-H "Authorization: Token <TOKEN>" \\
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>
-H 'Accept: application/json' \\<% }; %>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>
-H 'Content-Type: application/json' \\
--data-raw '<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) %>'<% }; %>
-H "Authorization: Token <TOKEN>" \\<% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
-H 'Accept: application/json' \\<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
-H 'Content-Type: application/json' \\\n--data-raw '<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) -%>'<% }; %>
\`\`\`
\`\`\`js
@@ -80,11 +80,13 @@ let config = {
method: '<%- operation.operation.toLowerCase() %>',
maxBodyLength: Infinity,
url: '<%- operation.path %>',
headers: {
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>'Content-Type': 'application/json',<% }; %>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>'Accept': 'application/json',<% }; %>
<% if(true){%>headers: { <% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
'Accept': 'application/json',<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
'Content-Type': 'application/json',<% }; %>
'Authorization': 'Token <TOKEN>'
}<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>,<% }; %>
<% if(true){ -%>}<% }; -%><% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>,<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
data : data<% }; %>
};
@@ -106,9 +108,11 @@ url = "<%- operation.fullPath %>"
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>
payload = json.dumps(<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) %>)<% }; -%>
headers = {
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>'Content-Type': 'application/json',<% }; %>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>'Accept': 'application/json',<% }; %>
<% if(true){%>headers: { <% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
'Content-Type': 'application/json',<% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
'Accept': 'application/json',<% }; %>
'Authorization': 'Token <TOKEN>'
}
@@ -141,10 +145,12 @@ func main() {
if err != nil {
fmt.Println(err)
return
}
<% if(true){%>{<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>req.Header.Add("Content-Type", "application/json")<% }; %>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>req.Header.Add("Accept", "application/json")<% }; %>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
req.Header.Add("Content-Type", "application/json")<% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
req.Header.Add("Accept", "application/json")<% }; %>
req.Header.Add("Authorization", "Token <TOKEN>")
res, err := client.Do(req)
@@ -173,9 +179,11 @@ url = URI("<%- operation.fullPath %>")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::<%- operation.operation.slice(0,1).toUpperCase() + operation.operation.slice(1).toLowerCase()%>.new(url)
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>request["Content-Type"] = "application/json"<% }; %>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>request["Accept"] = "application/json"<% }; %>
<% if(true){ %>request = Net::HTTP::<%- operation.operation.slice(0,1).toUpperCase() + operation.operation.slice(1).toLowerCase()%>.new(url)<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
request["Content-Type"] = "application/json"<% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
request["Accept"] = "application/json"<% }; %>
request["Authorization"] = "Token <TOKEN>"
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
request.body = JSON.dump(<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) %>)<% }; -%>
@@ -192,9 +200,11 @@ MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, '<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) %>');<% }; %>
Request request = new Request.Builder()
.url("<%- operation.fullPath %>")
.method("<%- operation.operation.toUpperCase() %>"<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>, body<% }; %>)
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>.addHeader("Content-Type", "application/json")<% }; %>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>.addHeader("Accept", "application/json")<% }; %>
<% if(true){ %>.method("<%- operation.operation.toUpperCase() %>"<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>, body<% }; %>)<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
.addHeader("Content-Type", "application/json")<% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
.addHeader("Accept", "application/json")<% }; %>
.addHeader("Authorization: Token <TOKEN>")
.build();
Response response = client.newCall(request).execute();
@@ -213,12 +223,14 @@ curl_setopt_array($curl, array(
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => '<%- operation.operation.toUpperCase() %>',
<% if(true){ %>CURLOPT_CUSTOMREQUEST => '<%- operation.operation.toUpperCase() %>',<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
CURLOPT_POSTFIELDS =>'<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) %>',<% }; %>
CURLOPT_HTTPHEADER => array(
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>'Content-Type: application/json',<% }; %>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>'Accept: application/json',<% }; %>
CURLOPT_POSTFIELDS => '<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) %>',<% }; %>
<% if(true){ %>CURLOPT_HTTPHEADER => array(<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
'Content-Type: application/json',<% }; -%>
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ %>
'Accept: application/json',<% }; %>
'Authorization: Token <TOKEN>'
),
));