Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Style][Go] standardize the format of mustache (tiny change) #17363

Merged
merged 4 commits into from
Dec 10, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package handlers
{{#operations}}
import (
"{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}/models"
"github.com/labstack/echo/v4"
"net/http"
"{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}/models"
"github.com/labstack/echo/v4"
"net/http"
){{#operation}}

// {{nickname}} - {{{summary}}}
{{#isDeprecated}}
// Deprecated
{{/isDeprecated}}
func (c *Container) {{operationId}}(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, models.HelloWorld {
Message: "Hello World",
})
return ctx.JSON(http.StatusOK, models.HelloWorld {
Message: "Hello World",
})
}
{{/operation}}{{/operations}}
{{/operation}}{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ type Container struct {

// NewContainer returns an empty or an initialized container for your handlers.
func NewContainer() (Container, error) {
c := Container{}
return c, nil
}
c := Container{}
return c, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package models

// HelloWorld is a sample data structure to make sure each endpoint return something.
type HelloWorld struct {
Message string `json:"message"`
}
Message string `json:"message"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {
e := echo.New()

//todo: handle the error!
//todo: handle the error!
c, _ := handlers.NewContainer()

// Middleware
Expand All @@ -23,4 +23,4 @@ func main() {

// Start server
e.Logger.Fatal(e.Start(":{{serverPort}}"))
}
}
28 changes: 14 additions & 14 deletions modules/openapi-generator/src/main/resources/go/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})

Install the following dependencies:

```shell
```sh
go get github.com/stretchr/testify/assert
{{#hasOAuthMethods}}
go get golang.org/x/oauth2
Expand All @@ -31,13 +31,13 @@ go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

```golang
```go
import {{packageName}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}"
```

To use a proxy, set the environment variable `HTTP_PROXY`:

```golang
```go
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
```

Expand All @@ -49,15 +49,15 @@ Default configuration comes with `Servers` field that contains server objects as

For using other server than the one defined on index 0 set context value `{{packageName}}.ContextServerIndex` of type `int`.

```golang
```go
ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerIndex, 1)
```

### Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value `{{packageName}}.ContextServerVariables` of type `map[string]string`.

```golang
```go
ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerVariables, map[string]string{
"basePath": "v2",
})
Expand All @@ -71,7 +71,7 @@ Each operation can use different server URL defined using `OperationServers` map
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
Similar rules for overriding default operation server index and variables applies by using `{{packageName}}.ContextOperationServerIndices` and `{{packageName}}.ContextOperationServerVariables` context maps.

```golang
```go
ctx := context.WithValue(context.Background(), {{packageName}}.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
Expand Down Expand Up @@ -112,7 +112,7 @@ Note, each API key must be added to a map of `map[string]APIKey` where the key i

Example

```golang
```go
auth := context.WithValue(
context.Background(),
{{packageName}}.ContextAPIKeys,
Expand All @@ -130,7 +130,7 @@ r, err := client.Service.Operation(auth, args)

Example

```golang
```go
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "BEARER_TOKEN_STRING")
r, err := client.Service.Operation(auth, args)
```
Expand All @@ -141,10 +141,10 @@ r, err := client.Service.Operation(auth, args)

Example

```golang
```go
auth := context.WithValue(context.Background(), {{packageName}}.ContextBasicAuth, {{packageName}}.BasicAuth{
UserName: "username",
Password: "password",
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```
Expand All @@ -155,7 +155,7 @@ r, err := client.Service.Operation(auth, args)

Example

```golang
```go
authConfig := {{packageName}}.HttpSignatureAuth{
KeyId: "my-key-id",
PrivateKeyPath: "rsa.pem",
Expand Down Expand Up @@ -193,14 +193,14 @@ Example

Example

```golang
```go
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Or via OAuth2 module to automatically refresh tokens and perform user authentication.

```golang
```go
import "golang.org/x/oauth2"

/* Perform OAuth2 round trip request and obtain a token */
Expand Down
38 changes: 19 additions & 19 deletions modules/openapi-generator/src/main/resources/go/api_doc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ Method | HTTP request | Description
package main

import (
"context"
"fmt"
"os"
"context"
"fmt"
"os"
{{#vendorExtensions.x-go-import}}
{{{vendorExtensions.x-go-import}}}
{{/vendorExtensions.x-go-import}}
{{goImportAlias}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}"
{{goImportAlias}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}"
)

func main() {
{{#allParams}}
{{paramName}} := {{{vendorExtensions.x-go-example}}} // {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}

configuration := {{goImportAlias}}.NewConfiguration()
apiClient := {{goImportAlias}}.NewAPIClient(configuration)
{{#returnType}}resp, {{/returnType}}r, err := apiClient.{{classname}}.{{operationId}}(context.Background(){{#pathParams}}, {{paramName}}{{/pathParams}}){{#allParams}}{{^isPathParam}}.{{vendorExtensions.x-export-param-name}}({{paramName}}){{/isPathParam}}{{/allParams}}.Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `{{classname}}.{{operationId}}``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
{{#returnType}}
// response from `{{operationId}}`: {{{.}}}
fmt.Fprintf(os.Stdout, "Response from `{{classname}}.{{operationId}}`: %v\n", resp)
{{/returnType}}
{{#allParams}}
{{paramName}} := {{{vendorExtensions.x-go-example}}} // {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}

configuration := {{goImportAlias}}.NewConfiguration()
apiClient := {{goImportAlias}}.NewAPIClient(configuration)
{{#returnType}}resp, {{/returnType}}r, err := apiClient.{{classname}}.{{operationId}}(context.Background(){{#pathParams}}, {{paramName}}{{/pathParams}}){{#allParams}}{{^isPathParam}}.{{vendorExtensions.x-export-param-name}}({{paramName}}){{/isPathParam}}{{/allParams}}.Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `{{classname}}.{{operationId}}``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
{{#returnType}}
// response from `{{operationId}}`: {{{.}}}
fmt.Fprintf(os.Stdout, "Response from `{{classname}}.{{operationId}}`: %v\n", resp)
{{/returnType}}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) {
{{/hasRequired}}
{{/isAdditionalPropertiesTrue}}
{{#hasRequired}}
// This validates that all required properties are included in the JSON object
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
Expand Down
20 changes: 10 additions & 10 deletions samples/client/echo_api/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat

Install the following dependencies:

```shell
```sh
go get github.com/stretchr/testify/assert
go get golang.org/x/net/context
```

Put the package under your project folder and add the following in import:

```golang
```go
import openapi "github.com/GIT_USER_ID/GIT_REPO_ID"
```

To use a proxy, set the environment variable `HTTP_PROXY`:

```golang
```go
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
```

Expand All @@ -38,15 +38,15 @@ Default configuration comes with `Servers` field that contains server objects as

For using other server than the one defined on index 0 set context value `openapi.ContextServerIndex` of type `int`.

```golang
```go
ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)
```

### Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value `openapi.ContextServerVariables` of type `map[string]string`.

```golang
```go
ctx := context.WithValue(context.Background(), openapi.ContextServerVariables, map[string]string{
"basePath": "v2",
})
Expand All @@ -60,7 +60,7 @@ Each operation can use different server URL defined using `OperationServers` map
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
Similar rules for overriding default operation server index and variables applies by using `openapi.ContextOperationServerIndices` and `openapi.ContextOperationServerVariables` context maps.

```golang
```go
ctx := context.WithValue(context.Background(), openapi.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
Expand Down Expand Up @@ -126,10 +126,10 @@ Authentication schemes defined for the API:

Example

```golang
```go
auth := context.WithValue(context.Background(), openapi.ContextBasicAuth, openapi.BasicAuth{
UserName: "username",
Password: "password",
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```
Expand All @@ -140,7 +140,7 @@ r, err := client.Service.Operation(auth, args)

Example

```golang
```go
auth := context.WithValue(context.Background(), openapi.ContextAccessToken, "BEARER_TOKEN_STRING")
r, err := client.Service.Operation(auth, args)
```
Expand Down
52 changes: 26 additions & 26 deletions samples/client/echo_api/go/docs/AuthAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ To test HTTP basic authentication
package main

import (
"context"
"fmt"
"os"
openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID"
"context"
"fmt"
"os"
openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID"
)

func main() {

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.AuthAPI.TestAuthHttpBasic(context.Background()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AuthAPI.TestAuthHttpBasic``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `TestAuthHttpBasic`: string
fmt.Fprintf(os.Stdout, "Response from `AuthAPI.TestAuthHttpBasic`: %v\n", resp)
configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.AuthAPI.TestAuthHttpBasic(context.Background()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AuthAPI.TestAuthHttpBasic``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `TestAuthHttpBasic`: string
fmt.Fprintf(os.Stdout, "Response from `AuthAPI.TestAuthHttpBasic`: %v\n", resp)
}
```

Expand Down Expand Up @@ -84,23 +84,23 @@ To test HTTP bearer authentication
package main

import (
"context"
"fmt"
"os"
openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID"
"context"
"fmt"
"os"
openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID"
)

func main() {

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.AuthAPI.TestAuthHttpBearer(context.Background()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AuthAPI.TestAuthHttpBearer``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `TestAuthHttpBearer`: string
fmt.Fprintf(os.Stdout, "Response from `AuthAPI.TestAuthHttpBearer`: %v\n", resp)
configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.AuthAPI.TestAuthHttpBearer(context.Background()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AuthAPI.TestAuthHttpBearer``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `TestAuthHttpBearer`: string
fmt.Fprintf(os.Stdout, "Response from `AuthAPI.TestAuthHttpBearer`: %v\n", resp)
}
```

Expand Down
Loading
Loading