-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for #16787, minor format change
- Loading branch information
Showing
11 changed files
with
256 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* OpenAPI Petstore | ||
* | ||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package petstoreserver | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
// FakeAPIController binds http requests to an api service and writes the service results to the http response | ||
type FakeAPIController struct { | ||
service FakeAPIServicer | ||
errorHandler ErrorHandler | ||
} | ||
|
||
// FakeAPIOption for how the controller is set up. | ||
type FakeAPIOption func(*FakeAPIController) | ||
|
||
// WithFakeAPIErrorHandler inject ErrorHandler into controller | ||
func WithFakeAPIErrorHandler(h ErrorHandler) FakeAPIOption { | ||
return func(c *FakeAPIController) { | ||
c.errorHandler = h | ||
} | ||
} | ||
|
||
// NewFakeAPIController creates a default api controller | ||
func NewFakeAPIController(s FakeAPIServicer, opts ...FakeAPIOption) Router { | ||
controller := &FakeAPIController{ | ||
service: s, | ||
errorHandler: DefaultErrorHandler, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(controller) | ||
} | ||
|
||
return controller | ||
} | ||
|
||
// Routes returns all the api routes for the FakeAPIController | ||
func (c *FakeAPIController) Routes() Routes { | ||
return Routes{ | ||
"UploadFileArrayOfFiles": Route{ | ||
strings.ToUpper("Post"), | ||
"/v2/fake/uploadImage/array of_file", | ||
c.UploadFileArrayOfFiles, | ||
}, | ||
} | ||
} | ||
|
||
// UploadFileArrayOfFiles - uploads images (array of files0 | ||
func (c *FakeAPIController) UploadFileArrayOfFiles(w http.ResponseWriter, r *http.Request) { | ||
if err := r.ParseMultipartForm(32 << 20); err != nil { | ||
c.errorHandler(w, r, &ParsingError{Err: err}, nil) | ||
return | ||
} | ||
params := mux.Vars(r) | ||
petIdParam, err := parseNumericParameter[int64]( | ||
params["petId"], | ||
WithRequire[int64](parseInt64), | ||
) | ||
if err != nil { | ||
c.errorHandler(w, r, &ParsingError{Err: err}, nil) | ||
return | ||
} | ||
|
||
|
||
additionalMetadataParam := r.FormValue("additionalMetadata") | ||
filesParam, err := ReadFormFilesToTempFiles(r, "files") | ||
if err != nil { | ||
c.errorHandler(w, r, &ParsingError{Err: err}, nil) | ||
return | ||
} | ||
|
||
|
||
result, err := c.service.UploadFileArrayOfFiles(r.Context(), petIdParam, additionalMetadataParam, filesParam) | ||
// If an error occurred, encode the error with the status code | ||
if err != nil { | ||
c.errorHandler(w, r, err, &result) | ||
return | ||
} | ||
// If no error, encode the body and the result code | ||
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) | ||
} |
39 changes: 39 additions & 0 deletions
39
samples/server/petstore/go-api-server/go/api_fake_service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* OpenAPI Petstore | ||
* | ||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package petstoreserver | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"errors" | ||
"os" | ||
) | ||
|
||
// FakeAPIService is a service that implements the logic for the FakeAPIServicer | ||
// This service should implement the business logic for every endpoint for the FakeAPI API. | ||
// Include any external packages or services that will be required by this service. | ||
type FakeAPIService struct { | ||
} | ||
|
||
// NewFakeAPIService creates a default api service | ||
func NewFakeAPIService() FakeAPIServicer { | ||
return &FakeAPIService{} | ||
} | ||
|
||
// UploadFileArrayOfFiles - uploads images (array of files0 | ||
func (s *FakeAPIService) UploadFileArrayOfFiles(ctx context.Context, petId int64, additionalMetadata string, files []*os.File) (ImplResponse, error) { | ||
// TODO - update UploadFileArrayOfFiles with the required logic for this service method. | ||
// Add api_fake_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. | ||
|
||
// TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ... | ||
// return Response(200, ApiResponse{}), nil | ||
|
||
return Response(http.StatusNotImplemented, nil), errors.New("UploadFileArrayOfFiles method not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters