Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ nb-configuration.xml
/target
/generated-files
test-output/
nbactions.xml
test-output/

# website
website/build/
Expand All @@ -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
Expand All @@ -97,14 +100,17 @@ 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
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/
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8")
{{/addResponseHeaders}}
{{^addResponseHeaders}}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
{{/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")

if status != nil {
w.WriteHeader(*status)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,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:
Expand Down
18 changes: 18 additions & 0 deletions samples/openapi3/server/petstore/go/go-petstore/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions samples/server/petstore/go-api-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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
Expand Down
2 changes: 2 additions & 0 deletions samples/server/petstore/go-api-server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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)
Expand Down Expand Up @@ -67,6 +68,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)
Expand Down
26 changes: 26 additions & 0 deletions samples/server/petstore/go-api-server/go/api_pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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",
Expand Down Expand Up @@ -197,6 +202,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{}
Expand Down
17 changes: 17 additions & 0 deletions samples/server/petstore/go-api-server/go/api_pet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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.
Expand Down
18 changes: 18 additions & 0 deletions samples/server/petstore/go-api-server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions samples/server/petstore/go-chi-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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
Expand Down
2 changes: 2 additions & 0 deletions samples/server/petstore/go-chi-server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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)
Expand Down Expand Up @@ -67,6 +68,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)
Expand Down
25 changes: 25 additions & 0 deletions samples/server/petstore/go-chi-server/go/api_pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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",
Expand Down Expand Up @@ -195,6 +200,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{}
Expand Down
17 changes: 17 additions & 0 deletions samples/server/petstore/go-chi-server/go/api_pet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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.
Expand Down
Loading