From 6d9b196ae11d2566839f1c8e8d63fb7a737c10ec Mon Sep 17 00:00:00 2001 From: Jordan Dubrick Date: Tue, 20 Feb 2024 15:05:25 -0500 Subject: [PATCH] Update HTTP Response For Not Allowed Requests (#199) * add type to handle response message Signed-off-by: Jordan Dubrick * add put/post/delete endpoints and responses Signed-off-by: Jordan Dubrick * add new endpoint handling for post/put/delete Signed-off-by: Jordan Dubrick * add unit tests for new endpoint handlers Signed-off-by: Jordan Dubrick * break down response into function Signed-off-by: Jordan Dubrick * update codecoverage to exclude generated code Signed-off-by: Jordan Dubrick --------- Signed-off-by: Jordan Dubrick --- .codecov.yaml | 1 + index/server/docs/docs.go | 10 + index/server/openapi.yaml | 441 +++++++++ index/server/pkg/server/endpoint.gen.go | 1080 +++++++++++++++++++--- index/server/pkg/server/endpoint.go | 128 ++- index/server/pkg/server/endpoint_test.go | 296 ++++++ index/server/pkg/server/types.gen.go | 59 ++ 7 files changed, 1911 insertions(+), 104 deletions(-) diff --git a/.codecov.yaml b/.codecov.yaml index c06cf681..3849582a 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -44,6 +44,7 @@ coverage: - "vendor/*" - "Makefile" - ".travis.yml" + - "**/*.gen.go" # See http://docs.codecov.io/docs/pull-request-comments-1 comment: diff --git a/index/server/docs/docs.go b/index/server/docs/docs.go index 4e891d14..6cdeddb3 100644 --- a/index/server/docs/docs.go +++ b/index/server/docs/docs.go @@ -152,3 +152,13 @@ type HealthResponse struct { Message string `json:"message"` } } + +// Method used is not supported. +// +// swagger:response methodNotAllowedResponse +type MethodNotAllowedResponse struct { + // in: body + Payload struct { + Message string `json:"message"` + } +} diff --git a/index/server/openapi.yaml b/index/server/openapi.yaml index f6987588..37aa70f7 100644 --- a/index/server/openapi.yaml +++ b/index/server/openapi.yaml @@ -42,6 +42,21 @@ paths: application/yaml: schema: $ref: '#/components/schemas/IndexSchema' + post: + operationId: postRootEndpoint + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putRootEndpoint + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteRootEndpoint + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /health: get: tags: @@ -55,6 +70,21 @@ paths: 404: description: 'Page not found.' content: {} + post: + operationId: postHealthCheck + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putHealthCheck + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteHealthCheck + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /index: get: tags: @@ -76,6 +106,21 @@ paths: 404: description: 'Page not found.' content: {} + post: + operationId: postDevfileIndexV1 + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileIndexV1 + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileIndexV1 + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /index/{indexType}: get: tags: @@ -105,6 +150,54 @@ paths: 404: description: 'Page not found.' content: {} + post: + operationId: postDevfileIndexV1WithType + parameters: + - name: indexType + in: path + description: The devfile type filter + required: true + schema: + type: string + x-go-name: IndexType + x-go-name: IndexType + - $ref: '#/components/parameters/archParam' + - $ref: '#/components/parameters/iconParam' + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileIndexV1WithType + parameters: + - name: indexType + in: path + description: The devfile type filter + required: true + schema: + type: string + x-go-name: IndexType + x-go-name: IndexType + - $ref: '#/components/parameters/archParam' + - $ref: '#/components/parameters/iconParam' + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileIndexV1WithType + parameters: + - name: indexType + in: path + description: The devfile type filter + required: true + schema: + type: string + x-go-name: IndexType + x-go-name: IndexType + - $ref: '#/components/parameters/archParam' + - $ref: '#/components/parameters/iconParam' + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /v2index: get: tags: @@ -126,6 +219,21 @@ paths: 404: description: 'Page not found.' content: {} + post: + operationId: postDevfileIndexV2 + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileIndexV2 + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileIndexV2 + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /v2index/{indexType}: get: tags: @@ -155,6 +263,54 @@ paths: 404: description: 'Page not found.' content: {} + post: + operationId: postDevfileIndexV2WithType + parameters: + - name: indexType + in: path + description: The devfile type filter + required: true + schema: + type: string + x-go-name: IndexType + x-go-name: IndexType + - $ref: '#/components/parameters/archParam' + - $ref: '#/components/parameters/iconParam' + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileIndexV2WithType + parameters: + - name: indexType + in: path + description: The devfile type filter + required: true + schema: + type: string + x-go-name: IndexType + x-go-name: IndexType + - $ref: '#/components/parameters/archParam' + - $ref: '#/components/parameters/iconParam' + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileIndexV2WithType + parameters: + - name: indexType + in: path + description: The devfile type filter + required: true + schema: + type: string + x-go-name: IndexType + x-go-name: IndexType + - $ref: '#/components/parameters/archParam' + - $ref: '#/components/parameters/iconParam' + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /devfiles/{stack}: get: tags: @@ -181,6 +337,48 @@ paths: $ref: '#/components/responses/devfileNotFoundResponse' 500: $ref: '#/components/responses/devfileErrorResponse' + post: + operationId: postDevfile + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfile + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfile + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /devfiles/{stack}/{version}: get: tags: @@ -215,6 +413,72 @@ paths: $ref: '#/components/responses/devfileNotFoundResponse' 500: $ref: '#/components/responses/devfileErrorResponse' + post: + operationId: postDevfileWithVersion + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: version + in: path + description: The version of the stack + required: true + schema: + type: string + x-go-name: Version + x-go-name: Version + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileWithVersion + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: version + in: path + description: The version of the stack + required: true + schema: + type: string + x-go-name: Version + x-go-name: Version + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileWithVersion + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: version + in: path + description: The version of the stack + required: true + schema: + type: string + x-go-name: Version + x-go-name: Version + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /devfiles/{stack}/starter-projects/{starterProject}: get: summary: Fetches starter project by stack and project name @@ -248,6 +512,72 @@ paths: '500': description: Failed to get the devfile or starter project. $ref: '#/components/responses/devfileErrorResponse' + post: + operationId: postDevfileStarterProject + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: starterProject + in: path + description: The starter project name in the stack devfile + required: true + schema: + type: string + x-go-name: StarterProject + x-go-name: StarterProject + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileStarterProject + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: starterProject + in: path + description: The starter project name in the stack devfile + required: true + schema: + type: string + x-go-name: StarterProject + x-go-name: StarterProject + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileStarterProject + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: starterProject + in: path + description: The starter project name in the stack devfile + required: true + schema: + type: string + x-go-name: StarterProject + x-go-name: StarterProject + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' /devfiles/{stack}/{version}/starter-projects/{starterProject}: get: summary: Fetches starter project by stack name, stack version, and project name @@ -289,6 +619,96 @@ paths: '500': description: Failed to get the devfile or starter project. $ref: '#/components/responses/devfileErrorResponse' + post: + operationId: postDevfileStarterProjectWithVersion + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: version + in: path + description: The version of the stack + required: true + schema: + type: string + x-go-name: Version + x-go-name: Version + - name: starterProject + in: path + description: The starter project name in the stack devfile + required: true + schema: + type: string + x-go-name: StarterProject + x-go-name: StarterProject + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + put: + operationId: putDevfileStarterProjectWithVersion + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: version + in: path + description: The version of the stack + required: true + schema: + type: string + x-go-name: Version + x-go-name: Version + - name: starterProject + in: path + description: The starter project name in the stack devfile + required: true + schema: + type: string + x-go-name: StarterProject + x-go-name: StarterProject + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' + delete: + operationId: deleteDevfileStarterProjectWithVersion + parameters: + - name: stack + in: path + description: The stack name + required: true + schema: + type: string + x-go-name: Stack + x-go-name: Stack + - name: version + in: path + description: The version of the stack + required: true + schema: + type: string + x-go-name: Version + x-go-name: Version + - name: starterProject + in: path + description: The starter project name in the stack devfile + required: true + schema: + type: string + x-go-name: StarterProject + x-go-name: StarterProject + responses: + 405: + $ref: '#/components/responses/methodNotAllowedResponse' components: schemas: @@ -455,6 +875,27 @@ components: schema: type: string format: binary + methodNotAllowedResponse: + description: Method used is not supported. + content: + application/json: + schema: + type: object + properties: + message: + type: string + x-go-name: Message + required: + - message + application/yaml: + schema: + type: object + properties: + message: + type: string + x-go-name: Message + required: + - message securitySchemes: basic: type: http diff --git a/index/server/pkg/server/endpoint.gen.go b/index/server/pkg/server/endpoint.gen.go index 7a7041b1..8f0e472a 100644 --- a/index/server/pkg/server/endpoint.gen.go +++ b/index/server/pkg/server/endpoint.gen.go @@ -30,68 +30,788 @@ import ( ) type ServerInterface interface { + + // (DELETE /) + DeleteRootEndpoint(c *gin.Context) // Root endpoint of registry server. // (GET /) ServeRootEndpoint(c *gin.Context) + + // (POST /) + PostRootEndpoint(c *gin.Context) + + // (PUT /) + PutRootEndpoint(c *gin.Context) + + // (DELETE /devfiles/{stack}) + DeleteDevfile(c *gin.Context, stack string) // Get devfile by stack name. // (GET /devfiles/{stack}) ServeDevfile(c *gin.Context, stack string) + + // (POST /devfiles/{stack}) + PostDevfile(c *gin.Context, stack string) + + // (PUT /devfiles/{stack}) + PutDevfile(c *gin.Context, stack string) + + // (DELETE /devfiles/{stack}/starter-projects/{starterProject}) + DeleteDevfileStarterProject(c *gin.Context, stack string, starterProject string) // Fetches starter project by stack and project name // (GET /devfiles/{stack}/starter-projects/{starterProject}) ServeDevfileStarterProject(c *gin.Context, stack string, starterProject string) + + // (POST /devfiles/{stack}/starter-projects/{starterProject}) + PostDevfileStarterProject(c *gin.Context, stack string, starterProject string) + + // (PUT /devfiles/{stack}/starter-projects/{starterProject}) + PutDevfileStarterProject(c *gin.Context, stack string, starterProject string) + + // (DELETE /devfiles/{stack}/{version}) + DeleteDevfileWithVersion(c *gin.Context, stack string, version string) // Get devfile by stack name. // (GET /devfiles/{stack}/{version}) ServeDevfileWithVersion(c *gin.Context, stack string, version string) + + // (POST /devfiles/{stack}/{version}) + PostDevfileWithVersion(c *gin.Context, stack string, version string) + + // (PUT /devfiles/{stack}/{version}) + PutDevfileWithVersion(c *gin.Context, stack string, version string) + + // (DELETE /devfiles/{stack}/{version}/starter-projects/{starterProject}) + DeleteDevfileStarterProjectWithVersion(c *gin.Context, stack string, version string, starterProject string) // Fetches starter project by stack name, stack version, and project name // (GET /devfiles/{stack}/{version}/starter-projects/{starterProject}) ServeDevfileStarterProjectWithVersion(c *gin.Context, stack string, version string, starterProject string) + + // (POST /devfiles/{stack}/{version}/starter-projects/{starterProject}) + PostDevfileStarterProjectWithVersion(c *gin.Context, stack string, version string, starterProject string) + + // (PUT /devfiles/{stack}/{version}/starter-projects/{starterProject}) + PutDevfileStarterProjectWithVersion(c *gin.Context, stack string, version string, starterProject string) + + // (DELETE /health) + DeleteHealthCheck(c *gin.Context) // Get health status. // (GET /health) ServeHealthCheck(c *gin.Context) + + // (POST /health) + PostHealthCheck(c *gin.Context) + + // (PUT /health) + PutHealthCheck(c *gin.Context) + + // (DELETE /index) + DeleteDevfileIndexV1(c *gin.Context) // Gets index schemas of the stack devfiles. // (GET /index) ServeDevfileIndexV1(c *gin.Context, params ServeDevfileIndexV1Params) + + // (POST /index) + PostDevfileIndexV1(c *gin.Context) + + // (PUT /index) + PutDevfileIndexV1(c *gin.Context) + + // (DELETE /index/{indexType}) + DeleteDevfileIndexV1WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV1WithTypeParams) // Gets index schemas of the devfiles of specific type. // (GET /index/{indexType}) ServeDevfileIndexV1WithType(c *gin.Context, indexType string, params ServeDevfileIndexV1WithTypeParams) + + // (POST /index/{indexType}) + PostDevfileIndexV1WithType(c *gin.Context, indexType string, params PostDevfileIndexV1WithTypeParams) + + // (PUT /index/{indexType}) + PutDevfileIndexV1WithType(c *gin.Context, indexType string, params PutDevfileIndexV1WithTypeParams) + + // (DELETE /v2index) + DeleteDevfileIndexV2(c *gin.Context) // Gets V2 index schemas of the stack devfiles. // (GET /v2index) ServeDevfileIndexV2(c *gin.Context, params ServeDevfileIndexV2Params) + + // (POST /v2index) + PostDevfileIndexV2(c *gin.Context) + + // (PUT /v2index) + PutDevfileIndexV2(c *gin.Context) + + // (DELETE /v2index/{indexType}) + DeleteDevfileIndexV2WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV2WithTypeParams) // Gets V2 index schemas of the devfiles of specific type. // (GET /v2index/{indexType}) ServeDevfileIndexV2WithType(c *gin.Context, indexType string, params ServeDevfileIndexV2WithTypeParams) + + // (POST /v2index/{indexType}) + PostDevfileIndexV2WithType(c *gin.Context, indexType string, params PostDevfileIndexV2WithTypeParams) + + // (PUT /v2index/{indexType}) + PutDevfileIndexV2WithType(c *gin.Context, indexType string, params PutDevfileIndexV2WithTypeParams) +} + +// ServerInterfaceWrapper converts contexts to parameters. +type ServerInterfaceWrapper struct { + Handler ServerInterface + HandlerMiddlewares []MiddlewareFunc + ErrorHandler func(*gin.Context, error, int) +} + +type MiddlewareFunc func(c *gin.Context) + +// DeleteRootEndpoint operation middleware +func (siw *ServerInterfaceWrapper) DeleteRootEndpoint(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteRootEndpoint(c) +} + +// ServeRootEndpoint operation middleware +func (siw *ServerInterfaceWrapper) ServeRootEndpoint(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeRootEndpoint(c) +} + +// PostRootEndpoint operation middleware +func (siw *ServerInterfaceWrapper) PostRootEndpoint(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostRootEndpoint(c) +} + +// PutRootEndpoint operation middleware +func (siw *ServerInterfaceWrapper) PutRootEndpoint(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutRootEndpoint(c) +} + +// DeleteDevfile operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfile(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteDevfile(c, stack) +} + +// ServeDevfile operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfile(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeDevfile(c, stack) +} + +// PostDevfile operation middleware +func (siw *ServerInterfaceWrapper) PostDevfile(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostDevfile(c, stack) +} + +// PutDevfile operation middleware +func (siw *ServerInterfaceWrapper) PutDevfile(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutDevfile(c, stack) +} + +// DeleteDevfileStarterProject operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileStarterProject(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteDevfileStarterProject(c, stack, starterProject) +} + +// ServeDevfileStarterProject operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileStarterProject(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeDevfileStarterProject(c, stack, starterProject) +} + +// PostDevfileStarterProject operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileStarterProject(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostDevfileStarterProject(c, stack, starterProject) +} + +// PutDevfileStarterProject operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileStarterProject(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutDevfileStarterProject(c, stack, starterProject) } -// ServerInterfaceWrapper converts contexts to parameters. -type ServerInterfaceWrapper struct { - Handler ServerInterface - HandlerMiddlewares []MiddlewareFunc - ErrorHandler func(*gin.Context, error, int) +// DeleteDevfileWithVersion operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteDevfileWithVersion(c, stack, version) +} + +// ServeDevfileWithVersion operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeDevfileWithVersion(c, stack, version) +} + +// PostDevfileWithVersion operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostDevfileWithVersion(c, stack, version) +} + +// PutDevfileWithVersion operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutDevfileWithVersion(c, stack, version) +} + +// DeleteDevfileStarterProjectWithVersion operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileStarterProjectWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteDevfileStarterProjectWithVersion(c, stack, version, starterProject) +} + +// ServeDevfileStarterProjectWithVersion operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileStarterProjectWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeDevfileStarterProjectWithVersion(c, stack, version, starterProject) +} + +// PostDevfileStarterProjectWithVersion operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileStarterProjectWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostDevfileStarterProjectWithVersion(c, stack, version, starterProject) +} + +// PutDevfileStarterProjectWithVersion operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileStarterProjectWithVersion(c *gin.Context) { + + var err error + + // ------------- Path parameter "stack" ------------- + var stack string + + err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + return + } + + // ------------- Path parameter "starterProject" ------------- + var starterProject string + + err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutDevfileStarterProjectWithVersion(c, stack, version, starterProject) +} + +// DeleteHealthCheck operation middleware +func (siw *ServerInterfaceWrapper) DeleteHealthCheck(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteHealthCheck(c) +} + +// ServeHealthCheck operation middleware +func (siw *ServerInterfaceWrapper) ServeHealthCheck(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeHealthCheck(c) +} + +// PostHealthCheck operation middleware +func (siw *ServerInterfaceWrapper) PostHealthCheck(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostHealthCheck(c) +} + +// PutHealthCheck operation middleware +func (siw *ServerInterfaceWrapper) PutHealthCheck(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutHealthCheck(c) +} + +// DeleteDevfileIndexV1 operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileIndexV1(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.DeleteDevfileIndexV1(c) +} + +// ServeDevfileIndexV1 operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1(c *gin.Context) { + + var err error + + // Parameter object where we will unmarshal all parameters from the context + var params ServeDevfileIndexV1Params + + // ------------- Optional query parameter "arch" ------------- + + err = runtime.BindQueryParameter("form", true, false, "arch", c.Request.URL.Query(), ¶ms.Arch) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter arch: %s", err), http.StatusBadRequest) + return + } + + // ------------- Optional query parameter "icon" ------------- + + err = runtime.BindQueryParameter("form", true, false, "icon", c.Request.URL.Query(), ¶ms.Icon) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter icon: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.ServeDevfileIndexV1(c, params) } -type MiddlewareFunc func(c *gin.Context) +// PostDevfileIndexV1 operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileIndexV1(c *gin.Context) { -// ServeRootEndpoint operation middleware -func (siw *ServerInterfaceWrapper) ServeRootEndpoint(c *gin.Context) { + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostDevfileIndexV1(c) +} + +// PutDevfileIndexV1 operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileIndexV1(c *gin.Context) { for _, middleware := range siw.HandlerMiddlewares { middleware(c) } - siw.Handler.ServeRootEndpoint(c) + siw.Handler.PutDevfileIndexV1(c) } -// ServeDevfile operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfile(c *gin.Context) { +// DeleteDevfileIndexV1WithType operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileIndexV1WithType(c *gin.Context) { var err error - // ------------- Path parameter "stack" ------------- - var stack string + // ------------- Path parameter "indexType" ------------- + var indexType string - err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + err = runtime.BindStyledParameter("simple", false, "indexType", c.Param("indexType"), &indexType) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter indexType: %s", err), http.StatusBadRequest) + return + } + + // Parameter object where we will unmarshal all parameters from the context + var params DeleteDevfileIndexV1WithTypeParams + + // ------------- Optional query parameter "arch" ------------- + + err = runtime.BindQueryParameter("form", true, false, "arch", c.Request.URL.Query(), ¶ms.Arch) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter arch: %s", err), http.StatusBadRequest) + return + } + + // ------------- Optional query parameter "icon" ------------- + + err = runtime.BindQueryParameter("form", true, false, "icon", c.Request.URL.Query(), ¶ms.Icon) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter icon: %s", err), http.StatusBadRequest) return } @@ -99,29 +819,39 @@ func (siw *ServerInterfaceWrapper) ServeDevfile(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfile(c, stack) + siw.Handler.DeleteDevfileIndexV1WithType(c, indexType, params) } -// ServeDevfileStarterProject operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileStarterProject(c *gin.Context) { +// ServeDevfileIndexV1WithType operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1WithType(c *gin.Context) { var err error - // ------------- Path parameter "stack" ------------- - var stack string + // ------------- Path parameter "indexType" ------------- + var indexType string - err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + err = runtime.BindStyledParameter("simple", false, "indexType", c.Param("indexType"), &indexType) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter indexType: %s", err), http.StatusBadRequest) return } - // ------------- Path parameter "starterProject" ------------- - var starterProject string + // Parameter object where we will unmarshal all parameters from the context + var params ServeDevfileIndexV1WithTypeParams - err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + // ------------- Optional query parameter "arch" ------------- + + err = runtime.BindQueryParameter("form", true, false, "arch", c.Request.URL.Query(), ¶ms.Arch) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter arch: %s", err), http.StatusBadRequest) + return + } + + // ------------- Optional query parameter "icon" ------------- + + err = runtime.BindQueryParameter("form", true, false, "icon", c.Request.URL.Query(), ¶ms.Icon) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter icon: %s", err), http.StatusBadRequest) return } @@ -129,29 +859,39 @@ func (siw *ServerInterfaceWrapper) ServeDevfileStarterProject(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfileStarterProject(c, stack, starterProject) + siw.Handler.ServeDevfileIndexV1WithType(c, indexType, params) } -// ServeDevfileWithVersion operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileWithVersion(c *gin.Context) { +// PostDevfileIndexV1WithType operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileIndexV1WithType(c *gin.Context) { var err error - // ------------- Path parameter "stack" ------------- - var stack string + // ------------- Path parameter "indexType" ------------- + var indexType string - err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + err = runtime.BindStyledParameter("simple", false, "indexType", c.Param("indexType"), &indexType) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter indexType: %s", err), http.StatusBadRequest) return } - // ------------- Path parameter "version" ------------- - var version string + // Parameter object where we will unmarshal all parameters from the context + var params PostDevfileIndexV1WithTypeParams - err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + // ------------- Optional query parameter "arch" ------------- + + err = runtime.BindQueryParameter("form", true, false, "arch", c.Request.URL.Query(), ¶ms.Arch) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter arch: %s", err), http.StatusBadRequest) + return + } + + // ------------- Optional query parameter "icon" ------------- + + err = runtime.BindQueryParameter("form", true, false, "icon", c.Request.URL.Query(), ¶ms.Icon) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter icon: %s", err), http.StatusBadRequest) return } @@ -159,38 +899,39 @@ func (siw *ServerInterfaceWrapper) ServeDevfileWithVersion(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfileWithVersion(c, stack, version) + siw.Handler.PostDevfileIndexV1WithType(c, indexType, params) } -// ServeDevfileStarterProjectWithVersion operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileStarterProjectWithVersion(c *gin.Context) { +// PutDevfileIndexV1WithType operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileIndexV1WithType(c *gin.Context) { var err error - // ------------- Path parameter "stack" ------------- - var stack string + // ------------- Path parameter "indexType" ------------- + var indexType string - err = runtime.BindStyledParameter("simple", false, "stack", c.Param("stack"), &stack) + err = runtime.BindStyledParameter("simple", false, "indexType", c.Param("indexType"), &indexType) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter stack: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter indexType: %s", err), http.StatusBadRequest) return } - // ------------- Path parameter "version" ------------- - var version string + // Parameter object where we will unmarshal all parameters from the context + var params PutDevfileIndexV1WithTypeParams - err = runtime.BindStyledParameter("simple", false, "version", c.Param("version"), &version) + // ------------- Optional query parameter "arch" ------------- + + err = runtime.BindQueryParameter("form", true, false, "arch", c.Request.URL.Query(), ¶ms.Arch) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter version: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter arch: %s", err), http.StatusBadRequest) return } - // ------------- Path parameter "starterProject" ------------- - var starterProject string + // ------------- Optional query parameter "icon" ------------- - err = runtime.BindStyledParameter("simple", false, "starterProject", c.Param("starterProject"), &starterProject) + err = runtime.BindQueryParameter("form", true, false, "icon", c.Request.URL.Query(), ¶ms.Icon) if err != nil { - siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter starterProject: %s", err), http.StatusBadRequest) + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter icon: %s", err), http.StatusBadRequest) return } @@ -198,26 +939,26 @@ func (siw *ServerInterfaceWrapper) ServeDevfileStarterProjectWithVersion(c *gin. middleware(c) } - siw.Handler.ServeDevfileStarterProjectWithVersion(c, stack, version, starterProject) + siw.Handler.PutDevfileIndexV1WithType(c, indexType, params) } -// ServeHealthCheck operation middleware -func (siw *ServerInterfaceWrapper) ServeHealthCheck(c *gin.Context) { +// DeleteDevfileIndexV2 operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileIndexV2(c *gin.Context) { for _, middleware := range siw.HandlerMiddlewares { middleware(c) } - siw.Handler.ServeHealthCheck(c) + siw.Handler.DeleteDevfileIndexV2(c) } -// ServeDevfileIndexV1 operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1(c *gin.Context) { +// ServeDevfileIndexV2 operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2(c *gin.Context) { var err error // Parameter object where we will unmarshal all parameters from the context - var params ServeDevfileIndexV1Params + var params ServeDevfileIndexV2Params // ------------- Optional query parameter "arch" ------------- @@ -239,11 +980,31 @@ func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfileIndexV1(c, params) + siw.Handler.ServeDevfileIndexV2(c, params) } -// ServeDevfileIndexV1WithType operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1WithType(c *gin.Context) { +// PostDevfileIndexV2 operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileIndexV2(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PostDevfileIndexV2(c) +} + +// PutDevfileIndexV2 operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileIndexV2(c *gin.Context) { + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutDevfileIndexV2(c) +} + +// DeleteDevfileIndexV2WithType operation middleware +func (siw *ServerInterfaceWrapper) DeleteDevfileIndexV2WithType(c *gin.Context) { var err error @@ -257,7 +1018,7 @@ func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1WithType(c *gin.Context) { } // Parameter object where we will unmarshal all parameters from the context - var params ServeDevfileIndexV1WithTypeParams + var params DeleteDevfileIndexV2WithTypeParams // ------------- Optional query parameter "arch" ------------- @@ -279,16 +1040,25 @@ func (siw *ServerInterfaceWrapper) ServeDevfileIndexV1WithType(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfileIndexV1WithType(c, indexType, params) + siw.Handler.DeleteDevfileIndexV2WithType(c, indexType, params) } -// ServeDevfileIndexV2 operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2(c *gin.Context) { +// ServeDevfileIndexV2WithType operation middleware +func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2WithType(c *gin.Context) { var err error + // ------------- Path parameter "indexType" ------------- + var indexType string + + err = runtime.BindStyledParameter("simple", false, "indexType", c.Param("indexType"), &indexType) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter indexType: %s", err), http.StatusBadRequest) + return + } + // Parameter object where we will unmarshal all parameters from the context - var params ServeDevfileIndexV2Params + var params ServeDevfileIndexV2WithTypeParams // ------------- Optional query parameter "arch" ------------- @@ -310,11 +1080,11 @@ func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfileIndexV2(c, params) + siw.Handler.ServeDevfileIndexV2WithType(c, indexType, params) } -// ServeDevfileIndexV2WithType operation middleware -func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2WithType(c *gin.Context) { +// PostDevfileIndexV2WithType operation middleware +func (siw *ServerInterfaceWrapper) PostDevfileIndexV2WithType(c *gin.Context) { var err error @@ -328,7 +1098,7 @@ func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2WithType(c *gin.Context) { } // Parameter object where we will unmarshal all parameters from the context - var params ServeDevfileIndexV2WithTypeParams + var params PostDevfileIndexV2WithTypeParams // ------------- Optional query parameter "arch" ------------- @@ -350,7 +1120,47 @@ func (siw *ServerInterfaceWrapper) ServeDevfileIndexV2WithType(c *gin.Context) { middleware(c) } - siw.Handler.ServeDevfileIndexV2WithType(c, indexType, params) + siw.Handler.PostDevfileIndexV2WithType(c, indexType, params) +} + +// PutDevfileIndexV2WithType operation middleware +func (siw *ServerInterfaceWrapper) PutDevfileIndexV2WithType(c *gin.Context) { + + var err error + + // ------------- Path parameter "indexType" ------------- + var indexType string + + err = runtime.BindStyledParameter("simple", false, "indexType", c.Param("indexType"), &indexType) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter indexType: %s", err), http.StatusBadRequest) + return + } + + // Parameter object where we will unmarshal all parameters from the context + var params PutDevfileIndexV2WithTypeParams + + // ------------- Optional query parameter "arch" ------------- + + err = runtime.BindQueryParameter("form", true, false, "arch", c.Request.URL.Query(), ¶ms.Arch) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter arch: %s", err), http.StatusBadRequest) + return + } + + // ------------- Optional query parameter "icon" ------------- + + err = runtime.BindQueryParameter("form", true, false, "icon", c.Request.URL.Query(), ¶ms.Icon) + if err != nil { + siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter icon: %s", err), http.StatusBadRequest) + return + } + + for _, middleware := range siw.HandlerMiddlewares { + middleware(c) + } + + siw.Handler.PutDevfileIndexV2WithType(c, indexType, params) } // GinServerOptions provides options for the Gin server. @@ -382,63 +1192,127 @@ func RegisterHandlersWithOptions(router *gin.Engine, si ServerInterface, options ErrorHandler: errorHandler, } + router.DELETE(options.BaseURL+"/", wrapper.DeleteRootEndpoint) + router.GET(options.BaseURL+"/", wrapper.ServeRootEndpoint) + router.POST(options.BaseURL+"/", wrapper.PostRootEndpoint) + + router.PUT(options.BaseURL+"/", wrapper.PutRootEndpoint) + + router.DELETE(options.BaseURL+"/devfiles/:stack", wrapper.DeleteDevfile) + router.GET(options.BaseURL+"/devfiles/:stack", wrapper.ServeDevfile) + router.POST(options.BaseURL+"/devfiles/:stack", wrapper.PostDevfile) + + router.PUT(options.BaseURL+"/devfiles/:stack", wrapper.PutDevfile) + + router.DELETE(options.BaseURL+"/devfiles/:stack/starter-projects/:starterProject", wrapper.DeleteDevfileStarterProject) + router.GET(options.BaseURL+"/devfiles/:stack/starter-projects/:starterProject", wrapper.ServeDevfileStarterProject) + router.POST(options.BaseURL+"/devfiles/:stack/starter-projects/:starterProject", wrapper.PostDevfileStarterProject) + + router.PUT(options.BaseURL+"/devfiles/:stack/starter-projects/:starterProject", wrapper.PutDevfileStarterProject) + + router.DELETE(options.BaseURL+"/devfiles/:stack/:version", wrapper.DeleteDevfileWithVersion) + router.GET(options.BaseURL+"/devfiles/:stack/:version", wrapper.ServeDevfileWithVersion) + router.POST(options.BaseURL+"/devfiles/:stack/:version", wrapper.PostDevfileWithVersion) + + router.PUT(options.BaseURL+"/devfiles/:stack/:version", wrapper.PutDevfileWithVersion) + + router.DELETE(options.BaseURL+"/devfiles/:stack/:version/starter-projects/:starterProject", wrapper.DeleteDevfileStarterProjectWithVersion) + router.GET(options.BaseURL+"/devfiles/:stack/:version/starter-projects/:starterProject", wrapper.ServeDevfileStarterProjectWithVersion) + router.POST(options.BaseURL+"/devfiles/:stack/:version/starter-projects/:starterProject", wrapper.PostDevfileStarterProjectWithVersion) + + router.PUT(options.BaseURL+"/devfiles/:stack/:version/starter-projects/:starterProject", wrapper.PutDevfileStarterProjectWithVersion) + + router.DELETE(options.BaseURL+"/health", wrapper.DeleteHealthCheck) + router.GET(options.BaseURL+"/health", wrapper.ServeHealthCheck) + router.POST(options.BaseURL+"/health", wrapper.PostHealthCheck) + + router.PUT(options.BaseURL+"/health", wrapper.PutHealthCheck) + + router.DELETE(options.BaseURL+"/index", wrapper.DeleteDevfileIndexV1) + router.GET(options.BaseURL+"/index", wrapper.ServeDevfileIndexV1) + router.POST(options.BaseURL+"/index", wrapper.PostDevfileIndexV1) + + router.PUT(options.BaseURL+"/index", wrapper.PutDevfileIndexV1) + + router.DELETE(options.BaseURL+"/index/:indexType", wrapper.DeleteDevfileIndexV1WithType) + router.GET(options.BaseURL+"/index/:indexType", wrapper.ServeDevfileIndexV1WithType) + router.POST(options.BaseURL+"/index/:indexType", wrapper.PostDevfileIndexV1WithType) + + router.PUT(options.BaseURL+"/index/:indexType", wrapper.PutDevfileIndexV1WithType) + + router.DELETE(options.BaseURL+"/v2index", wrapper.DeleteDevfileIndexV2) + router.GET(options.BaseURL+"/v2index", wrapper.ServeDevfileIndexV2) + router.POST(options.BaseURL+"/v2index", wrapper.PostDevfileIndexV2) + + router.PUT(options.BaseURL+"/v2index", wrapper.PutDevfileIndexV2) + + router.DELETE(options.BaseURL+"/v2index/:indexType", wrapper.DeleteDevfileIndexV2WithType) + router.GET(options.BaseURL+"/v2index/:indexType", wrapper.ServeDevfileIndexV2WithType) + router.POST(options.BaseURL+"/v2index/:indexType", wrapper.PostDevfileIndexV2WithType) + + router.PUT(options.BaseURL+"/v2index/:indexType", wrapper.PutDevfileIndexV2WithType) + return router } // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xaX3PbuBH/Khi0M01maNHRpTdTvV17SU8PbT22mz6c/QCRSxEXEuABSyk6j757ZwGQ", - "Ik3SlhXnLjfnl4QClsBvd3/7h4DveKLLSitQaPnijlfCiBIQjPslTJJf0Aj9SMEmRlYoteILfp0DQ2HW", - "gIykJEKCtQGWyQLB8IhLkvq5BrPjEVeiBL5w6/GI2ySHUtCafzaQ8QX/U3xAEftZG3/XWdby/T7iMtHq", - "ATg0zXBXPQKCxI4GsSThPW1uwFZaWbB+800mC3hnjDaXYYLGE60QFDrbVVUhE0H44p8sgbzr7FkZXYFB", - "6ZcDWoceCD1fcItGqjWP+KeztT4LuN1mfB9xiwJr+5j4lZci6EFMr36CBN1IF9xOlMVXBG4f3XPteyEL", - "SBlqRmTDHFiw/ow7Wff8b43vda3SZ3DGr2zeL2mwTKp0ymInWeqhUPner3uEAY5bZaDXVZ0kYG1WF4wM", - "6Faf3agbdYUi+djoyIIyTtccRIH5M5CiBGvFGh5z07+CmE8YP9fSQMoXP7av334uW74cjuPN/YMzKvPE", - "dWaWKoVPz06oJa165UU/j1T9lY7X1L3XI5RFYRDMhdFktiNU/kVWfZyZNqVAvuArqYSrS31HPgXfe+L7", - "aodgKdpTvVWFFqkDupkvT3aKY1KDyo3OgvGiw9yZLCtt0DcNmPMFX0vM69Us0WUcYjE2sJYWze7M1hVJ", - "x44p8RoUqaFN8JBX+mH//iagjnfFhzm7z5Z902S4yO23M4MG5j/uQRSskBaZzlhlNO2kTa+/sgxz0auC",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wKR3WKyw2XzhuRJ1ZYqr+W/Qsuanz+gvMo1UG", + "bcCJ3PHUlNqh6TQ5ZL8603njFN6g4jvtH0J7+1+V9lYH+f6GOnOv1lDgg4pM/wUR4MdvJz8hdX/on4AF", + "978WC+7zIwbiE3hwv8ua58aDt2aqe7WREx+WrDr/v9TEeixa3EHqnGhx543T0GL38wZmWtm2MGn54wV2", + "ENa/ktCzKCbQq34sS+rQyb1hcmPax8WfAQAA//+ZpfowSk8AAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/index/server/pkg/server/endpoint.go b/index/server/pkg/server/endpoint.go index 2f10f9ea..ea15cc00 100644 --- a/index/server/pkg/server/endpoint.go +++ b/index/server/pkg/server/endpoint.go @@ -56,14 +56,50 @@ func (*Server) ServeRootEndpoint(c *gin.Context) { } } +func (*Server) PostRootEndpoint(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutRootEndpoint(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteRootEndpoint(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + func (*Server) ServeDevfileIndexV1(c *gin.Context, params ServeDevfileIndexV1Params) { ServeDevfileIndex(c, true, IndexParams(params)) } +func (*Server) PostDevfileIndexV1(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutDevfileIndexV1(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteDevfileIndexV1(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + func (*Server) ServeDevfileIndexV2(c *gin.Context, params ServeDevfileIndexV2Params) { ServeDevfileIndex(c, false, IndexParams(params)) } +func (*Server) PostDevfileIndexV2(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutDevfileIndexV2(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteDevfileIndexV2(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} + // ServeDevfileIndex serves the index.json file located in the container at `ServeDevfileIndex` func ServeDevfileIndex(c *gin.Context, wantV1Index bool, params IndexParams) { // Start the counter for the request @@ -85,18 +121,54 @@ func (*Server) ServeDevfileIndexV1WithType(c *gin.Context, indexType string, par buildIndexAPIResponse(c, indexType, true, IndexParams(params)) } +func (*Server) PostDevfileIndexV1WithType(c *gin.Context, indexType string, params PostDevfileIndexV1WithTypeParams){ + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutDevfileIndexV1WithType(c *gin.Context, indexType string, params PutDevfileIndexV1WithTypeParams){ + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteDevfileIndexV1WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV1WithTypeParams){ + SetMethodNotAllowedJSONResponse(c) +} + func (*Server) ServeDevfileIndexV2WithType(c *gin.Context, indexType string, params ServeDevfileIndexV2WithTypeParams) { // Serve the index with type buildIndexAPIResponse(c, indexType, false, IndexParams(params)) } -// ServeHealthCheck serves endpoint `/health` for registry health check +func (*Server) PostDevfileIndexV2WithType(c *gin.Context, indexType string, params PostDevfileIndexV2WithTypeParams) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutDevfileIndexV2WithType(c *gin.Context, indexType string, params PutDevfileIndexV2WithTypeParams) { + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteDevfileIndexV2WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV2WithTypeParams) { + SetMethodNotAllowedJSONResponse(c) +} + +// ServeHealthCheck serves endpoint `/health` for registry health check with GET request func (*Server) ServeHealthCheck(c *gin.Context) { c.JSON(http.StatusOK, HealthResponse{ Message: "the server is up and running", }) } +// PostHealthCheck serves endpoint `/health` for registry health check with POST request +func (*Server) PostHealthCheck(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} +// PutHealthCheck serves endpoint `/health` for registry health check with PUT request +func (*Server) PutHealthCheck(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} +// DeleteHealthCheck serves endpoint `/health` for registry health check with DELETE request +func (*Server) DeleteHealthCheck(c *gin.Context) { + SetMethodNotAllowedJSONResponse(c) +} func (*Server) ServeDevfileWithVersion(c *gin.Context, name string, version string) { bytes, devfileIndex := fetchDevfile(c, name, version) @@ -126,17 +198,53 @@ func (*Server) ServeDevfileWithVersion(c *gin.Context, name string, version stri } } +func (*Server) PostDevfileWithVersion(c *gin.Context, name string, version string){ + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutDevfileWithVersion(c *gin.Context, name string, version string){ + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteDevfileWithVersion(c *gin.Context, name string, version string){ + SetMethodNotAllowedJSONResponse(c) +} + // ServeDevfile returns the devfile content func (s *Server) ServeDevfile(c *gin.Context, name string) { // append the stack version, for endpoint /devfiles/name without version s.ServeDevfileWithVersion(c, name, "default") } +func (s *Server) PostDevfile(c *gin.Context, name string) { + SetMethodNotAllowedJSONResponse(c) +} + +func (s *Server) PutDevfile(c *gin.Context, name string) { + SetMethodNotAllowedJSONResponse(c) +} + +func (s *Server) DeleteDevfile(c *gin.Context, name string) { + SetMethodNotAllowedJSONResponse(c) +} + // ServeDevfileStarterProject returns the starter project content for the devfile using default version func (s *Server) ServeDevfileStarterProject(c *gin.Context, name string, starterProject string) { s.ServeDevfileStarterProjectWithVersion(c, name, "default", starterProject) } +func (s *Server) PostDevfileStarterProject(c *gin.Context, name string, starterProject string) { + SetMethodNotAllowedJSONResponse(c) +} + +func (s *Server) PutDevfileStarterProject(c *gin.Context, name string, starterProject string) { + SetMethodNotAllowedJSONResponse(c) +} + +func (s *Server) DeleteDevfileStarterProject(c *gin.Context, name string, starterProject string) { + SetMethodNotAllowedJSONResponse(c) +} + // ServeDevfileStarterProject returns the starter project content for the devfile using specified version func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) { downloadTmpLoc := path.Join("/tmp", starterProject) @@ -323,6 +431,18 @@ func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string } } +func (*Server) PostDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){ + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) PutDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){ + SetMethodNotAllowedJSONResponse(c) +} + +func (*Server) DeleteDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){ + SetMethodNotAllowedJSONResponse(c) +} + // ServeUI handles registry viewer proxy requests func ServeUI(c *gin.Context) { if headless { @@ -682,3 +802,9 @@ func ServeOciProxy(c *gin.Context) { proxy.ServeHTTP(c.Writer, c.Request) } + +func SetMethodNotAllowedJSONResponse(c *gin.Context){ + c.JSON(http.StatusMethodNotAllowed, MethodNotAllowedResponse{ + Message: "Only GET requests are supported.", + }) +} \ No newline at end of file diff --git a/index/server/pkg/server/endpoint_test.go b/index/server/pkg/server/endpoint_test.go index 502bb8be..2fd581d0 100644 --- a/index/server/pkg/server/endpoint_test.go +++ b/index/server/pkg/server/endpoint_test.go @@ -1204,3 +1204,299 @@ func TestBuildProxyErrorResponse(t *testing.T) { } } } + +// TestRootEndpointMethodNotAllowed tests with POST/PUT/DELETE requests +// All of these should return 405 response codes as they are not allowed +// Currently only GET requests are required/supported +func TestRootEndpointMethodNotAllowed(t *testing.T) { + setupVars() + server := &Server{} + tests := []struct { + name string + handler gin.HandlerFunc + wantCode int + }{ + { + name: "POST / - Successful Response Test", + handler: server.PostRootEndpoint, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT / - Successful Response Test", + handler: server.PutRootEndpoint, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE / - Successful Response Test", + handler: server.DeleteRootEndpoint, + wantCode: http.StatusMethodNotAllowed, + }, + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + gin.SetMode(gin.TestMode) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + test.handler(c) + + if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { + t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) + return + } + }) + } +} + +// TestHealthCheckMethodNotAllowed tests with POST/PUT/DELETE requests +// All of these should return 405 response codes as they are not allowed +// Currently only GET requests are required/supported +func TestHealthCheckMethodNotAllowed(t *testing.T) { + setupVars() + server := &Server{} + tests := []struct { + name string + handler gin.HandlerFunc + wantCode int + }{ + { + name: "POST /health - Successful Response Test", + handler: server.PostHealthCheck, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /health - Successful Response Test", + handler: server.PutHealthCheck, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /health - Successful Response Test", + handler: server.DeleteHealthCheck, + wantCode: http.StatusMethodNotAllowed, + }, + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + gin.SetMode(gin.TestMode) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + test.handler(c) + + if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { + t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) + return + } + }) + } +} + +// TestDevfileIndexV1MethodNotAllowed tests with POST/PUT/DELETE requests +// All of these should return 405 response codes as they are not allowed +// Currently only GET requests are required/supported +func TestDevfileIndexV1MethodNotAllowed(t *testing.T) { + setupVars() + server := &Server{} + tests := []struct { + name string + handler gin.HandlerFunc + wantCode int + }{ + { + name: "POST /index - Successful Response Test", + handler: server.PostDevfileIndexV1, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /index - Successful Response Test", + handler: server.PutDevfileIndexV1, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /index - Successful Response Test", + handler: server.DeleteDevfileIndexV1, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "POST /index/{indexType} - Successful Response Test", + handler: func(c *gin.Context){server.PostDevfileIndexV1WithType(c, "stack", PostDevfileIndexV1WithTypeParams{})}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /index/{indexType} - Successful Response Test", + handler: func(c *gin.Context){server.PutDevfileIndexV1WithType(c, "stack", PutDevfileIndexV1WithTypeParams{})}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /index/{indexType} - Successful Response Test", + handler: func(c *gin.Context){server.DeleteDevfileIndexV1WithType(c, "stack", DeleteDevfileIndexV1WithTypeParams{})}, + wantCode: http.StatusMethodNotAllowed, + }, + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + gin.SetMode(gin.TestMode) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + test.handler(c) + + if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { + t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) + return + } + }) + } +} + +// TestDevfileIndexV2MethodNotAllowed tests with POST/PUT/DELETE requests +// All of these should return 405 response codes as they are not allowed +// Currently only GET requests are required/supported +func TestDevfileIndexV2MethodNotAllowed(t *testing.T) { + setupVars() + server := &Server{} + tests := []struct { + name string + handler gin.HandlerFunc + wantCode int + }{ + { + name: "POST /v2index - Successful Response Test", + handler: server.PostDevfileIndexV2, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /v2index - Successful Response Test", + handler: server.PutDevfileIndexV2, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /v2index - Successful Response Test", + handler: server.DeleteDevfileIndexV2, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "POST /v2index/{indexType} - Successful Response Test", + handler: func(c *gin.Context){server.PostDevfileIndexV2WithType(c, "stack", PostDevfileIndexV2WithTypeParams{})}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /v2index/{indexType} - Successful Response Test", + handler: func(c *gin.Context){server.PutDevfileIndexV2WithType(c, "stack", PutDevfileIndexV2WithTypeParams{})}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /v2index/{indexType} - Successful Response Test", + handler: func(c *gin.Context){server.DeleteDevfileIndexV2WithType(c, "stack", DeleteDevfileIndexV2WithTypeParams{})}, + wantCode: http.StatusMethodNotAllowed, + }, + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + gin.SetMode(gin.TestMode) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + test.handler(c) + + if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { + t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) + return + } + }) + } +} + +// TestDevfileMethodNotAllowed tests with POST/PUT/DELETE requests +// All of these should return 405 response codes as they are not allowed +// Currently only GET requests are required/supported +func TestDevfileMethodNotAllowed(t *testing.T) { + setupVars() + server := &Server{} + tests := []struct { + name string + handler gin.HandlerFunc + wantCode int + }{ + { + name: "POST /devfiles/{stack} - Successful Response Test", + handler: func(c *gin.Context){server.PostDevfile(c, "go")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /devfiles/{stack} - Successful Response Test", + handler: func(c *gin.Context){server.PutDevfile(c, "go")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /devfiles/{stack} - Successful Response Test", + handler: func(c *gin.Context){server.DeleteDevfile(c, "go")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "POST /devfiles/{stack}/{version} - Successful Response Test", + handler: func(c *gin.Context){server.PostDevfileWithVersion(c, "go", "2.0.0")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /devfiles/{stack}/{version} - Successful Response Test", + handler: func(c *gin.Context){server.PutDevfileWithVersion(c, "go", "2.0.0")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /devfiles/{stack}/{version} - Successful Response Test", + handler: func(c *gin.Context){server.DeleteDevfileWithVersion(c, "go", "2.0.0")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "POST /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context){server.PostDevfileStarterProject(c, "go", "go-starter")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context){server.PutDevfileStarterProject(c, "go", "go-starter")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /devfiles/{stack}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context){server.DeleteDevfileStarterProject(c, "go", "go-starter")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "POST /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context){server.PostDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "PUT /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context){server.PutDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter")}, + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "DELETE /devfiles/{stack}/{version}/starter-projects/{starterProject} - Successful Response Test", + handler: func(c *gin.Context){server.DeleteDevfileStarterProjectWithVersion(c, "go", "2.0.0", "go-starter")}, + wantCode: http.StatusMethodNotAllowed, + }, + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + gin.SetMode(gin.TestMode) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + + test.handler(c) + + if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) { + t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode) + return + } + }) + } +} diff --git a/index/server/pkg/server/types.gen.go b/index/server/pkg/server/types.gen.go index 0310d7c5..a3753602 100644 --- a/index/server/pkg/server/types.gen.go +++ b/index/server/pkg/server/types.gen.go @@ -69,6 +69,11 @@ type HealthResponse struct { // IndexResponse The index file schema type IndexResponse = IndexSchema +// MethodNotAllowedResponse defines model for methodNotAllowedResponse. +type MethodNotAllowedResponse struct { + Message string `json:"message"` +} + // V2IndexResponse defines model for v2IndexResponse. type V2IndexResponse = schema.Schema @@ -81,6 +86,15 @@ type ServeDevfileIndexV1Params struct { Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` } +// DeleteDevfileIndexV1WithTypeParams defines parameters for DeleteDevfileIndexV1WithType. +type DeleteDevfileIndexV1WithTypeParams struct { + // Arch The target architecture filter + Arch *ArchParam `form:"arch,omitempty" json:"arch,omitempty"` + + // Icon The icon type filter + Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` +} + // ServeDevfileIndexV1WithTypeParams defines parameters for ServeDevfileIndexV1WithType. type ServeDevfileIndexV1WithTypeParams struct { // Arch The target architecture filter @@ -90,6 +104,24 @@ type ServeDevfileIndexV1WithTypeParams struct { Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` } +// PostDevfileIndexV1WithTypeParams defines parameters for PostDevfileIndexV1WithType. +type PostDevfileIndexV1WithTypeParams struct { + // Arch The target architecture filter + Arch *ArchParam `form:"arch,omitempty" json:"arch,omitempty"` + + // Icon The icon type filter + Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` +} + +// PutDevfileIndexV1WithTypeParams defines parameters for PutDevfileIndexV1WithType. +type PutDevfileIndexV1WithTypeParams struct { + // Arch The target architecture filter + Arch *ArchParam `form:"arch,omitempty" json:"arch,omitempty"` + + // Icon The icon type filter + Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` +} + // ServeDevfileIndexV2Params defines parameters for ServeDevfileIndexV2. type ServeDevfileIndexV2Params struct { // Arch The target architecture filter @@ -99,6 +131,15 @@ type ServeDevfileIndexV2Params struct { Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` } +// DeleteDevfileIndexV2WithTypeParams defines parameters for DeleteDevfileIndexV2WithType. +type DeleteDevfileIndexV2WithTypeParams struct { + // Arch The target architecture filter + Arch *ArchParam `form:"arch,omitempty" json:"arch,omitempty"` + + // Icon The icon type filter + Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` +} + // ServeDevfileIndexV2WithTypeParams defines parameters for ServeDevfileIndexV2WithType. type ServeDevfileIndexV2WithTypeParams struct { // Arch The target architecture filter @@ -107,3 +148,21 @@ type ServeDevfileIndexV2WithTypeParams struct { // Icon The icon type filter Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` } + +// PostDevfileIndexV2WithTypeParams defines parameters for PostDevfileIndexV2WithType. +type PostDevfileIndexV2WithTypeParams struct { + // Arch The target architecture filter + Arch *ArchParam `form:"arch,omitempty" json:"arch,omitempty"` + + // Icon The icon type filter + Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` +} + +// PutDevfileIndexV2WithTypeParams defines parameters for PutDevfileIndexV2WithType. +type PutDevfileIndexV2WithTypeParams struct { + // Arch The target architecture filter + Arch *ArchParam `form:"arch,omitempty" json:"arch,omitempty"` + + // Icon The icon type filter + Icon *IconParam `form:"icon,omitempty" json:"icon,omitempty"` +}