forked from loafle/openapi-generator-original
Merge pull request #2627 from guohuang/remove_package_name
Removed "packageName" folder for easy installation
This commit is contained in:
commit
48a42358f0
@ -133,8 +133,8 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", packageName, "configuration.go"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", packageName, "api_client.go"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", "", "api_client.go"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,11 +158,11 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + packageName;
|
||||
return outputFolder + File.separator;
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + packageName;
|
||||
return outputFolder + File.separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
40
samples/client/petstore/go/api_client.go
Normal file
40
samples/client/petstore/go/api_client.go
Normal file
@ -0,0 +1,40 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ApiClient struct {
|
||||
}
|
||||
|
||||
func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string {
|
||||
if len(contentTypes) == 0 {
|
||||
return ""
|
||||
}
|
||||
if contains(contentTypes, "application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return contentTypes[0] // use the first content type specified in 'consumes'
|
||||
}
|
||||
|
||||
func (c *ApiClient) SelectHeaderAccept(accepts []string) string {
|
||||
if len(accepts) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if contains(accepts, "application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return strings.Join(accepts, ",")
|
||||
}
|
||||
|
||||
func contains(source []string, containvalue string) bool {
|
||||
for _, a := range source {
|
||||
if strings.ToLower(a) == strings.ToLower(containvalue) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
package main
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
sw "./swagger"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddPet(t *testing.T) {
|
||||
s := sw.NewPetApi()
|
||||
newPet := (sw.Pet{Id: 12830, Name: "gopher",
|
||||
s := NewPetApi()
|
||||
newPet := (Pet{Id: 12830, Name: "gopher",
|
||||
PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"})
|
||||
|
||||
err := s.AddPet(newPet)
|
||||
@ -23,22 +21,22 @@ func TestAddPet(t *testing.T) {
|
||||
func TestGetPetById(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
s := sw.NewPetApi()
|
||||
s := NewPetApi()
|
||||
resp, err := s.GetPetById(12830)
|
||||
if err != nil {
|
||||
t.Errorf("Error while getting pet by id")
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(resp.Id, "12830", "Pet id should be equal")
|
||||
assert.Equal(resp.Id, int64(12830), "Pet id should be equal")
|
||||
assert.Equal(resp.Name, "gopher", "Pet name should be gopher")
|
||||
assert.Equal(resp.Status, "pending", "Pet status should be pending")
|
||||
|
||||
t.Log(resp)
|
||||
//t.Log(resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdatePetWithForm(t *testing.T) {
|
||||
s := sw.NewPetApi()
|
||||
s := NewPetApi()
|
||||
err := s.UpdatePetWithForm(12830, "golang", "available")
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,41 +0,0 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ApiClient struct {
|
||||
|
||||
}
|
||||
|
||||
func (c *ApiClient) SelectHeaderContentType(contentTypes []string) string {
|
||||
if (len(contentTypes) == 0){
|
||||
return ""
|
||||
}
|
||||
if contains(contentTypes,"application/json") {
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return contentTypes[0] // use the first content type specified in 'consumes'
|
||||
}
|
||||
|
||||
func (c *ApiClient) SelectHeaderAccept(accepts []string) string {
|
||||
if (len(accepts) == 0){
|
||||
return ""
|
||||
}
|
||||
|
||||
if contains(accepts,"application/json"){
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
return strings.Join(accepts,",")
|
||||
}
|
||||
|
||||
func contains(source []string, containvalue string) bool {
|
||||
for _, a := range source {
|
||||
if strings.ToLower(a) == strings.ToLower(containvalue) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
package main
|
||||
package swagger
|
||||
|
||||
import (
|
||||
sw "./swagger"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
s := sw.NewPetApi()
|
||||
s := NewPetApi()
|
||||
|
||||
// test POST(body)
|
||||
newPet := (sw.Pet{Id: 12830, Name: "gopher",
|
||||
newPet := (Pet{Id: 12830, Name: "gopher",
|
||||
PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"})
|
||||
|
||||
jsonNewPet, _ := json.Marshal(newPet)
|
||||
|
Loading…
x
Reference in New Issue
Block a user