remove logger, fix deserialization of json response

This commit is contained in:
wing328 2015-12-21 21:19:12 +08:00
parent 3ebefba678
commit 4062deed92
13 changed files with 351 additions and 758 deletions

View File

@ -1045,8 +1045,6 @@ public class DefaultCodegen {
}
property.baseType = getSwaggerType(p);
LOGGER.info("property.baseType=" + property.baseType);
LOGGER.info("property.datatype=" + property.datatype);
if (p instanceof ArrayProperty) {
property.isContainer = true;

View File

@ -657,7 +657,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
for (String nextImport : allImports) {
Map<String, String> im = new LinkedHashMap<String, String>();
String mapping = config.importMapping().get(nextImport);
LOGGER.info("mapping = " + mapping);
if (mapping == null) {
mapping = config.toModelImport(nextImport);
}
@ -704,7 +703,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
for (String nextImport : allImports) {
LOGGER.info("nextImport=" + nextImport);
Map<String, String> im = new LinkedHashMap<String, String>();
String mapping = config.importMapping().get(nextImport);
if (mapping == null) {
@ -713,14 +711,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
if (mapping != null && !config.defaultIncludes().contains(mapping)) {
im.put("import", mapping);
imports.add(im);
LOGGER.info("config.importMaping added " + mapping);
}
// add instantiation types
mapping = config.instantiationTypes().get(nextImport);
if (mapping != null && !config.defaultIncludes().contains(mapping)) {
im.put("import", mapping);
imports.add(im);
LOGGER.info("config.instantiationTypes added " + mapping);
}
}

View File

@ -128,8 +128,8 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
return name;
// camelize (lower first character) the variable name
// pet_id => petId
name = camelize(name, true);
// pet_id => PetId
name = camelize(name);
// for reserved word or word starting with number, append _
if(reservedWords.contains(name) || name.matches("^\\d.*"))
@ -163,7 +163,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String getTypeDeclaration(Property p) {
LOGGER.info("getTypeDeclaration=" + p.getName());
String swaggerType = getSwaggerType(p);
if(p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
@ -175,14 +175,6 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
return getSwaggerType(p) + "[string]" + getTypeDeclaration(inner);
}
LOGGER.info("super.getTypeDeclaration=" + super.getTypeDeclaration(p));
return super.getTypeDeclaration(p);
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
LOGGER.info("swaggerType=" + swaggerType);
String type = null;
if(typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
@ -200,7 +192,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
if(reservedWords.contains(operationId))
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
return camelize(operationId, true);
return camelize(operationId);
}
@Override

View File

@ -14,7 +14,7 @@ import (
type {{classname}} struct {
basePath string
apiClient ApiClient
sling *sling.Sling
//sling *sling.Sling
}
func New{{classname}}() *{{classname}}{
@ -39,13 +39,11 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{
//func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
_sling := a.sling.{{httpMethod}}(a.basePath)
_sling := sling.New().{{httpMethod}}(a.basePath)
// create path and map variables
path := "{{path}}"
{{#pathParams}}//path = regexp.MustCompile("{" + "{{paramName}}" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "{{paramName}}" + "\\}", ApiClient.EscapeString({{{paramName}}}))
path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%b", {{paramName}}), -1)
path := "{{basePathWithoutHost}}{{path}}"
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
{{/pathParams}}
_sling = _sling.Path(path)
@ -54,53 +52,36 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
{{#queryParams}}{{paramName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/queryParams}}
}
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{paramName}}: {{baseName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
_sling = _sling.QueryStruct(&QueryParams{ {{#queryParams}}{{paramName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}} })
{{/hasQueryParams}}
{{#headerParams}}// header params "{{baseName}}"
// accept header
accepts := []string { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
{{#hasHeaderParams}}{{#headerParams}} // header params "{{baseName}}"
_sling = _sling.Set("{{baseName}}", {{paramName}})
{{/headerParams}}
//contentTypes := []string { {{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}} }
{{/headerParams}}{{/hasHeaderParams}}
{{#hasFormParams}} type FormParams struct {
{{#formParams}} {{paramName}} {{dataType}} `url:"{{baseName}},omitempty"`
{{/formParams}}
}
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{paramName}}: {{baseName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
_sling = _sling.BodyForm(&FormParams{ {{#formParams}}{{paramName}}: {{paramName}}{{#hasMore}},{{/hasMore}}{{/formParams}} })
{{/hasFormParams}}
{{#bodyParams}}// body params
{{#hasBodyParams}}{{#bodyParams}}// body params
_sling = _sling.BodyJSON({{paramName}})
//b, _ := json.Marshal(body)
//bodyParams["{{baseName}}"] = string(b)
{{/bodyParams}}
{{/bodyParams}}{{/hasBodyParams}}
{{#returnType}}
var response {{returnType}}
{{#returnType}} response := new({{returnType}})
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("{{operationId}} response: ", response, resp, err)
return response, err
return *response, err
{{/returnType}}{{^returnType}}
resp, err := _sling.Request()
fmt.Println("{{operationId}} response: void, ", resp, err)
return err
{{/returnType}}
//response, err := a.apiClient.CallApi(a.basePath, path, "{{httpMethod}}", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//{{#returnType}}ApiClient.Deserialize(response, "{{returnContainer}}", "{{returnBaseType}}"){{/returnType}}
//{{#returnType}}var response {{returnType}}
//err = json.Unmarshal([]byte(req), &response)
//return response, err{{/returnType}}
//{{^returnType}}return err{{/returnType}}
}
{{/operation}}
{{/operations}}

View File

@ -4,7 +4,7 @@ import (
)
type Category struct {
id int64 `json:"id,omitempty"`
name string `json:"name,omitempty"`
Id int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}

View File

@ -1,15 +1,14 @@
package swagger
import (
"time"
)
type Order struct {
id int64 `json:"id,omitempty"`
petId int64 `json:"petId,omitempty"`
quantity int32 `json:"quantity,omitempty"`
shipDate time.Time `json:"shipDate,omitempty"`
status string `json:"status,omitempty"`
complete bool `json:"complete,omitempty"`
Id int64 `json:"id,omitempty"`
PetId int64 `json:"petId,omitempty"`
Quantity int32 `json:"quantity,omitempty"`
ShipDate time.Time `json:"shipDate,omitempty"`
Status string `json:"status,omitempty"`
Complete bool `json:"complete,omitempty"`
}

View File

@ -4,11 +4,11 @@ import (
)
type Pet struct {
id int64 `json:"id,omitempty"`
category Category `json:"category,omitempty"`
name string `json:"name,omitempty"`
photoUrls []string `json:"photoUrls,omitempty"`
tags []Tag `json:"tags,omitempty"`
status string `json:"status,omitempty"`
Id int64 `json:"id,omitempty"`
Category Category `json:"category,omitempty"`
Name string `json:"name,omitempty"`
PhotoUrls []string `json:"photoUrls,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Status string `json:"status,omitempty"`
}

View File

@ -6,13 +6,12 @@ import (
"fmt"
// "log"
"github.com/dghubble/sling"
"os"
)
type PetApi struct {
basePath string
apiClient ApiClient
sling *sling.Sling
//sling *sling.Sling
}
func NewPetApi() *PetApi{
@ -30,420 +29,271 @@ func NewPetApiWithBasePath(basePath string) *PetApi{
/**
* Update an existing pet
*
* @param body Pet object that needs to be added to the store
* @param Body Pet object that needs to be added to the store
* @return void
*/
//func (a PetApi) updatePet (body Pet) (error) {
func (a PetApi) updatePet (body Pet) (error) {
//func (a PetApi) UpdatePet (Body Pet) (error) {
func (a PetApi) UpdatePet (Body Pet) (error) {
_sling := a.sling.Put(a.basePath)
_sling := sling.New().Put(a.basePath)
// create path and map variables
path := "/pet"
path := "/v2/pet"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { "application/json","application/xml" }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
resp, err := _sling.Request()
fmt.Println("updatePet response: void, ", resp, err)
fmt.Println("UpdatePet response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Put", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Add a new pet to the store
*
* @param body Pet object that needs to be added to the store
* @param Body Pet object that needs to be added to the store
* @return void
*/
//func (a PetApi) addPet (body Pet) (error) {
func (a PetApi) addPet (body Pet) (error) {
//func (a PetApi) AddPet (Body Pet) (error) {
func (a PetApi) AddPet (Body Pet) (error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/pet"
path := "/v2/pet"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { "application/json","application/xml" }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
resp, err := _sling.Request()
fmt.Println("addPet response: void, ", resp, err)
fmt.Println("AddPet response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter
* @param Status Status values that need to be considered for filter
* @return []Pet
*/
//func (a PetApi) findPetsByStatus (status []string) ([]Pet, error) {
func (a PetApi) findPetsByStatus (status []string) ([]Pet, error) {
//func (a PetApi) FindPetsByStatus (Status []string) ([]Pet, error) {
func (a PetApi) FindPetsByStatus (Status []string) ([]Pet, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/pet/findByStatus"
path := "/v2/pet/findByStatus"
_sling = _sling.Path(path)
type QueryParams struct {
status []string `url:"status,omitempty"`
Status []string `url:"status,omitempty"`
}
_sling = _sling.QueryStruct(&QueryParams{ status: status })
_sling = _sling.QueryStruct(&QueryParams{ Status: Status })
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response []Pet
response := new([]Pet)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("findPetsByStatus response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "array", "Pet")
//var response []Pet
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("FindPetsByStatus response: ", response, resp, err)
return *response, err
}
/**
* Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by
* @param Tags Tags to filter by
* @return []Pet
*/
//func (a PetApi) findPetsByTags (tags []string) ([]Pet, error) {
func (a PetApi) findPetsByTags (tags []string) ([]Pet, error) {
//func (a PetApi) FindPetsByTags (Tags []string) ([]Pet, error) {
func (a PetApi) FindPetsByTags (Tags []string) ([]Pet, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/pet/findByTags"
path := "/v2/pet/findByTags"
_sling = _sling.Path(path)
type QueryParams struct {
tags []string `url:"tags,omitempty"`
Tags []string `url:"tags,omitempty"`
}
_sling = _sling.QueryStruct(&QueryParams{ tags: tags })
_sling = _sling.QueryStruct(&QueryParams{ Tags: Tags })
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response []Pet
response := new([]Pet)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("findPetsByTags response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "array", "Pet")
//var response []Pet
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("FindPetsByTags response: ", response, resp, err)
return *response, err
}
/**
* Find pet by ID
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @param PetId ID of pet that needs to be fetched
* @return Pet
*/
//func (a PetApi) getPetById (petId int64) (Pet, error) {
func (a PetApi) getPetById (petId int64) (Pet, error) {
//func (a PetApi) GetPetById (PetId int64) (Pet, error) {
func (a PetApi) GetPetById (PetId int64) (Pet, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/pet/{petId}"
//path = regexp.MustCompile("{" + "petId" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "petId" + "\\}", ApiClient.EscapeString(petId))
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%b", petId), -1)
path := "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", PetId), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response Pet
response := new(Pet)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("getPetById response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "", "Pet")
//var response Pet
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("GetPetById response: ", response, resp, err)
return *response, err
}
/**
* Updates a pet in the store with form data
*
* @param petId ID of pet that needs to be updated
* @param name Updated name of the pet
* @param status Updated status of the pet
* @param PetId ID of pet that needs to be updated
* @param Name Updated name of the pet
* @param Status Updated status of the pet
* @return void
*/
//func (a PetApi) updatePetWithForm (petId string, name string, status string) (error) {
func (a PetApi) updatePetWithForm (petId string, name string, status string) (error) {
//func (a PetApi) UpdatePetWithForm (PetId string, Name string, Status string) (error) {
func (a PetApi) UpdatePetWithForm (PetId string, Name string, Status string) (error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/pet/{petId}"
//path = regexp.MustCompile("{" + "petId" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "petId" + "\\}", ApiClient.EscapeString(petId))
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%b", petId), -1)
path := "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", PetId), -1)
_sling = _sling.Path(path)
//contentTypes := []string { "application/x-www-form-urlencoded" }
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
type FormParams struct {
name string `url:"name,omitempty"`
status string `url:"status,omitempty"`
Name string `url:"name,omitempty"`
Status string `url:"status,omitempty"`
}
_sling = _sling.BodyForm(&FormParams{ name: name,status: status })
_sling = _sling.BodyForm(&FormParams{ Name: Name,Status: Status })
resp, err := _sling.Request()
fmt.Println("updatePetWithForm response: void, ", resp, err)
fmt.Println("UpdatePetWithForm response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Deletes a pet
*
* @param petId Pet id to delete
* @param apiKey
* @param PetId Pet id to delete
* @param ApiKey
* @return void
*/
//func (a PetApi) deletePet (petId int64, apiKey string) (error) {
func (a PetApi) deletePet (petId int64, apiKey string) (error) {
//func (a PetApi) DeletePet (PetId int64, ApiKey string) (error) {
func (a PetApi) DeletePet (PetId int64, ApiKey string) (error) {
_sling := a.sling.Delete(a.basePath)
_sling := sling.New().Delete(a.basePath)
// create path and map variables
path := "/pet/{petId}"
//path = regexp.MustCompile("{" + "petId" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "petId" + "\\}", ApiClient.EscapeString(petId))
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%b", petId), -1)
path := "/v2/pet/{petId}"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", PetId), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
// header params "api_key"
_sling = _sling.Set("api_key", apiKey)
//contentTypes := []string { }
_sling = _sling.Set("api_key", ApiKey)
resp, err := _sling.Request()
fmt.Println("deletePet response: void, ", resp, err)
fmt.Println("DeletePet response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Delete", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* uploads an image
*
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
* @param PetId ID of pet to update
* @param AdditionalMetadata Additional data to pass to server
* @param File file to upload
* @return void
*/
//func (a PetApi) uploadFile (petId int64, additionalMetadata string, file *os.File) (error) {
func (a PetApi) uploadFile (petId int64, additionalMetadata string, file *os.File) (error) {
//func (a PetApi) UploadFile (PetId int64, AdditionalMetadata string, File *os.File) (error) {
func (a PetApi) UploadFile (PetId int64, AdditionalMetadata string, File *os.File) (error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/pet/{petId}/uploadImage"
//path = regexp.MustCompile("{" + "petId" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "petId" + "\\}", ApiClient.EscapeString(petId))
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%b", petId), -1)
path := "/v2/pet/{petId}/uploadImage"
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", PetId), -1)
_sling = _sling.Path(path)
//contentTypes := []string { "multipart/form-data" }
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
type FormParams struct {
additionalMetadata string `url:"additionalMetadata,omitempty"`
file *os.File `url:"file,omitempty"`
AdditionalMetadata string `url:"additionalMetadata,omitempty"`
File *os.File `url:"file,omitempty"`
}
_sling = _sling.BodyForm(&FormParams{ additionalMetadata: additionalMetadata,file: file })
_sling = _sling.BodyForm(&FormParams{ AdditionalMetadata: AdditionalMetadata,File: File })
resp, err := _sling.Request()
fmt.Println("uploadFile response: void, ", resp, err)
fmt.Println("UploadFile response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}

View File

@ -11,7 +11,7 @@ import (
type StoreApi struct {
basePath string
apiClient ApiClient
sling *sling.Sling
//sling *sling.Sling
}
func NewStoreApi() *StoreApi{
@ -31,196 +31,119 @@ func NewStoreApiWithBasePath(basePath string) *StoreApi{
* Returns a map of status codes to quantities
* @return map[string]int32
*/
//func (a StoreApi) getInventory () (map[string]int32, error) {
func (a StoreApi) getInventory () (map[string]int32, error) {
//func (a StoreApi) GetInventory () (map[string]int32, error) {
func (a StoreApi) GetInventory () (map[string]int32, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/store/inventory"
path := "/v2/store/inventory"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response map[string]int32
response := new(map[string]int32)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("getInventory response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "map", "map")
//var response map[string]int32
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("GetInventory response: ", response, resp, err)
return *response, err
}
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @param Body order placed for purchasing the pet
* @return Order
*/
//func (a StoreApi) placeOrder (body Order) (Order, error) {
func (a StoreApi) placeOrder (body Order) (Order, error) {
//func (a StoreApi) PlaceOrder (Body Order) (Order, error) {
func (a StoreApi) PlaceOrder (Body Order) (Order, error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/store/order"
path := "/v2/store/order"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
var response Order
response := new(Order)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("placeOrder response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "", "Order")
//var response Order
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("PlaceOrder response: ", response, resp, err)
return *response, err
}
/**
* Find purchase order by ID
* For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions
* @param orderId ID of pet that needs to be fetched
* @param OrderId ID of pet that needs to be fetched
* @return Order
*/
//func (a StoreApi) getOrderById (orderId string) (Order, error) {
func (a StoreApi) getOrderById (orderId string) (Order, error) {
//func (a StoreApi) GetOrderById (OrderId string) (Order, error) {
func (a StoreApi) GetOrderById (OrderId string) (Order, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/store/order/{orderId}"
//path = regexp.MustCompile("{" + "orderId" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "orderId" + "\\}", ApiClient.EscapeString(orderId))
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%b", orderId), -1)
path := "/v2/store/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", OrderId), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response Order
response := new(Order)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("getOrderById response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "", "Order")
//var response Order
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("GetOrderById response: ", response, resp, err)
return *response, err
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* @param orderId ID of the order that needs to be deleted
* @param OrderId ID of the order that needs to be deleted
* @return void
*/
//func (a StoreApi) deleteOrder (orderId string) (error) {
func (a StoreApi) deleteOrder (orderId string) (error) {
//func (a StoreApi) DeleteOrder (OrderId string) (error) {
func (a StoreApi) DeleteOrder (OrderId string) (error) {
_sling := a.sling.Delete(a.basePath)
_sling := sling.New().Delete(a.basePath)
// create path and map variables
path := "/store/order/{orderId}"
//path = regexp.MustCompile("{" + "orderId" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "orderId" + "\\}", ApiClient.EscapeString(orderId))
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%b", orderId), -1)
path := "/v2/store/order/{orderId}"
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", OrderId), -1)
_sling = _sling.Path(path)
//contentTypes := []string { }
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
resp, err := _sling.Request()
fmt.Println("deleteOrder response: void, ", resp, err)
fmt.Println("DeleteOrder response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Delete", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}

View File

@ -4,7 +4,7 @@ import (
)
type Tag struct {
id int64 `json:"id,omitempty"`
name string `json:"name,omitempty"`
Id int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}

View File

@ -4,13 +4,13 @@ import (
)
type User struct {
id int64 `json:"id,omitempty"`
username string `json:"username,omitempty"`
firstName string `json:"firstName,omitempty"`
lastName string `json:"lastName,omitempty"`
email string `json:"email,omitempty"`
password string `json:"password,omitempty"`
phone string `json:"phone,omitempty"`
userStatus int32 `json:"userStatus,omitempty"`
Id int64 `json:"id,omitempty"`
Username string `json:"username,omitempty"`
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
Email string `json:"email,omitempty"`
Password string `json:"password,omitempty"`
Phone string `json:"phone,omitempty"`
UserStatus int32 `json:"userStatus,omitempty"`
}

View File

@ -11,7 +11,7 @@ import (
type UserApi struct {
basePath string
apiClient ApiClient
sling *sling.Sling
//sling *sling.Sling
}
func NewUserApi() *UserApi{
@ -29,399 +29,250 @@ func NewUserApiWithBasePath(basePath string) *UserApi{
/**
* Create user
* This can only be done by the logged in user.
* @param body Created user object
* @param Body Created user object
* @return void
*/
//func (a UserApi) createUser (body User) (error) {
func (a UserApi) createUser (body User) (error) {
//func (a UserApi) CreateUser (Body User) (error) {
func (a UserApi) CreateUser (Body User) (error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/user"
path := "/v2/user"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
resp, err := _sling.Request()
fmt.Println("createUser response: void, ", resp, err)
fmt.Println("CreateUser response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @param Body List of user object
* @return void
*/
//func (a UserApi) createUsersWithArrayInput (body []User) (error) {
func (a UserApi) createUsersWithArrayInput (body []User) (error) {
//func (a UserApi) CreateUsersWithArrayInput (Body []User) (error) {
func (a UserApi) CreateUsersWithArrayInput (Body []User) (error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/user/createWithArray"
path := "/v2/user/createWithArray"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
resp, err := _sling.Request()
fmt.Println("createUsersWithArrayInput response: void, ", resp, err)
fmt.Println("CreateUsersWithArrayInput response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Creates list of users with given input array
*
* @param body List of user object
* @param Body List of user object
* @return void
*/
//func (a UserApi) createUsersWithListInput (body []User) (error) {
func (a UserApi) createUsersWithListInput (body []User) (error) {
//func (a UserApi) CreateUsersWithListInput (Body []User) (error) {
func (a UserApi) CreateUsersWithListInput (Body []User) (error) {
_sling := a.sling.Post(a.basePath)
_sling := sling.New().Post(a.basePath)
// create path and map variables
path := "/user/createWithList"
path := "/v2/user/createWithList"
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
resp, err := _sling.Request()
fmt.Println("createUsersWithListInput response: void, ", resp, err)
fmt.Println("CreateUsersWithListInput response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Post", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Logs user into the system
*
* @param username The user name for login
* @param password The password for login in clear text
* @param Username The user name for login
* @param Password The password for login in clear text
* @return string
*/
//func (a UserApi) loginUser (username string, password string) (string, error) {
func (a UserApi) loginUser (username string, password string) (string, error) {
//func (a UserApi) LoginUser (Username string, Password string) (string, error) {
func (a UserApi) LoginUser (Username string, Password string) (string, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/user/login"
path := "/v2/user/login"
_sling = _sling.Path(path)
type QueryParams struct {
username string `url:"username,omitempty"`
password string `url:"password,omitempty"`
Username string `url:"username,omitempty"`
Password string `url:"password,omitempty"`
}
_sling = _sling.QueryStruct(&QueryParams{ username: username,password: password })
_sling = _sling.QueryStruct(&QueryParams{ Username: Username,Password: Password })
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response string
response := new(string)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("loginUser response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "", "string")
//var response string
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("LoginUser response: ", response, resp, err)
return *response, err
}
/**
* Logs out current logged in user session
*
* @return void
*/
//func (a UserApi) logoutUser () (error) {
func (a UserApi) logoutUser () (error) {
//func (a UserApi) LogoutUser () (error) {
func (a UserApi) LogoutUser () (error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/user/logout"
path := "/v2/user/logout"
_sling = _sling.Path(path)
//contentTypes := []string { }
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
resp, err := _sling.Request()
fmt.Println("logoutUser response: void, ", resp, err)
fmt.Println("LogoutUser response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
* @param Username The name that needs to be fetched. Use user1 for testing.
* @return User
*/
//func (a UserApi) getUserByName (username string) (User, error) {
func (a UserApi) getUserByName (username string) (User, error) {
//func (a UserApi) GetUserByName (Username string) (User, error) {
func (a UserApi) GetUserByName (Username string) (User, error) {
_sling := a.sling.Get(a.basePath)
_sling := sling.New().Get(a.basePath)
// create path and map variables
path := "/user/{username}"
//path = regexp.MustCompile("{" + "username" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "username" + "\\}", ApiClient.EscapeString(username))
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%b", username), -1)
path := "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", Username), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
var response User
response := new(User)
resp, err := _sling.ReceiveSuccess(response)
fmt.Println("getUserByName response: ", response, resp, err)
return response, err
//response, err := a.apiClient.CallApi(a.basePath, path, "Get", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//ApiClient.Deserialize(response, "", "User")
//var response User
//err = json.Unmarshal([]byte(req), &response)
//return response, err
//
fmt.Println("GetUserByName response: ", response, resp, err)
return *response, err
}
/**
* Updated user
* This can only be done by the logged in user.
* @param username name that need to be deleted
* @param body Updated user object
* @param Username name that need to be deleted
* @param Body Updated user object
* @return void
*/
//func (a UserApi) updateUser (username string, body User) (error) {
func (a UserApi) updateUser (username string, body User) (error) {
//func (a UserApi) UpdateUser (Username string, Body User) (error) {
func (a UserApi) UpdateUser (Username string, Body User) (error) {
_sling := a.sling.Put(a.basePath)
_sling := sling.New().Put(a.basePath)
// create path and map variables
path := "/user/{username}"
//path = regexp.MustCompile("{" + "username" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "username" + "\\}", ApiClient.EscapeString(username))
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%b", username), -1)
path := "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", Username), -1)
_sling = _sling.Path(path)
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
//contentTypes := []string { }
// body params
_sling = _sling.BodyJSON(body)
//b, _ := json.Marshal(body)
//bodyParams["body"] = string(b)
resp, err := _sling.Request()
fmt.Println("updateUser response: void, ", resp, err)
fmt.Println("UpdateUser response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Put", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}
/**
* Delete user
* This can only be done by the logged in user.
* @param username The name that needs to be deleted
* @param Username The name that needs to be deleted
* @return void
*/
//func (a UserApi) deleteUser (username string) (error) {
func (a UserApi) deleteUser (username string) (error) {
//func (a UserApi) DeleteUser (Username string) (error) {
func (a UserApi) DeleteUser (Username string) (error) {
_sling := a.sling.Delete(a.basePath)
_sling := sling.New().Delete(a.basePath)
// create path and map variables
path := "/user/{username}"
//path = regexp.MustCompile("{" + "username" + "}").ReplaceAllString(path, "$1")
//path = path.Replace("\\{" + "username" + "\\}", ApiClient.EscapeString(username))
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%b", username), -1)
path := "/v2/user/{username}"
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", Username), -1)
_sling = _sling.Path(path)
//contentTypes := []string { }
// accept header
accepts := []string { "application/json", "application/xml" }
for key := range accepts {
_sling = _sling.Set("Accept", accepts[key])
break // only use the first Accept
}
resp, err := _sling.Request()
fmt.Println("deleteUser response: void, ", resp, err)
fmt.Println("DeleteUser response: void, ", resp, err)
return err
//response, err := a.apiClient.CallApi(a.basePath, path, "Delete", queryParams, headerParams, formParams, fileParams, bodyParams, contentTypes)
//if err != nil {
// log.Fatal(err)
//}
//
//
//return err
}

View File

@ -1,15 +1,18 @@
package main
import (
sw "./swagger"
"fmt"
// "log"
swagger "./swagger"
)
func main() {
fmt.Println("hello world")
s := swagger.NewPetApi()
&s.updatePetWithForm("2", "golang", "available")
s := sw.NewPetApi()
//s.UpdatePetWithForm("2", "golang", "available")
// test Get
resp, err := s.GetPetById(3)
fmt.Println("GetPetById: ", resp, err)
}