|
| 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