Skip to content

Commit d33111f

Browse files
Generate docs and examples for Typescript (#143)
1 parent 5415351 commit d33111f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+19054
-5
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.4.1.dev6",
7-
"regenerated": "2021-05-21 07:36:13.096490",
8-
"spec_repo_commit": "c413ebe"
7+
"regenerated": "2021-05-21 18:10:08.464066",
8+
"spec_repo_commit": "888558a"
99
},
1010
"v2": {
1111
"apigentools_version": "1.4.1.dev6",
12-
"regenerated": "2021-05-21 07:36:18.492517",
13-
"spec_repo_commit": "c413ebe"
12+
"regenerated": "2021-05-21 18:10:54.641466",
13+
"spec_repo_commit": "888558a"
1414
}
1515
}
1616
}

.generator/templates/api_doc.mustache

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# {{projectName}}.{{moduleName}}.{{classname}}{{#description}}
2+
3+
{{description}}{{/description}}
4+
5+
All URIs are relative to *{{basePath}}*
6+
7+
Method | HTTP request | Description
8+
------------- | ------------- | -------------
9+
{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
10+
{{/operation}}{{/operations}}
11+
12+
{{#operations}}
13+
{{#operation}}
14+
## **{{{operationId}}}**
15+
> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#requiredParams}}{{^defaultValue}}{{paramName}}{{^-last}}, {{/-last}}{{/defaultValue}}{{/requiredParams}})
16+
17+
{{#notes}}
18+
{{{notes}}}
19+
{{/notes}}
20+
21+
### Example
22+
23+
24+
```typescript
25+
import { {{{moduleName}}} } from '{{{projectName}}}';
26+
import * as fs from 'fs';
27+
28+
const configuration = {{{moduleName}}}.createConfiguration();
29+
const apiInstance = new {{{moduleName}}}.{{classname}}(configuration);
30+
31+
{{#hasParams}}
32+
let body:{{{moduleName}}}.{{classname}}{{operationIdCamelCase}}Request = {
33+
{{#allParams}}
34+
// {{{dataType}}}{{#description}} | {{{description}}}{{/description}}{{^required}} (optional){{/required}}
35+
{{paramName}}: {{{example}}},
36+
{{/allParams}}
37+
};
38+
{{/hasParams}}
39+
{{^hasParams}}
40+
let body:any = {};
41+
{{/hasParams}}
42+
43+
apiInstance.{{{operationId}}}(body).then((data:any) => {
44+
console.log('API called successfully. Returned data: ' + data);
45+
}).catch((error:any) => console.error(error));
46+
```
47+
48+
49+
### Parameters
50+
{{^hasParams}}This endpoint does not need any parameter.{{/hasParams}}{{#allParams}}{{#-last}}
51+
Name | Type | Description | Notes
52+
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
53+
{{#allParams}}{{^defaultValue}} **{{paramName}}** | {{^isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}| {{description}} |
54+
{{/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 {{{.}}}
55+
{{/defaultValue}}{{/allParams}}
56+
57+
### Return type
58+
59+
{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}
60+
61+
### Authorization
62+
63+
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}}
64+
65+
### HTTP request headers
66+
67+
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
68+
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
69+
70+
{{#responses.0}}
71+
72+
### HTTP response details
73+
| Status code | Description | Response headers |
74+
|-------------|-------------|------------------|
75+
{{#responses}}
76+
**{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
77+
{{/responses}}
78+
{{/responses.0}}
79+
80+
[[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)
81+
82+
{{/operation}}
83+
{{/operations}}

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ node_modules
33
package-lock.json
44
@rerun.txt
55

6-
node_modules
6+
examples
7+
8+
*.js
9+
*.js.map
10+
*.d.ts
11+
12+
!cucumber.js
13+
!bin/check-licenses.js
14+
!.eslintrc.js

check-examples.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -eq 0 ]; then
4+
echo "No arguments supplied"
5+
exit 2
6+
fi
7+
8+
# install dependencies
9+
yarn
10+
11+
./extract-code-blocks.sh examples $1
12+
13+
# temporary fix to compile example files
14+
find examples/$1 -type f -name "*.ts" | xargs sed -i.bak 's_datadog-api-client_../../../index_1'
15+
16+
touch examples/$1/tsconfig.json
17+
18+
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
19+
20+
yarn tsc --build examples/$1
21+
22+
if [ $? -ne 0 ]; then
23+
echo -e "Failed to build examples"
24+
exit 1
25+
fi

0 commit comments

Comments
 (0)