Skip to content

Commit

Permalink
Switch from go-swagger to openapi-generator
Browse files Browse the repository at this point in the history
Switch from go-swagger to openapi-generator
  • Loading branch information
carceneaux authored Apr 29, 2021
2 parents 5029a3f + 27748f0 commit fadb65d
Show file tree
Hide file tree
Showing 1,863 changed files with 194,746 additions and 264,733 deletions.
27 changes: 26 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
.DS_Store
.DS_Store

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@ default: generate dependency
# Removes currently generated client files
cleanup:
@echo "Removing current client files"
rm -rf models client
rm -rf client/*


# Validating Swagger spec
#
# https://goswagger.io/usage/validate.html
# https://openapi-generator.tech/docs/usage/#validate
validate:
@echo "Validating Swagger spec"
swagger validate ./swagger.yml
openapi-generator validate -i swagger.json

# Generating API client
#
# https://goswagger.io/generate/server.html
# https://goswagger.io/generate/client.html
# https://openapi-generator.tech/docs/generators/go
generate: cleanup validate
@echo "Generating API client"
# swagger generate server \
--skip-validation \
--exclude-main \
--target=./ \
--spec=./swagger.yml \
--name=veeam_vbr
swagger generate client \
--skip-validation \
--spec=./swagger.yml \
--name=veeam_vbr
openapi-generator generate \
-i swagger.json \
-g go \
-o client \
--package-name client \
--global-property skipFormModel=false \
-p enumClassPrefix=true
@echo "Removing generated dependencies file"
rm -rf client/go.*

# Adding new dependencies
dependency:
Expand Down
76 changes: 37 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

veeam-vbr-sdk-go is the unofficial Veeam Backup & Replication SDK for the Go programming language.

This SDK was generated using [go-swagger](https://github.com/go-swagger/go-swagger). As such, any API call in the [Veeam Backup & Replication v11 REST API](https://helpcenter.veeam.com/docs/backup/vbr_rest/overview.html?ver=110) is present in this SDK.
This SDK was generated using the [OpenAPI Generator](https://openapi-generator.tech/). As such, any API call in the [Veeam Backup & Replication v11 REST API](https://helpcenter.veeam.com/docs/backup/vbr_rest/overview.html?ver=110) is present in this SDK.

## 📗 Documentation

Expand Down Expand Up @@ -33,16 +33,14 @@ This example shows a complete working Go file which will list the names of all B
package main

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"os"
"time"

httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/veeamhub/veeam-vbr-sdk-go/client"
"github.com/veeamhub/veeam-vbr-sdk-go/client/jobs"
"github.com/veeamhub/veeam-vbr-sdk-go/client/login"
)

// Retrieves and prints out all Backup Job names of the specified VBR server.
Expand All @@ -51,65 +49,65 @@ import (
func main() {
// Setting variables
host := "vbr.contoso.local:9419" // default API port 9419
u := "contoso\\jsmith" // VBR username
p := strfmt.Password("password") // VBR password
timeout := 15 * time.Second // 15 seconds

// Using untrusted (self-signed) certificates
skipTlsClient := &http.Client{
username := "contoso\\jsmith" // VBR username
password = "password" // VBR password

// Setting constants
const (
apiVersion = "1.0-rev1" // default API version (1.0-rev1)
skipTls = true // skip TLS certificate verification
timeout = 30 * time.Second // 30 seconds
)

// Generating API client
tlsClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
InsecureSkipVerify: skipTls,
},
},
Timeout: timeout,
}
transport := httptransport.NewWithClient(host, "/", []string{"https"}, skipTlsClient)
veeam := client.New(transport, nil)

// Using trusted certificates
// veeam := client.NewHTTPClientWithConfig(nil, &client.TransportConfig{
// Host: host,
// BasePath: "/",
// Schemes: []string{"https"},
// })

// Settings parameters
params := login.NewCreateTokenParams().WithDefaults()
params.Username = &u
params.Password = &p
config := client.NewConfiguration()
config.HTTPClient = tlsClient
config.Host = host
config.HTTPClient.Timeout = timeout
config.Scheme = "https"
veeam := client.NewAPIClient(config)

// Authenticating to VBR API
l, err := veeam.Login.CreateToken(params)
login, r, err := veeam.LoginApi.CreateToken(context.Background()).XApiVersion(apiVersion).GrantType("password").Username(username).Password(password).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
panic(err)
}
token := *l.Payload.AccessToken

// Setting authorization
// From this point, all calls will require the 'auth' variable
auth := httptransport.BearerToken(token)
// From this point, all calls will 'auth' as the context
auth := context.WithValue(context.Background(), client.ContextAccessToken,
login.AccessToken)

// Retrieving all backup jobs
allJobs, err := veeam.Jobs.GetAllJobs(
jobs.NewGetAllJobsParams().WithDefaults(),
auth)
jobs, r, err := veeam.JobsApi.GetAllJobs(auth).XApiVersion(apiVersion).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
panic(err)
}

// Printing out job names
// Working with the response payload
fmt.Printf("Job Names:\n\n")
for _, job := range allJobs.Payload.Data {
fmt.Println(*job.Name)
for _, job := range jobs.Data {
fmt.Println(job.Name)
}

// Logging out session
veeam.Login.Logout(
login.NewLogoutParams().WithDefaults(),
auth)
_, r, err = veeam.LoginApi.Logout(auth).XApiVersion(apiVersion).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
panic(err)
}
}

```

## ✍ Contributions
Expand Down
24 changes: 24 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
23 changes: 23 additions & 0 deletions client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Loading

0 comments on commit fadb65d

Please sign in to comment.