Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed Mar 23, 2022
1 parent 1cd72ae commit 965ca27
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 117 deletions.
16 changes: 8 additions & 8 deletions cmd/internal/openapi/v3/codegen/testdata/test/pageclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (receiver *PageClient) SetClient(client *resty.Client) {
receiver.client = client
}

// PostPageUsers2 PageUsers2 demonstrate how to define POST and Content-Type as application/json api
func (receiver *PageClient) PostPageUsers2(ctx context.Context, _headers map[string]string,
// PostPageUsers PageUsers demonstrate how to define POST and Content-Type as application/json api
func (receiver *PageClient) PostPageUsers(ctx context.Context, _headers map[string]string,
// comments above input and output struct type parameters in vo package will display on online document
// not comments here
bodyJSON *PageQuery) (ret PageUsers2Resp, _resp *resty.Response, err error) {
bodyJSON PageQuery) (ret PageUsersResp, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
Expand All @@ -46,7 +46,7 @@ func (receiver *PageClient) PostPageUsers2(ctx context.Context, _headers map[str
}
_req.SetBody(bodyJSON)

_resp, _err = _req.Post("/page/users/2")
_resp, _err = _req.Post("/page/users")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand All @@ -62,11 +62,11 @@ func (receiver *PageClient) PostPageUsers2(ctx context.Context, _headers map[str
return
}

// PostPageUsers PageUsers demonstrate how to define POST and Content-Type as application/json api
func (receiver *PageClient) PostPageUsers(ctx context.Context, _headers map[string]string,
// PostPageUsers2 PageUsers2 demonstrate how to define POST and Content-Type as application/json api
func (receiver *PageClient) PostPageUsers2(ctx context.Context, _headers map[string]string,
// comments above input and output struct type parameters in vo package will display on online document
// not comments here
bodyJSON PageQuery) (ret PageUsersResp, _resp *resty.Response, err error) {
bodyJSON *PageQuery) (ret PageUsers2Resp, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
Expand All @@ -76,7 +76,7 @@ func (receiver *PageClient) PostPageUsers(ctx context.Context, _headers map[stri
}
_req.SetBody(bodyJSON)

_resp, _err = _req.Post("/page/users")
_resp, _err = _req.Post("/page/users/2")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand Down
74 changes: 37 additions & 37 deletions cmd/internal/openapi/v3/codegen/testdata/test/petclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,6 @@ func (receiver *PetClient) SetClient(client *resty.Client) {
receiver.client = client
}

// GetPetFindByStatus Finds Pets by status
// Multiple status values can be provided with comma separated strings
func (receiver *PetClient) GetPetFindByStatus(ctx context.Context, _headers map[string]string,
queryParams *struct {
Status *string `json:"status,omitempty" url:"status"`
}) (ret []Pet, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
_req.SetContext(ctx)
if len(_headers) > 0 {
_req.SetHeaders(_headers)
}
_queryParams, _ := _querystring.Values(queryParams)
_req.SetQueryParamsFromValues(_queryParams)

_resp, _err = _req.Get("/pet/findByStatus")
if _err != nil {
err = errors.Wrap(_err, "")
return
}
if _resp.IsError() {
err = errors.New(_resp.String())
return
}
if _err = json.Unmarshal(_resp.Body(), &ret); _err != nil {
err = errors.Wrap(_err, "")
return
}
return
}

// GetPetPetId Find pet by ID
// Returns a single pet
func (receiver *PetClient) GetPetPetId(ctx context.Context, _headers map[string]string,
Expand Down Expand Up @@ -136,11 +104,11 @@ func (receiver *PetClient) PostPetPetIdUploadImage(ctx context.Context, _headers
return
}

// GetPetFindByTags Finds Pets by tags
// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
func (receiver *PetClient) GetPetFindByTags(ctx context.Context, _headers map[string]string,
// GetPetFindByStatus Finds Pets by status
// Multiple status values can be provided with comma separated strings
func (receiver *PetClient) GetPetFindByStatus(ctx context.Context, _headers map[string]string,
queryParams *struct {
Tags *[]string `json:"tags,omitempty" url:"tags"`
Status *string `json:"status,omitempty" url:"status"`
}) (ret []Pet, _resp *resty.Response, err error) {
var _err error

Expand All @@ -152,7 +120,7 @@ func (receiver *PetClient) GetPetFindByTags(ctx context.Context, _headers map[st
_queryParams, _ := _querystring.Values(queryParams)
_req.SetQueryParamsFromValues(_queryParams)

_resp, _err = _req.Get("/pet/findByTags")
_resp, _err = _req.Get("/pet/findByStatus")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand Down Expand Up @@ -226,6 +194,38 @@ func (receiver *PetClient) PutPet(ctx context.Context, _headers map[string]strin
return
}

// GetPetFindByTags Finds Pets by tags
// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
func (receiver *PetClient) GetPetFindByTags(ctx context.Context, _headers map[string]string,
queryParams *struct {
Tags *[]string `json:"tags,omitempty" url:"tags"`
}) (ret []Pet, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
_req.SetContext(ctx)
if len(_headers) > 0 {
_req.SetHeaders(_headers)
}
_queryParams, _ := _querystring.Values(queryParams)
_req.SetQueryParamsFromValues(_queryParams)

_resp, _err = _req.Get("/pet/findByTags")
if _err != nil {
err = errors.Wrap(_err, "")
return
}
if _resp.IsError() {
err = errors.New(_resp.String())
return
}
if _err = json.Unmarshal(_resp.Body(), &ret); _err != nil {
err = errors.Wrap(_err, "")
return
}
return
}

func NewPet(opts ...ddhttp.DdClientOption) *PetClient {
defaultProvider := ddhttp.NewServiceProvider("PET")
defaultClient := ddhttp.NewClient()
Expand Down
38 changes: 19 additions & 19 deletions cmd/internal/openapi/v3/codegen/testdata/test/storeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ func (receiver *StoreClient) SetClient(client *resty.Client) {
receiver.client = client
}

// PostStoreOrder Place an order for a pet
// Place a new order in the store
func (receiver *StoreClient) PostStoreOrder(ctx context.Context, _headers map[string]string,
bodyJSON *Order) (ret Order, _resp *resty.Response, err error) {
// GetStoreInventory Returns pet inventories by status
// Returns a map of status codes to quantities
func (receiver *StoreClient) GetStoreInventory(ctx context.Context, _headers map[string]string) (ret struct {
}, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
_req.SetContext(ctx)
if len(_headers) > 0 {
_req.SetHeaders(_headers)
}
_req.SetBody(bodyJSON)

_resp, _err = _req.Post("/store/order")
_resp, _err = _req.Get("/store/inventory")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand All @@ -61,22 +60,20 @@ func (receiver *StoreClient) PostStoreOrder(ctx context.Context, _headers map[st
return
}

// GetStoreOrderOrderId Find purchase order by ID
// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
func (receiver *StoreClient) GetStoreOrderOrderId(ctx context.Context, _headers map[string]string,
// ID of order that needs to be fetched
// required
orderId int64) (ret Order, _resp *resty.Response, err error) {
// PostStoreOrder Place an order for a pet
// Place a new order in the store
func (receiver *StoreClient) PostStoreOrder(ctx context.Context, _headers map[string]string,
bodyJSON *Order) (ret Order, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
_req.SetContext(ctx)
if len(_headers) > 0 {
_req.SetHeaders(_headers)
}
_req.SetPathParam("orderId", fmt.Sprintf("%v", orderId))
_req.SetBody(bodyJSON)

_resp, _err = _req.Get("/store/order/{orderId}")
_resp, _err = _req.Post("/store/order")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand All @@ -92,19 +89,22 @@ func (receiver *StoreClient) GetStoreOrderOrderId(ctx context.Context, _headers
return
}

// GetStoreInventory Returns pet inventories by status
// Returns a map of status codes to quantities
func (receiver *StoreClient) GetStoreInventory(ctx context.Context, _headers map[string]string) (ret struct {
}, _resp *resty.Response, err error) {
// GetStoreOrderOrderId Find purchase order by ID
// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
func (receiver *StoreClient) GetStoreOrderOrderId(ctx context.Context, _headers map[string]string,
// ID of order that needs to be fetched
// required
orderId int64) (ret Order, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
_req.SetContext(ctx)
if len(_headers) > 0 {
_req.SetHeaders(_headers)
}
_req.SetPathParam("orderId", fmt.Sprintf("%v", orderId))

_resp, _err = _req.Get("/store/inventory")
_resp, _err = _req.Get("/store/order/{orderId}")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/openapi/v3/codegen/testdata/test/unipayclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func (receiver *UnipayClient) SetClient(client *resty.Client) {
}
func (receiver *UnipayClient) GetUnipayStartUnionPay(ctx context.Context, _headers map[string]string,
queryParams struct {
// required
CompanyId string `json:"companyId,omitempty" url:"companyId"`
// required
FrontUrl string `json:"frontUrl,omitempty" url:"frontUrl"`
// required
TxnAmt string `json:"txnAmt,omitempty" url:"txnAmt"`
// required
Token string `json:"token,omitempty" url:"token"`
// required
CompanyId string `json:"companyId,omitempty" url:"companyId"`
// required
FrontUrl string `json:"frontUrl,omitempty" url:"frontUrl"`
}) (ret string, _resp *resty.Response, err error) {
var _err error

Expand Down
34 changes: 17 additions & 17 deletions cmd/internal/openapi/v3/codegen/testdata/test/uploadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ func (receiver *UploadClient) SetClient(client *resty.Client) {
receiver.client = client
}

// PostUploadAvatar2 UploadAvatar2 demonstrate how to define upload files api
// PostUploadAvatar UploadAvatar demonstrate how to define upload files api
// there must be one []v3.FileModel or v3.FileModel parameter among input parameters
// remember to close the readers by Close method of v3.FileModel if you don't need them anymore when you finished your own business logic
func (receiver *UploadClient) PostUploadAvatar2(ctx context.Context, _headers map[string]string,
func (receiver *UploadClient) PostUploadAvatar(ctx context.Context, _headers map[string]string,
bodyParams struct {
// required
Ps string `json:"ps,omitempty" url:"ps"`
},
pf3 *v3.FileModel,
pf []v3.FileModel,
pf2 *v3.FileModel) (ret UploadAvatar2Resp, _resp *resty.Response, err error) {
pf []v3.FileModel) (ret UploadAvatarResp, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
Expand All @@ -53,21 +52,15 @@ func (receiver *UploadClient) PostUploadAvatar2(ctx context.Context, _headers ma
}
_bodyParams, _ := _querystring.Values(bodyParams)
_req.SetFormDataFromValues(_bodyParams)
if pf3 != nil {
_req.SetFileReader("pf3", pf3.Filename, pf3.Reader)
}
if len(pf) == 0 {
err = errors.New("at least one file should be uploaded for parameter pf")
return
}
for _, _f := range pf {
_req.SetFileReader("pf", _f.Filename, _f.Reader)
}
if pf2 != nil {
_req.SetFileReader("pf2", pf2.Filename, pf2.Reader)
}

_resp, _err = _req.Post("/upload/avatar/2")
_resp, _err = _req.Post("/upload/avatar")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand All @@ -83,15 +76,16 @@ func (receiver *UploadClient) PostUploadAvatar2(ctx context.Context, _headers ma
return
}

// PostUploadAvatar UploadAvatar demonstrate how to define upload files api
// there must be one []v3.FileModel or v3.FileModel parameter among input parameters
// PostUploadAvatar2 UploadAvatar2 demonstrate how to define upload files api
// remember to close the readers by Close method of v3.FileModel if you don't need them anymore when you finished your own business logic
func (receiver *UploadClient) PostUploadAvatar(ctx context.Context, _headers map[string]string,
func (receiver *UploadClient) PostUploadAvatar2(ctx context.Context, _headers map[string]string,
bodyParams struct {
// required
Ps string `json:"ps,omitempty" url:"ps"`
},
pf []v3.FileModel) (ret UploadAvatarResp, _resp *resty.Response, err error) {
pf []v3.FileModel,
pf2 *v3.FileModel,
pf3 *v3.FileModel) (ret UploadAvatar2Resp, _resp *resty.Response, err error) {
var _err error

_req := receiver.client.R()
Expand All @@ -108,8 +102,14 @@ func (receiver *UploadClient) PostUploadAvatar(ctx context.Context, _headers map
for _, _f := range pf {
_req.SetFileReader("pf", _f.Filename, _f.Reader)
}
if pf2 != nil {
_req.SetFileReader("pf2", pf2.Filename, pf2.Reader)
}
if pf3 != nil {
_req.SetFileReader("pf3", pf3.Filename, pf3.Reader)
}

_resp, _err = _req.Post("/upload/avatar")
_resp, _err = _req.Post("/upload/avatar/2")
if _err != nil {
err = errors.Wrap(_err, "")
return
Expand Down
Loading

0 comments on commit 965ca27

Please sign in to comment.