Skip to content

Commit 611df59

Browse files
authored
docs: GH-6 Part 2 - Updating docs to be more readable (#8)
* docs: GH-6 Updating docs templates and generation script * docs: GH-6 Updating ClientLockToAPSetting name to avoid conflicts * docs: GH-6 Updating generator version * docs: GH-6 Updating module version to 0.2.0
1 parent c503c14 commit 611df59

169 files changed

Lines changed: 11379 additions & 10588 deletions

File tree

Some content is hidden

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

.github/workflows/generate.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@ jobs:
3737
uses: docker://openapitools/openapi-generator-cli:v7.12.0
3838
with:
3939
args: >-
40-
generate
41-
-i tools/all-fixed.json
42-
-g go
43-
-o omada
44-
-c generator/config.json
45-
--git-user-id Tohaker
46-
--git-repo-id omada-go-sdk
40+
batch
41+
/github/workspace/generator/batch.yaml
4742
4843
- name: Tidy modules
4944
run: go mod tidy

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.0] - 2026-04-03
9+
10+
### Added
11+
12+
- Documentation is now available at https://tohaker.github.io/omada-go-sdk
13+
14+
### Changed
15+
16+
- SDK is now generated with `openapi-generator-cli` v7.21.0
17+
- Multipart requests now defer the closing of files when calling the `addFile` method.
18+
819
## [0.1.0] - 2026-03-29
920

1021
### Added

generator/batch.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
generatorName: go
2+
inputSpec: tools/all-fixed.json
3+
outputDir: omada
4+
templateDir: generator/templates
5+
gitUserId: Tohaker
6+
gitRepoId: omada-go-sdk
7+
additionalProperties:
8+
packageName: omada
9+
packageVersion: 0.2.0
10+
isGoSubmodule: true
11+
generateInterfaces: true
12+
structPrefix: true
13+
enumClassPrefix: true
14+
modelNameMappings:
15+
ClientLockToAPSetting: ClientLockToApMacListSetting
16+
ClientLockToApSetting: ClientLockToApDetailSetting

generator/config.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

generator/generate.sh

100644100755
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1515
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
1616
cd "${ROOT_DIR}"
1717

18-
GENERATOR_IMAGE="openapitools/openapi-generator-cli:v7.12.0"
18+
GENERATOR_IMAGE="openapitools/openapi-generator-cli:v7.21.0"
1919

2020
echo "=== Step 1: Fetch and fix upstream spec ==="
2121
go run tools/fix_spec.go
2222

2323
echo ""
2424
echo "=== Step 2: Generate SDK from fixed spec ==="
2525
docker run --rm \
26+
-w /local \
2627
-v "${ROOT_DIR}:/local" \
27-
"${GENERATOR_IMAGE}" generate \
28-
-i /local/tools/all-fixed.json \
29-
-g go \
30-
-o /local/omada \
31-
-c /local/generator/config.json \
32-
--git-user-id Tohaker \
33-
--git-repo-id omada-go-sdk
28+
"${GENERATOR_IMAGE}" batch generator/batch.yaml
3429

3530
echo ""
3631
echo "=== Step 3: Tidy Go modules ==="
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
# Go API client for TP-Link {{#lambda.titlecase}}{{{packageName}}}{{/lambda.titlecase}}
2+
3+
{{#appDescriptionWithNewLines}}
4+
{{{.}}}
5+
{{/appDescriptionWithNewLines}}
6+
7+
## Overview
8+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.
9+
10+
- API version: {{appVersion}}
11+
- Package version: {{packageVersion}}
12+
{{^hideGenerationTimestamp}}
13+
- Build date: {{generatedDate}}
14+
{{/hideGenerationTimestamp}}
15+
- Generator version: {{generatorVersion}}
16+
- Build package: {{generatorClass}}
17+
{{#infoUrl}}
18+
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
19+
{{/infoUrl}}
20+
21+
## Installation
22+
23+
Install the following dependencies:
24+
25+
```sh
26+
go get github.com/stretchr/testify/assert
27+
{{#hasOAuthMethods}}
28+
go get golang.org/x/oauth2
29+
{{/hasOAuthMethods}}
30+
go get golang.org/x/net/context
31+
```
32+
33+
Put the package under your project folder and add the following in import:
34+
35+
```go
36+
import {{packageName}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}"
37+
```
38+
39+
To use a proxy, set the environment variable `HTTP_PROXY`:
40+
41+
```go
42+
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
43+
```
44+
45+
## Configuration of Server URL
46+
47+
Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.
48+
49+
### Select Server Configuration
50+
51+
For using other server than the one defined on index 0 set context value `{{packageName}}.ContextServerIndex` of type `int`.
52+
53+
```go
54+
ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerIndex, 1)
55+
```
56+
57+
### Templated Server URL
58+
59+
Templated server URL is formatted using default variables from configuration or from context value `{{packageName}}.ContextServerVariables` of type `map[string]string`.
60+
61+
```go
62+
ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerVariables, map[string]string{
63+
"basePath": "v2",
64+
})
65+
```
66+
67+
Note, enum values are always validated and all unused variables are silently ignored.
68+
69+
### URLs Configuration per Operation
70+
71+
Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
72+
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
73+
Similar rules for overriding default operation server index and variables applies by using `{{packageName}}.ContextOperationServerIndices` and `{{packageName}}.ContextOperationServerVariables` context maps.
74+
75+
```go
76+
ctx := context.WithValue(context.Background(), {{packageName}}.ContextOperationServerIndices, map[string]int{
77+
"{classname}Service.{nickname}": 2,
78+
})
79+
ctx = context.WithValue(context.Background(), {{packageName}}.ContextOperationServerVariables, map[string]map[string]string{
80+
"{classname}Service.{nickname}": {
81+
"port": "8443",
82+
},
83+
})
84+
```
85+
86+
## Documentation for API Endpoints
87+
88+
All URIs are relative to *{{basePath}}*
89+
90+
Class | Method | HTTP request | Description
91+
------------ | ------------- | ------------- | -------------
92+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{summary}}
93+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
94+
95+
## Documentation For Models
96+
97+
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
98+
{{/model}}{{/models}}
99+
100+
## Documentation For Authorization
101+
102+
{{^authMethods}}Endpoints do not require authorization.{{/authMethods}}
103+
{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}}
104+
{{#authMethods}}
105+
### {{{name}}}
106+
107+
{{#isApiKey}}
108+
- **Type**: API key
109+
- **API key parameter name**: {{{keyParamName}}}
110+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
111+
112+
Note, each API key must be added to a map of `map[string]APIKey` where the key is: {{name}} and passed in as the auth context for each request.
113+
114+
Example
115+
116+
```go
117+
auth := context.WithValue(
118+
context.Background(),
119+
{{packageName}}.ContextAPIKeys,
120+
map[string]{{packageName}}.APIKey{
121+
"{{name}}": {Key: "API_KEY_STRING"},
122+
},
123+
)
124+
r, err := client.Service.Operation(auth, args)
125+
```
126+
127+
{{/isApiKey}}
128+
{{#isBasic}}
129+
{{#isBasicBearer}}
130+
- **Type**: HTTP Bearer token authentication
131+
132+
Example
133+
134+
```go
135+
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "BEARER_TOKEN_STRING")
136+
r, err := client.Service.Operation(auth, args)
137+
```
138+
139+
{{/isBasicBearer}}
140+
{{#isBasicBasic}}
141+
- **Type**: HTTP basic authentication
142+
143+
Example
144+
145+
```go
146+
auth := context.WithValue(context.Background(), {{packageName}}.ContextBasicAuth, {{packageName}}.BasicAuth{
147+
UserName: "username",
148+
Password: "password",
149+
})
150+
r, err := client.Service.Operation(auth, args)
151+
```
152+
153+
{{/isBasicBasic}}
154+
{{#isHttpSignature}}
155+
- **Type**: HTTP signature authentication
156+
157+
Example
158+
159+
```go
160+
authConfig := {{packageName}}.HttpSignatureAuth{
161+
KeyId: "my-key-id",
162+
PrivateKeyPath: "rsa.pem",
163+
Passphrase: "my-passphrase",
164+
SigningScheme: {{packageName}}.HttpSigningSchemeHs2019,
165+
SignedHeaders: []string{
166+
{{packageName}}.HttpSignatureParameterRequestTarget, // The special (request-target) parameter expresses the HTTP request target.
167+
{{packageName}}.HttpSignatureParameterCreated, // Time when request was signed, formatted as a Unix timestamp integer value.
168+
"Host", // The Host request header specifies the domain name of the server, and optionally the TCP port number.
169+
"Date", // The date and time at which the message was originated.
170+
"Content-Type", // The Media type of the body of the request.
171+
"Digest", // A cryptographic digest of the request body.
172+
},
173+
SigningAlgorithm: {{packageName}}.HttpSigningAlgorithmRsaPSS,
174+
SignatureMaxValidity: 5 * time.Minute,
175+
}
176+
var authCtx context.Context
177+
var err error
178+
if authCtx, err = authConfig.ContextWithValue(context.Background()); err != nil {
179+
// Process error
180+
}
181+
r, err = client.Service.Operation(auth, args)
182+
183+
```
184+
{{/isHttpSignature}}
185+
{{/isBasic}}
186+
{{#isOAuth}}
187+
188+
- **Type**: OAuth
189+
- **Flow**: {{{flow}}}
190+
- **Authorization URL**: {{{authorizationUrl}}}
191+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
192+
{{#scopes}} - **{{{scope}}}**: {{{description}}}
193+
{{/scopes}}
194+
195+
Example
196+
197+
```go
198+
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "ACCESSTOKENSTRING")
199+
r, err := client.Service.Operation(auth, args)
200+
```
201+
202+
Or via OAuth2 module to automatically refresh tokens and perform user authentication.
203+
204+
```go
205+
import "golang.org/x/oauth2"
206+
207+
/* Perform OAuth2 round trip request and obtain a token */
208+
209+
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
210+
auth := context.WithValue(oauth2.NoContext, {{packageName}}.ContextOAuth2, tokenSource)
211+
r, err := client.Service.Operation(auth, args)
212+
```
213+
214+
{{/isOAuth}}
215+
{{/authMethods}}
216+
217+
## Documentation for Utility Methods
218+
219+
Due to the fact that model structure members are all pointers, this package contains
220+
a number of utility functions to easily obtain pointers to values of basic types.
221+
Each of these functions takes a value of the given basic type and returns a pointer to it:
222+
223+
* `PtrBool`
224+
* `PtrInt`
225+
* `PtrInt32`
226+
* `PtrInt64`
227+
* `PtrFloat`
228+
* `PtrFloat32`
229+
* `PtrFloat64`
230+
* `PtrString`
231+
* `PtrTime`
232+
233+
## Author
234+
235+
{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}}
236+
{{/-last}}{{/apis}}{{/apiInfo}}

0 commit comments

Comments
 (0)