Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .generator/templates/api_doc.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# {{projectName}}.{{moduleName}}.{{classname}}{{#description}}

{{description}}{{/description}}

All URIs are relative to *{{basePath}}*

Method | HTTP request | Description
------------- | ------------- | -------------
{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}

{{#operations}}
{{#operation}}
## **{{{operationId}}}**
> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#requiredParams}}{{^defaultValue}}{{paramName}}{{^-last}}, {{/-last}}{{/defaultValue}}{{/requiredParams}})

{{#notes}}
{{{notes}}}
{{/notes}}

### Example


```typescript
import { {{{moduleName}}} } from '{{{projectName}}}';
import * as fs from 'fs';

const configuration = {{{moduleName}}}.createConfiguration();
const apiInstance = new {{{moduleName}}}.{{classname}}(configuration);

{{#hasParams}}
let body:{{{moduleName}}}.{{classname}}{{operationIdCamelCase}}Request = {
{{#allParams}}
// {{{dataType}}}{{#description}} | {{{description}}}{{/description}}{{^required}} (optional){{/required}}
{{paramName}}: {{{example}}},
{{/allParams}}
};
{{/hasParams}}
{{^hasParams}}
let body:any = {};
{{/hasParams}}

apiInstance.{{{operationId}}}(body).then((data:any) => {
console.log('API called successfully. Returned data: ' + data);
}).catch((error:any) => console.error(error));
```


### Parameters
{{^hasParams}}This endpoint does not need any parameter.{{/hasParams}}{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
{{#allParams}}{{^defaultValue}} **{{paramName}}** | {{^isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}| {{description}} |
{{/defaultValue}}{{/allParams}}{{#allParams}}{{#defaultValue}} **{{paramName}}** | {{^isPrimitiveType}}{{^isEnum}}**{{dataType}}**{{/isEnum}}{{/isPrimitiveType}}{{#isPrimitiveType}}[**{{dataType}}**]{{/isPrimitiveType}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}{{#-first}}**Array<{{/-first}}{{value}}{{^-last}} &#124; {{/-last}}{{#-last}}>**{{/-last}}{{/enumVars}}{{/allowableValues}}{{/isEnum}} | {{description}} |{{^required}} (optional){{/required}} defaults to {{{.}}}
{{/defaultValue}}{{/allParams}}

### Return type

{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}

### Authorization

{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}}

### HTTP request headers

- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}

{{#responses.0}}

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
{{#responses}}
**{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
{{/responses}}
{{/responses.0}}

[[Back to top]](#) [[Back to API list]](README.md#documentation-for-api-endpoints) [[Back to Model list]](README.md#documentation-for-models) [[Back to README]](README.md)

{{/operation}}
{{/operations}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ node_modules
package-lock.json
@rerun.txt

node_modules
examples
25 changes: 25 additions & 0 deletions check-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

if [ $# -eq 0 ]; then
echo "No arguments supplied"
exit 2
fi

# install dependencies
yarn

./extract-code-blocks.sh examples $1

# temporary fix to compile example files
find examples/$1 -type f -name "*.ts" | xargs sed -i.bak 's_datadog-api-client_../../../index_1'

touch examples/$1/tsconfig.json

echo '{"compilerOptions":{"strict":true,"target":"es5","module":"commonjs","moduleResolution":"node","declaration":true,"esModuleInterop":true,"resolveJsonModule":true,"noImplicitAny":true,"noImplicitThis":true,"noUnusedLocals":false,"noUnusedParameters":false,"noImplicitReturns":true,"noFallthroughCasesInSwitch":true,"sourceMap":true,"noLib":false,"lib":["es5","es6","es7"]},"exclude":["dist","features","node_modules"],"include":["./**/*.ts"]}' > examples/$1/tsconfig.json

yarn tsc --build examples/$1

if [ $? -ne 0 ]; then
echo -e "Failed to build examples"
exit 1
fi
71 changes: 71 additions & 0 deletions extract-code-blocks.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env -S awk -f
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Based on https://codereview.stackexchange.com/questions/194986/print-code-fenced-sections-of-a-markdown-document/195030#195030
BEGIN {
in_code_block = 0;
tag = "";
operation_id = "";
}

function slug(value) {
head = "";
tail = value;
while ( match(tail,/[A-Z][a-z]/) ) {
tgt = substr(tail,RSTART,1);
if ( substr(tail,RSTART-1,1) ~ /[a-z]/ || RSTART > 1 ) {
tgt = "-" tolower(tgt);
}
head = head substr(tail,1,RSTART-1) tgt;
tail = substr(tail,RSTART+1);
}
return tolower(head) tail;
}

function camel(value) {
gsub("_ip_", "_iP_", value);
gsub("_id_", "_iD_", value);

head = toupper(substr(value,1,1)) substr(value,2);
while ( match(head, /_([a-z])/) ) {
head = substr(head,0,RSTART-1) toupper(substr(head,RSTART+1, 1)) substr(head,RSTART+2)
}
# NOTE special cases for all caps groups which we can't handle otherwise
gsub("Aws", "AWS", head);
gsub("Gcp", "GCP", head);
return head;
}

/^# datadog-api-client\.v[0-9]*\.(.+)Api/ {
tag = slug(substr($2, 23, length($2)-25));
}
/^##? \*\*.+\*\*/ {
operation_id = camel(substr($2, 3, length($2)-4))
}
/^```typescript/ {
if (in_code_block == 0) {
in_code_block = 1;
if (out_file) {
close(out_file);
}
system("mkdir -p " output "/" tag);
out_file=output "/" tag "/" operation_id ".ts";
print out_file;
} else {
print "Can't parse " FILENAME > "/dev/stderr"
exit 1
}
next;
}
/^```/ {
in_code_block = 0;
}

in_code_block {
# Make sure that the file is newly created
if (in_code_block == 1) {
in_code_block = 2;
print > out_file;
} else {
print >> out_file;
}
}
12 changes: 12 additions & 0 deletions extract-code-blocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

OUTPUT=${1:-examples}
VERSIONS=${2:-v1,v2}

cd ${0%/*}

VERSIONS=(${VERSIONS//,/ })

for version in "${VERSIONS[@]}"; do
ls docs/$version/*Api.md| xargs -n1 ./extract-code-blocks.awk -v output="${OUTPUT}/$version"
done