Skip to content

Commit

Permalink
Regenerate the api files with openapitool v6.6.0 and changes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
Co-authored-by: Armel Soro <[email protected]>
  • Loading branch information
valaparthvi and rm3l committed Jun 19, 2023
1 parent 92f4106 commit 00844bb
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 407 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ test-doc-automation:

# Generate OpenAPISpec library based on ododevapispec.yaml inside pkg/apiserver-gen; this will only generate interfaces
# Actual implementation must be done inside pkg/apiserver-impl
# Apart from generating the files, this target also formats the generated files
# and removes openapi.yaml to avoid any confusion regarding ododevapispec.yaml file and which file to use.
.PHONY: generate-apiserver
generate-apiserver: ## Generate OpenAPISpec library based on ododevapispec.yaml inside pkg/apiserver-gen; also go fmt the files
generate-apiserver: ## Generate OpenAPISpec library based on ododevapispec.yaml inside pkg/apiserver-gen
podman run --rm \
-v ${PWD}:/local \
docker.io/openapitools/openapi-generator-cli:v6.6.0 \
Expand All @@ -242,5 +244,5 @@ generate-apiserver: ## Generate OpenAPISpec library based on ododevapispec.yaml
-g go-server \
-o /local/pkg/apiserver-gen \
--additional-properties=outputAsLibrary=true,onlyInterfaces=true,hideGenerationTimestamp=true && \
echo "Formatting generated files:" && \
go fmt ./pkg/apiserver-gen/...
echo "Formatting generated files:" && go fmt ./pkg/apiserver-gen/... && \
echo "Removing pkg/apiserver-gen/api/openapi.yaml" && rm ./pkg/apiserver-gen/api/openapi.yaml
2 changes: 1 addition & 1 deletion pkg/apiserver-gen/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0-SNAPSHOT
6.6.0
1 change: 0 additions & 1 deletion pkg/apiserver-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ To see how to make this your own, look here:
[README](https://openapi-generator.tech)

- API version: 0.1
- Build date: 2023-06-12T03:51:38.118965Z[Etc/UTC]


### Running the server
Expand Down
184 changes: 0 additions & 184 deletions pkg/apiserver-gen/api/openapi.yaml

This file was deleted.

12 changes: 6 additions & 6 deletions pkg/apiserver-gen/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ import (
"net/http"
)

// DefaultAPIRouter defines the required methods for binding the api requests to a responses for the DefaultAPI
// The DefaultAPIRouter implementation should parse necessary information from the http request,
// pass the data to a DefaultAPIServicer to perform the required actions, then write the service results to the http response.
type DefaultAPIRouter interface {
// DefaultApiRouter defines the required methods for binding the api requests to a responses for the DefaultApi
// The DefaultApiRouter implementation should parse necessary information from the http request,
// pass the data to a DefaultApiServicer to perform the required actions, then write the service results to the http response.
type DefaultApiRouter interface {
ComponentCommandPost(http.ResponseWriter, *http.Request)
ComponentGet(http.ResponseWriter, *http.Request)
InstanceDelete(http.ResponseWriter, *http.Request)
InstanceGet(http.ResponseWriter, *http.Request)
}

// DefaultAPIServicer defines the api actions for the DefaultAPI service
// DefaultApiServicer defines the api actions for the DefaultApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type DefaultAPIServicer interface {
type DefaultApiServicer interface {
ComponentCommandPost(context.Context, ComponentCommandPostRequest) (ImplResponse, error)
ComponentGet(context.Context) (ImplResponse, error)
InstanceDelete(context.Context) (ImplResponse, error)
Expand Down
54 changes: 29 additions & 25 deletions pkg/apiserver-gen/go/api_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ import (
"strings"
)

// DefaultAPIController binds http requests to an api service and writes the service results to the http response
type DefaultAPIController struct {
service DefaultAPIServicer
// DefaultApiController binds http requests to an api service and writes the service results to the http response
type DefaultApiController struct {
service DefaultApiServicer
errorHandler ErrorHandler
}

// DefaultAPIOption for how the controller is set up.
type DefaultAPIOption func(*DefaultAPIController)
// DefaultApiOption for how the controller is set up.
type DefaultApiOption func(*DefaultApiController)

// WithDefaultAPIErrorHandler inject ErrorHandler into controller
func WithDefaultAPIErrorHandler(h ErrorHandler) DefaultAPIOption {
return func(c *DefaultAPIController) {
// WithDefaultApiErrorHandler inject ErrorHandler into controller
func WithDefaultApiErrorHandler(h ErrorHandler) DefaultApiOption {
return func(c *DefaultApiController) {
c.errorHandler = h
}
}

// NewDefaultAPIController creates a default api controller
func NewDefaultAPIController(s DefaultAPIServicer, opts ...DefaultAPIOption) Router {
controller := &DefaultAPIController{
// NewDefaultApiController creates a default api controller
func NewDefaultApiController(s DefaultApiServicer, opts ...DefaultApiOption) Router {
controller := &DefaultApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
Expand All @@ -45,25 +45,29 @@ func NewDefaultAPIController(s DefaultAPIServicer, opts ...DefaultAPIOption) Rou
return controller
}

// Routes returns all the api routes for the DefaultAPIController
func (c *DefaultAPIController) Routes() Routes {
// Routes returns all the api routes for the DefaultApiController
func (c *DefaultApiController) Routes() Routes {
return Routes{
"ComponentCommandPost": Route{
{
"ComponentCommandPost",
strings.ToUpper("Post"),
"/api/v1/component/command",
c.ComponentCommandPost,
},
"ComponentGet": Route{
{
"ComponentGet",
strings.ToUpper("Get"),
"/api/v1/component",
c.ComponentGet,
},
"InstanceDelete": Route{
{
"InstanceDelete",
strings.ToUpper("Delete"),
"/api/v1/instance",
c.InstanceDelete,
},
"InstanceGet": Route{
{
"InstanceGet",
strings.ToUpper("Get"),
"/api/v1/instance",
c.InstanceGet,
Expand All @@ -72,7 +76,7 @@ func (c *DefaultAPIController) Routes() Routes {
}

// ComponentCommandPost -
func (c *DefaultAPIController) ComponentCommandPost(w http.ResponseWriter, r *http.Request) {
func (c *DefaultApiController) ComponentCommandPost(w http.ResponseWriter, r *http.Request) {
componentCommandPostRequestParam := ComponentCommandPostRequest{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
Expand All @@ -84,10 +88,6 @@ func (c *DefaultAPIController) ComponentCommandPost(w http.ResponseWriter, r *ht
c.errorHandler(w, r, err, nil)
return
}
if err := AssertComponentCommandPostRequestConstraints(componentCommandPostRequestParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.ComponentCommandPost(r.Context(), componentCommandPostRequestParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -96,10 +96,11 @@ func (c *DefaultAPIController) ComponentCommandPost(w http.ResponseWriter, r *ht
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// ComponentGet -
func (c *DefaultAPIController) ComponentGet(w http.ResponseWriter, r *http.Request) {
func (c *DefaultApiController) ComponentGet(w http.ResponseWriter, r *http.Request) {
result, err := c.service.ComponentGet(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -108,10 +109,11 @@ func (c *DefaultAPIController) ComponentGet(w http.ResponseWriter, r *http.Reque
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// InstanceDelete -
func (c *DefaultAPIController) InstanceDelete(w http.ResponseWriter, r *http.Request) {
func (c *DefaultApiController) InstanceDelete(w http.ResponseWriter, r *http.Request) {
result, err := c.service.InstanceDelete(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -120,10 +122,11 @@ func (c *DefaultAPIController) InstanceDelete(w http.ResponseWriter, r *http.Req
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// InstanceGet -
func (c *DefaultAPIController) InstanceGet(w http.ResponseWriter, r *http.Request) {
func (c *DefaultApiController) InstanceGet(w http.ResponseWriter, r *http.Request) {
result, err := c.service.InstanceGet(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -132,4 +135,5 @@ func (c *DefaultAPIController) InstanceGet(w http.ResponseWriter, r *http.Reques
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}
Loading

0 comments on commit 00844bb

Please sign in to comment.