Skip to content

Commit 142141b

Browse files
authored
chore(doc): document Go SDK generator template adjustments (#242)
1 parent bbdf672 commit 142141b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

languages/golang/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# STACKIT Golang SDK Generator
2+
3+
## Template adjustments
4+
5+
The following templates were customized but don't need to be adjusted when updating the Go SDK generator to a new a newer upstream version:
6+
7+
- `configuration.mustache`: This template was entirely overwritten so we can use our custom [configuration struct](https://github.com/stackitcloud/stackit-sdk-go/blob/c3b04bc3cb8bf93de351fd7b1b04ac11de78ff89/core/config/config.go#L78) from our Go SDK core module. By default the OpenAPI generator would generate a new configuration struct for each service API version.
8+
9+
The following templates were customized and need to be checked for adjustments when updating the Go SDK generator to a newer upstream version:
10+
11+
- `client.mustache`:
12+
- Removed the generation of the `GenericOpenAPIError` struct which would be generated for each service API version by default. Instead use the `GenericOpenAPIError` struct from the [Go SDK core module](https://github.com/stackitcloud/stackit-sdk-go/blob/c3b04bc3cb8bf93de351fd7b1b04ac11de78ff89/core/oapierror/oapierror.go#L15).
13+
- Our custom `GenericOpenAPIError` struct from the core module has additional fields like the http status code, ... which the default one doesn't have.
14+
- Customized the `NewAPIClient` func to use the configuration struct and the authentication from the core SDK module.
15+
- `api.mustache`
16+
- Added customization to capture the HTTP request and response in the context (like it was done before the multi API version support was implemented in the Go SDK generator).
17+
- Use the `GenericOpenAPIError` struct from the core module instead of the default one (see previous section of `client.mustache`).
18+
- Don't return the `http.Response` param which the OpenAPI generator returns by default.
19+
- It was done like that before the multi API version support was implemented in the Go SDK generator.
20+
- Furthermore, it would when using the STACKIT Go SDK require a lot of boilerplate code after each SDK API call to do a nil check, close the http response body and handle the potential error.
21+
22+
## Custom templates
23+
24+
The custom templates don't need to be adjusted when updating the Go SDK generator to a new a newer upstream version.
25+
26+
- `custom/api_mock.mustache`: This template was added to allow easy mocking of SDK API calls in unit test implementations.
27+

languages/golang/templates/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
482482
{{! TEMPLATE CUSTOMIZATION - BEGIN - use the GenericOpenAPIError struct from the core module instead of the one generated by OpenAPI generator by default }}
483483
newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v)
484484
newErr.Model = v
485+
{{! TEMPLATE CUSTOMIZATION - END - use the GenericOpenAPIError struct from the core module instead of the one generated by OpenAPI generator by default }}
485486
{{! TEMPLATE CUSTOMIZATION - BEGIN - don't return http response - would require closing after each SDK API call to prevent resource leaks }}
486487
return {{#returnType}}localVarReturnValue, {{/returnType}} newErr
487488
{{! TEMPLATE CUSTOMIZATION - END - don't return http response - would require closing after each SDK API call to prevent resource leaks }}

0 commit comments

Comments
 (0)