From 00fcf9946a86d3da65e8dfc58c7b04bcf6bbbe81 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Sun, 10 Apr 2016 20:50:53 -0700 Subject: [PATCH 1/4] issue #1946, added AddDefaultHeader method for GO --- .../src/main/resources/go/configuration.mustache | 7 +++++++ samples/client/petstore/go/swagger/Configuration.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/go/configuration.mustache b/modules/swagger-codegen/src/main/resources/go/configuration.mustache index bf3a8f92bed..b9e13630fc9 100644 --- a/modules/swagger-codegen/src/main/resources/go/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/go/configuration.mustache @@ -14,12 +14,19 @@ type Configuration struct { BasePath string `json:"basePath,omitempty"` Host string `json:"host,omitempty"` Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` } func NewConfiguration() *Configuration { + defaultHeader := make(map[string]string) return &Configuration{ BasePath: "{{basePath}}", UserName: "", Debug: false, + DefaultHeader: defaultHeader, } +} + +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value } \ No newline at end of file diff --git a/samples/client/petstore/go/swagger/Configuration.go b/samples/client/petstore/go/swagger/Configuration.go index 7535db5e67f..fd20e992c08 100644 --- a/samples/client/petstore/go/swagger/Configuration.go +++ b/samples/client/petstore/go/swagger/Configuration.go @@ -14,12 +14,19 @@ type Configuration struct { BasePath string `json:"basePath,omitempty"` Host string `json:"host,omitempty"` Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` } func NewConfiguration() *Configuration { + defaultHeader := make(map[string]string) return &Configuration{ BasePath: "http://petstore.swagger.io/v2", UserName: "", Debug: false, + DefaultHeader: defaultHeader, } +} + +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value } \ No newline at end of file From ae3c628875e40ca218672f5b93f797976696cbdf Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 11 Apr 2016 10:37:50 -0700 Subject: [PATCH 2/4] issue#2534, added _sling.Set in the go api --- .../src/main/resources/go/api.mustache | 5 +++ samples/client/petstore/go/swagger/PetApi.go | 40 +++++++++++++++++++ .../client/petstore/go/swagger/StoreApi.go | 20 ++++++++++ samples/client/petstore/go/swagger/UserApi.go | 40 +++++++++++++++++++ 4 files changed, 105 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index d1cf877cd43..8aeb69c3dc3 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -50,6 +50,11 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{ _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + {{#hasQueryParams}} type QueryParams struct { {{#queryParams}}{{paramName}} {{dataType}} `url:"{{baseName}},omitempty"` {{/queryParams}} diff --git a/samples/client/petstore/go/swagger/PetApi.go b/samples/client/petstore/go/swagger/PetApi.go index 41353aac741..8f11ac5d207 100644 --- a/samples/client/petstore/go/swagger/PetApi.go +++ b/samples/client/petstore/go/swagger/PetApi.go @@ -45,6 +45,11 @@ func (a PetApi) AddPet (body Pet) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -107,6 +112,11 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -167,6 +177,11 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + type QueryParams struct { status []string `url:"status,omitempty"` } @@ -229,6 +244,11 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + type QueryParams struct { tags []string `url:"tags,omitempty"` } @@ -292,6 +312,11 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -350,6 +375,11 @@ func (a PetApi) UpdatePet (body Pet) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -413,6 +443,11 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -479,6 +514,11 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/json" } for key := range accepts { diff --git a/samples/client/petstore/go/swagger/StoreApi.go b/samples/client/petstore/go/swagger/StoreApi.go index 8d3e41e71e1..4719ce03144 100644 --- a/samples/client/petstore/go/swagger/StoreApi.go +++ b/samples/client/petstore/go/swagger/StoreApi.go @@ -45,6 +45,11 @@ func (a StoreApi) DeleteOrder (orderId string) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -102,6 +107,11 @@ func (a StoreApi) GetInventory () (map[string]int32, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/json" } for key := range accepts { @@ -161,6 +171,11 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -219,6 +234,11 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { diff --git a/samples/client/petstore/go/swagger/UserApi.go b/samples/client/petstore/go/swagger/UserApi.go index f8c8581aa3b..d85213b58f7 100644 --- a/samples/client/petstore/go/swagger/UserApi.go +++ b/samples/client/petstore/go/swagger/UserApi.go @@ -44,6 +44,11 @@ func (a UserApi) CreateUser (body User) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -104,6 +109,11 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -164,6 +174,11 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -225,6 +240,11 @@ func (a UserApi) DeleteUser (username string) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -284,6 +304,11 @@ func (a UserApi) GetUserByName (username string) (User, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -343,6 +368,11 @@ func (a UserApi) LoginUser (username string, password string) (string, error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + type QueryParams struct { username string `url:"username,omitempty"` password string `url:"password,omitempty"` @@ -405,6 +435,11 @@ func (a UserApi) LogoutUser () (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { @@ -465,6 +500,11 @@ func (a UserApi) UpdateUser (username string, body User) (error) { _sling = _sling.Path(path) + // add default headers if any + for key := range a.Configuration.DefaultHeader { + _sling = _sling.Set(key, a.Configuration.DefaultHeader[key]) + } + // accept header accepts := []string { "application/xml", "application/json" } for key := range accepts { From 9c455880b21dcb5ea48263751cd6c0c430a23c7b Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Mon, 11 Apr 2016 11:14:33 -0700 Subject: [PATCH 3/4] issue #2548, added docstring to Go model and its properties --- .../swagger-codegen/src/main/resources/go/model.mustache | 2 ++ samples/client/petstore/go/swagger/ApiResponse.go | 4 ++++ samples/client/petstore/go/swagger/Category.go | 3 +++ samples/client/petstore/go/swagger/Order.go | 7 +++++++ samples/client/petstore/go/swagger/Pet.go | 7 +++++++ samples/client/petstore/go/swagger/Tag.go | 3 +++ samples/client/petstore/go/swagger/User.go | 9 +++++++++ 7 files changed, 35 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/go/model.mustache b/modules/swagger-codegen/src/main/resources/go/model.mustache index 9045bea1ed2..4102299c5e9 100644 --- a/modules/swagger-codegen/src/main/resources/go/model.mustache +++ b/modules/swagger-codegen/src/main/resources/go/model.mustache @@ -7,8 +7,10 @@ import ( ) {{#model}} +{{#description}}// {{{description}}}{{/description}} type {{classname}} struct { {{#vars}} + {{#description}}// {{{description}}}{{/description}} {{name}} {{{datatype}}} `json:"{{baseName}},omitempty"` {{/vars}} } diff --git a/samples/client/petstore/go/swagger/ApiResponse.go b/samples/client/petstore/go/swagger/ApiResponse.go index 196af29c15d..abb7971189d 100644 --- a/samples/client/petstore/go/swagger/ApiResponse.go +++ b/samples/client/petstore/go/swagger/ApiResponse.go @@ -3,8 +3,12 @@ package swagger import ( ) + type ApiResponse struct { + Code int32 `json:"code,omitempty"` + Type_ string `json:"type,omitempty"` + Message string `json:"message,omitempty"` } diff --git a/samples/client/petstore/go/swagger/Category.go b/samples/client/petstore/go/swagger/Category.go index 1739a41f1eb..1853dfe7239 100644 --- a/samples/client/petstore/go/swagger/Category.go +++ b/samples/client/petstore/go/swagger/Category.go @@ -3,7 +3,10 @@ package swagger import ( ) + type Category struct { + Id int64 `json:"id,omitempty"` + Name string `json:"name,omitempty"` } diff --git a/samples/client/petstore/go/swagger/Order.go b/samples/client/petstore/go/swagger/Order.go index 8b9ddfeb212..a199bcc857d 100644 --- a/samples/client/petstore/go/swagger/Order.go +++ b/samples/client/petstore/go/swagger/Order.go @@ -4,11 +4,18 @@ 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"` + // Order Status Status string `json:"status,omitempty"` + Complete bool `json:"complete,omitempty"` } diff --git a/samples/client/petstore/go/swagger/Pet.go b/samples/client/petstore/go/swagger/Pet.go index d9faa1cb90f..32b9e6d97fc 100644 --- a/samples/client/petstore/go/swagger/Pet.go +++ b/samples/client/petstore/go/swagger/Pet.go @@ -3,11 +3,18 @@ package swagger 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"` + // pet status in the store Status string `json:"status,omitempty"` } diff --git a/samples/client/petstore/go/swagger/Tag.go b/samples/client/petstore/go/swagger/Tag.go index 77b55099c4a..7347106078a 100644 --- a/samples/client/petstore/go/swagger/Tag.go +++ b/samples/client/petstore/go/swagger/Tag.go @@ -3,7 +3,10 @@ package swagger import ( ) + type Tag struct { + Id int64 `json:"id,omitempty"` + Name string `json:"name,omitempty"` } diff --git a/samples/client/petstore/go/swagger/User.go b/samples/client/petstore/go/swagger/User.go index 03f0821252b..8f459db4674 100644 --- a/samples/client/petstore/go/swagger/User.go +++ b/samples/client/petstore/go/swagger/User.go @@ -3,13 +3,22 @@ package swagger 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"` + // User Status UserStatus int32 `json:"userStatus,omitempty"` } From 62401835452f44963392ff85b5b1160560fa506e Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 12 Apr 2016 10:41:59 +0800 Subject: [PATCH 4/4] update nodejs to nodejs-server --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c7ecb5758d..7c1bf779d32 100644 --- a/README.md +++ b/README.md @@ -565,7 +565,7 @@ You can also use the codegen to generate a server for a couple different framewo ``` java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i http://petstore.swagger.io/v2/swagger.json \ - -l nodejs \ + -l nodejs-server \ -o samples/server/petstore/nodejs ```