diff --git a/.gitignore b/.gitignore index ab086a35e06..9f893291374 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,8 @@ nb-configuration.xml /target /generated-files test-output/ +nbactions.xml +test-output/ # website website/build/ @@ -71,6 +73,7 @@ samples/client/petstore/build samples/client/petstore/cpp-qt/PetStore/moc_* samples/client/petstore/cpp-qt/PetStore/*.o samples/client/petstore/cpp-qt/build-* +samples/client/petstore/cpp-qt/build-* samples/client/petstore/cpp-qt/PetStore/PetStore samples/client/petstore/cpp-qt/PetStore/Makefile samples/client/petstore/cpp-qt/PetStore/PetStore.pro.user @@ -97,7 +100,9 @@ samples/client/petstore/java/jersey2/build/ samples/client/petstore/java/okhttp-gson/.gradle/ samples/client/petstore/java/okhttp-gson/build/ samples/client/petstore/java/feign/build/ +samples/client/petstore/java/feign10x/build/ samples/client/petstore/java/feign/project/ +samples/client/petstore/java/feign10x/project/ samples/client/petstore/java/retrofit/build/ samples/client/petstore/java/retrofit2/build/ samples/client/petstore/java/retrofit2/hello.txt @@ -105,6 +110,7 @@ samples/client/petstore/java/retrofit2rx/build/ samples/client/petstore/java/default/build/ samples/client/petstore/scala/build/ samples/client/petstore/java/resttemplate/hello.txt +samples/client/petstore/java/retrofit2/hello.txt samples/client/petstore/java/feign/hello.txt samples/client/petstore/java/jersey2-java6/project/ samples/client/petstore/java/jersey2-java8/project/ @@ -187,7 +193,6 @@ samples/server/petstore/php-slim4/composer.lock samples/server/petstore/php-symfony/SymfonyBundle-php/composer.lock samples/server/petstore/php-mezzio-ph/composer.lock samples/server/petstore/php-mezzio-ph-modern/composer.lock -samples/client/petstore/php-nextgen/OpenAPIClient-php/.phplint.cache/ # ts samples/client/petstore/typescript-angular2/npm/npm-debug.log diff --git a/modules/openapi-generator/src/main/resources/go-server/routers.mustache b/modules/openapi-generator/src/main/resources/go-server/routers.mustache index d773a47f01a..ca06cca97ac 100644 --- a/modules/openapi-generator/src/main/resources/go-server/routers.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/routers.mustache @@ -89,18 +89,33 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi} // EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code func EncodeJSONResponse(i interface{}, status *int,{{#addResponseHeaders}} headers map[string][]string,{{/addResponseHeaders}} w http.ResponseWriter) error { - {{#addResponseHeaders}} wHeader := w.Header() + {{#addResponseHeaders}} for key, values := range headers { for _, value := range values { wHeader.Add(key, value) } } + {{/addResponseHeaders}} + + f, ok := i.(*os.File) + if ok { + data, err := io.ReadAll(f) + if err != nil { + return err + } + wHeader.Set("Content-Type", http.DetectContentType(data)) + wHeader.Set("Content-Disposition", "attachment; filename="+f.Name()) + if status != nil { + w.WriteHeader(*status) + } else { + w.WriteHeader(http.StatusOK) + } + _, err = w.Write(data) + return err + } wHeader.Set("Content-Type", "application/json; charset=UTF-8") - {{/addResponseHeaders}} - {{^addResponseHeaders}} - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - {{/addResponseHeaders}} + if status != nil { w.WriteHeader(*status) } else { diff --git a/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml index f28f075a495..26a1f081695 100644 --- a/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml @@ -332,6 +332,32 @@ paths: description: file to upload type: string format: binary + get: + tags: + - pet + summary: Returns the image for the Pet that has been previously uploaded + description: Returns the image for the Pet that has been previously uploaded + operationId: getPetImageById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + image/jpeg: + schema: + type: string + format: binary + '400': + description: Invalid ID supplied + '404': + description: Pet not found /store/inventory: get: tags: diff --git a/samples/openapi3/server/petstore/go/go-petstore/go/routers.go b/samples/openapi3/server/petstore/go/go-petstore/go/routers.go index f45a21ded89..4e6f1007f44 100644 --- a/samples/openapi3/server/petstore/go/go-petstore/go/routers.go +++ b/samples/openapi3/server/petstore/go/go-petstore/go/routers.go @@ -64,7 +64,25 @@ func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, wHeader.Add(key, value) } } + + f, ok := i.(*os.File) + if ok { + data, err := io.ReadAll(f) + if err != nil { + return err + } + wHeader.Set("Content-Type", http.DetectContentType(data)) + wHeader.Set("Content-Disposition", "attachment; filename="+f.Name()) + if status != nil { + w.WriteHeader(*status) + } else { + w.WriteHeader(http.StatusOK) + } + _, err = w.Write(data) + return err + } wHeader.Set("Content-Type", "application/json; charset=UTF-8") + if status != nil { w.WriteHeader(*status) } else { diff --git a/samples/server/petstore/go-api-server/api/openapi.yaml b/samples/server/petstore/go-api-server/api/openapi.yaml index 88e07777510..701dca72075 100644 --- a/samples/server/petstore/go-api-server/api/openapi.yaml +++ b/samples/server/petstore/go-api-server/api/openapi.yaml @@ -298,6 +298,34 @@ paths: tags: - pet /pet/{petId}/uploadImage: + get: + description: Returns the image for the Pet that has been previously uploaded + operationId: getPetImageById + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + image/jpeg: + schema: + format: binary + type: string + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + summary: Returns the image for the Pet that has been previously uploaded + tags: + - pet post: description: "" operationId: uploadFile diff --git a/samples/server/petstore/go-api-server/go/api.go b/samples/server/petstore/go-api-server/go/api.go index 18ab08d8f26..4e99b1fe232 100644 --- a/samples/server/petstore/go-api-server/go/api.go +++ b/samples/server/petstore/go-api-server/go/api.go @@ -28,6 +28,7 @@ type PetAPIRouter interface { // Deprecated FindPetsByTags(http.ResponseWriter, *http.Request) GetPetById(http.ResponseWriter, *http.Request) + GetPetImageById(http.ResponseWriter, *http.Request) UpdatePet(http.ResponseWriter, *http.Request) UpdatePetWithForm(http.ResponseWriter, *http.Request) UploadFile(http.ResponseWriter, *http.Request) @@ -69,6 +70,7 @@ type PetAPIServicer interface { // Deprecated FindPetsByTags(context.Context, []string) (ImplResponse, error) GetPetById(context.Context, int64) (ImplResponse, error) + GetPetImageById(context.Context, int64) (ImplResponse, error) UpdatePet(context.Context, Pet) (ImplResponse, error) UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error) UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error) diff --git a/samples/server/petstore/go-api-server/go/api_pet.go b/samples/server/petstore/go-api-server/go/api_pet.go index 10ea4d6870c..f283133bc65 100644 --- a/samples/server/petstore/go-api-server/go/api_pet.go +++ b/samples/server/petstore/go-api-server/go/api_pet.go @@ -80,6 +80,11 @@ func (c *PetAPIController) Routes() Routes { "/v2/pet/{petId}", c.GetPetById, }, + "GetPetImageById": Route{ + strings.ToUpper("Get"), + "/v2/pet/{petId}/uploadImage", + c.GetPetImageById, + }, "UpdatePet": Route{ strings.ToUpper("Put"), "/v2/pet", @@ -249,6 +254,27 @@ func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// GetPetImageById - Returns the image for the Pet that has been previously uploaded +func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Request) { + 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 + } + result, err := c.service.GetPetImageById(r.Context(), petIdParam) + // 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) +} + // UpdatePet - Update an existing pet func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { petParam := Pet{} diff --git a/samples/server/petstore/go-api-server/go/api_pet_service.go b/samples/server/petstore/go-api-server/go/api_pet_service.go index 1d54529fb94..5987c4bed62 100644 --- a/samples/server/petstore/go-api-server/go/api_pet_service.go +++ b/samples/server/petstore/go-api-server/go/api_pet_service.go @@ -112,6 +112,23 @@ func (s *PetAPIService) GetPetById(ctx context.Context, petId int64) (ImplRespon return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") } +// GetPetImageById - Returns the image for the Pet that has been previously uploaded +func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplResponse, error) { + // TODO - update GetPetImageById with the required logic for this service method. + // Add api_pet_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, *os.File{}) or use other options such as http.Ok ... + // return Response(200, *os.File{}), nil + + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil + + // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil + + return Response(http.StatusNotImplemented, nil), errors.New("GetPetImageById method not implemented") +} + // UpdatePet - Update an existing pet func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { // TODO - update UpdatePet with the required logic for this service method. diff --git a/samples/server/petstore/go-api-server/go/routers.go b/samples/server/petstore/go-api-server/go/routers.go index 1c88898e9e6..ec25be4df67 100644 --- a/samples/server/petstore/go-api-server/go/routers.go +++ b/samples/server/petstore/go-api-server/go/routers.go @@ -68,7 +68,25 @@ func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, wHeader.Add(key, value) } } + + f, ok := i.(*os.File) + if ok { + data, err := io.ReadAll(f) + if err != nil { + return err + } + wHeader.Set("Content-Type", http.DetectContentType(data)) + wHeader.Set("Content-Disposition", "attachment; filename="+f.Name()) + if status != nil { + w.WriteHeader(*status) + } else { + w.WriteHeader(http.StatusOK) + } + _, err = w.Write(data) + return err + } wHeader.Set("Content-Type", "application/json; charset=UTF-8") + if status != nil { w.WriteHeader(*status) } else { diff --git a/samples/server/petstore/go-chi-server/api/openapi.yaml b/samples/server/petstore/go-chi-server/api/openapi.yaml index 88e07777510..701dca72075 100644 --- a/samples/server/petstore/go-chi-server/api/openapi.yaml +++ b/samples/server/petstore/go-chi-server/api/openapi.yaml @@ -298,6 +298,34 @@ paths: tags: - pet /pet/{petId}/uploadImage: + get: + description: Returns the image for the Pet that has been previously uploaded + operationId: getPetImageById + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + image/jpeg: + schema: + format: binary + type: string + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + summary: Returns the image for the Pet that has been previously uploaded + tags: + - pet post: description: "" operationId: uploadFile diff --git a/samples/server/petstore/go-chi-server/go/api.go b/samples/server/petstore/go-chi-server/go/api.go index 18ab08d8f26..4e99b1fe232 100644 --- a/samples/server/petstore/go-chi-server/go/api.go +++ b/samples/server/petstore/go-chi-server/go/api.go @@ -28,6 +28,7 @@ type PetAPIRouter interface { // Deprecated FindPetsByTags(http.ResponseWriter, *http.Request) GetPetById(http.ResponseWriter, *http.Request) + GetPetImageById(http.ResponseWriter, *http.Request) UpdatePet(http.ResponseWriter, *http.Request) UpdatePetWithForm(http.ResponseWriter, *http.Request) UploadFile(http.ResponseWriter, *http.Request) @@ -69,6 +70,7 @@ type PetAPIServicer interface { // Deprecated FindPetsByTags(context.Context, []string) (ImplResponse, error) GetPetById(context.Context, int64) (ImplResponse, error) + GetPetImageById(context.Context, int64) (ImplResponse, error) UpdatePet(context.Context, Pet) (ImplResponse, error) UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error) UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error) diff --git a/samples/server/petstore/go-chi-server/go/api_pet.go b/samples/server/petstore/go-chi-server/go/api_pet.go index e780ab1af29..d01736abbf3 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet.go +++ b/samples/server/petstore/go-chi-server/go/api_pet.go @@ -80,6 +80,11 @@ func (c *PetAPIController) Routes() Routes { "/v2/pet/{petId}", c.GetPetById, }, + "GetPetImageById": Route{ + strings.ToUpper("Get"), + "/v2/pet/{petId}/uploadImage", + c.GetPetImageById, + }, "UpdatePet": Route{ strings.ToUpper("Put"), "/v2/pet", @@ -246,6 +251,26 @@ func (c *PetAPIController) GetPetById(w http.ResponseWriter, r *http.Request) { EncodeJSONResponse(result.Body, &result.Code, result.Headers, w) } +// GetPetImageById - Returns the image for the Pet that has been previously uploaded +func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Request) { + petIdParam, err := parseNumericParameter[int64]( + chi.URLParam(r, "petId"), + WithRequire[int64](parseInt64), + ) + if err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + result, err := c.service.GetPetImageById(r.Context(), petIdParam) + // 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) +} + // UpdatePet - Update an existing pet func (c *PetAPIController) UpdatePet(w http.ResponseWriter, r *http.Request) { petParam := Pet{} diff --git a/samples/server/petstore/go-chi-server/go/api_pet_service.go b/samples/server/petstore/go-chi-server/go/api_pet_service.go index 1d54529fb94..5987c4bed62 100644 --- a/samples/server/petstore/go-chi-server/go/api_pet_service.go +++ b/samples/server/petstore/go-chi-server/go/api_pet_service.go @@ -112,6 +112,23 @@ func (s *PetAPIService) GetPetById(ctx context.Context, petId int64) (ImplRespon return Response(http.StatusNotImplemented, nil), errors.New("GetPetById method not implemented") } +// GetPetImageById - Returns the image for the Pet that has been previously uploaded +func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplResponse, error) { + // TODO - update GetPetImageById with the required logic for this service method. + // Add api_pet_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, *os.File{}) or use other options such as http.Ok ... + // return Response(200, *os.File{}), nil + + // TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ... + // return Response(400, nil),nil + + // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil + + return Response(http.StatusNotImplemented, nil), errors.New("GetPetImageById method not implemented") +} + // UpdatePet - Update an existing pet func (s *PetAPIService) UpdatePet(ctx context.Context, pet Pet) (ImplResponse, error) { // TODO - update UpdatePet with the required logic for this service method. diff --git a/samples/server/petstore/go-chi-server/go/routers.go b/samples/server/petstore/go-chi-server/go/routers.go index f45a21ded89..4e6f1007f44 100644 --- a/samples/server/petstore/go-chi-server/go/routers.go +++ b/samples/server/petstore/go-chi-server/go/routers.go @@ -64,7 +64,25 @@ func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, wHeader.Add(key, value) } } + + f, ok := i.(*os.File) + if ok { + data, err := io.ReadAll(f) + if err != nil { + return err + } + wHeader.Set("Content-Type", http.DetectContentType(data)) + wHeader.Set("Content-Disposition", "attachment; filename="+f.Name()) + if status != nil { + w.WriteHeader(*status) + } else { + w.WriteHeader(http.StatusOK) + } + _, err = w.Write(data) + return err + } wHeader.Set("Content-Type", "application/json; charset=UTF-8") + if status != nil { w.WriteHeader(*status) } else {