Skip to content

Commit 657f5fb

Browse files
authored
Test go client with aws signature in github workflow (#21657)
* test go client with aws signature in github workflow * fix path * fix path * test with windows * omit version
1 parent fbb15fd commit 657f5fb

File tree

25 files changed

+3160
-0
lines changed

25 files changed

+3160
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Samples Go Clients
2+
3+
on:
4+
push:
5+
paths:
6+
- 'samples/openapi3/client/petstore/go/go-petstore-aws-signature/**'
7+
pull_request:
8+
paths:
9+
- 'samples/openapi3/client/petstore/go/go-petstore-aws-signature/**'
10+
11+
jobs:
12+
build:
13+
name: Build Go
14+
runs-on: windows-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
sample:
19+
- 'samples/openapi3/client/petstore/go/go-petstore-aws-signature/'
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-go@v5
23+
- run: go version
24+
- name: Install Dependencies
25+
working-directory: ${{ matrix.sample }}
26+
run: |
27+
go mod tidy
28+
- name: Run test
29+
working-directory: ${{ matrix.sample }}
30+
run: go test -mod=mod -v
31+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: go
2+
outputDir: samples/openapi3/client/petstore/go/go-petstore-aws-signature
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/go
5+
additionalProperties:
6+
enumClassPrefix: "true"
7+
packageName: petstore
8+
disallowAdditionalPropertiesIfNotPresent: false
9+
withAWSV4Signature: true
10+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.gitignore
2+
.travis.yml
3+
README.md
4+
api/openapi.yaml
5+
api_pet.go
6+
client.go
7+
configuration.go
8+
docs/Category.md
9+
docs/Pet.md
10+
docs/PetAPI.md
11+
docs/Tag.md
12+
git_push.sh
13+
go.mod
14+
go.sum
15+
model_category.go
16+
model_pet.go
17+
model_tag.go
18+
response.go
19+
utils.go
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.15.0-SNAPSHOT
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: go
2+
3+
install:
4+
- go get -d -v .
5+
6+
script:
7+
- go build -v ./
8+
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Go API client for petstore
2+
3+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
5+
## Overview
6+
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.
7+
8+
- API version: 1.0.0
9+
- Package version: 1.0.0
10+
- Generator version: 7.15.0-SNAPSHOT
11+
- Build package: org.openapitools.codegen.languages.GoClientCodegen
12+
13+
## Installation
14+
15+
Install the following dependencies:
16+
17+
```sh
18+
go get github.com/stretchr/testify/assert
19+
go get golang.org/x/oauth2
20+
go get golang.org/x/net/context
21+
```
22+
23+
Put the package under your project folder and add the following in import:
24+
25+
```go
26+
import petstore "github.com/GIT_USER_ID/GIT_REPO_ID"
27+
```
28+
29+
To use a proxy, set the environment variable `HTTP_PROXY`:
30+
31+
```go
32+
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
33+
```
34+
35+
## Configuration of Server URL
36+
37+
Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.
38+
39+
### Select Server Configuration
40+
41+
For using other server than the one defined on index 0 set context value `petstore.ContextServerIndex` of type `int`.
42+
43+
```go
44+
ctx := context.WithValue(context.Background(), petstore.ContextServerIndex, 1)
45+
```
46+
47+
### Templated Server URL
48+
49+
Templated server URL is formatted using default variables from configuration or from context value `petstore.ContextServerVariables` of type `map[string]string`.
50+
51+
```go
52+
ctx := context.WithValue(context.Background(), petstore.ContextServerVariables, map[string]string{
53+
"basePath": "v2",
54+
})
55+
```
56+
57+
Note, enum values are always validated and all unused variables are silently ignored.
58+
59+
### URLs Configuration per Operation
60+
61+
Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
62+
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
63+
Similar rules for overriding default operation server index and variables applies by using `petstore.ContextOperationServerIndices` and `petstore.ContextOperationServerVariables` context maps.
64+
65+
```go
66+
ctx := context.WithValue(context.Background(), petstore.ContextOperationServerIndices, map[string]int{
67+
"{classname}Service.{nickname}": 2,
68+
})
69+
ctx = context.WithValue(context.Background(), petstore.ContextOperationServerVariables, map[string]map[string]string{
70+
"{classname}Service.{nickname}": {
71+
"port": "8443",
72+
},
73+
})
74+
```
75+
76+
## Documentation for API Endpoints
77+
78+
All URIs are relative to *http://petstore.swagger.io/v2*
79+
80+
Class | Method | HTTP request | Description
81+
------------ | ------------- | ------------- | -------------
82+
*PetAPI* | [**AddPet**](docs/PetAPI.md#addpet) | **Post** /pet | Add a new pet to the store
83+
84+
85+
## Documentation For Models
86+
87+
- [Category](docs/Category.md)
88+
- [Pet](docs/Pet.md)
89+
- [Tag](docs/Tag.md)
90+
91+
92+
## Documentation For Authorization
93+
94+
95+
Authentication schemes defined for the API:
96+
### petstore_auth
97+
98+
99+
- **Type**: OAuth
100+
- **Flow**: implicit
101+
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
102+
- **Scopes**:
103+
- **write:pets**: modify pets in your account
104+
- **read:pets**: read your pets
105+
106+
Example
107+
108+
```go
109+
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
110+
r, err := client.Service.Operation(auth, args)
111+
```
112+
113+
Or via OAuth2 module to automatically refresh tokens and perform user authentication.
114+
115+
```go
116+
import "golang.org/x/oauth2"
117+
118+
/* Perform OAuth2 round trip request and obtain a token */
119+
120+
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
121+
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
122+
r, err := client.Service.Operation(auth, args)
123+
```
124+
125+
126+
## Documentation for Utility Methods
127+
128+
Due to the fact that model structure members are all pointers, this package contains
129+
a number of utility functions to easily obtain pointers to values of basic types.
130+
Each of these functions takes a value of the given basic type and returns a pointer to it:
131+
132+
* `PtrBool`
133+
* `PtrInt`
134+
* `PtrInt32`
135+
* `PtrInt64`
136+
* `PtrFloat`
137+
* `PtrFloat32`
138+
* `PtrFloat64`
139+
* `PtrString`
140+
* `PtrTime`
141+
142+
## Author
143+
144+
145+

0 commit comments

Comments
 (0)