diff --git a/docs/api_docs/bundle.yaml b/docs/api_docs/bundle.yaml index c40ef6ef..03c8900f 100644 --- a/docs/api_docs/bundle.yaml +++ b/docs/api_docs/bundle.yaml @@ -871,6 +871,60 @@ paths: schema: $ref: '#/definitions/error' /evaluation: + get: + tags: + - evaluation + operationId: getEvaluation + parameters: + - in: query + name: entity + description: >- + JSON encoded "query optimized" evaluation entity: + ?entity={"id":"1","type":"a","ctx":{"foo":"bar"}} + required: true + type: string + - in: query + name: dbg + description: '"query optimized" enableDebug parameter' + type: boolean + default: false + - in: query + name: id + description: '"query optimized" flagID parameter' + required: false + type: integer + format: int64 + - in: query + name: key + description: '"query optimized" flagKey parameter' + required: false + type: string + - in: query + name: tags + description: '"query optimized" flagTags parameter' + required: false + type: array + collectionFormat: csv + items: + type: string + - in: query + name: all + description: >- + whether to use ALL (flagTags) semantics (ANY by default): + `?tags=foo,bar&all=true` is equivalent to postEvaluation's + `flagTagsOperator: "ALL"` + required: false + type: boolean + default: false + responses: + '200': + description: evaluation result + schema: + $ref: '#/definitions/evalResult' + default: + description: generic error response + schema: + $ref: '#/definitions/error' post: tags: - evaluation @@ -892,6 +946,74 @@ paths: schema: $ref: '#/definitions/error' /evaluation/batch: + get: + tags: + - evaluation + operationId: getEvaluationBatch + parameters: + - in: query + name: entity + description: >- + JSON encoded "query optimized" evaluation entities: + ?entity={"id":"1","type":"a","ctx":{"foo":"bar"}}&entity={"id":"2","ctx":{"baz":42}} + required: true + type: array + collectionFormat: multi + minItems: 1 + items: + type: string + - in: query + name: dbg + description: '"query optimized" enableDebug parameter' + required: false + type: boolean + default: false + - in: query + name: ids + description: '"query optimized" flagIDs parameter' + required: false + type: array + collectionFormat: csv + minItems: 1 + items: + type: integer + format: int64 + - in: query + name: keys + description: '"query optimized" flagKeys parameter' + required: false + type: array + collectionFormat: csv + minItems: 1 + items: + type: string + minLength: 1 + - in: query + name: tags + description: '"query optimized" flagTags parameter' + required: false + type: array + collectionFormat: csv + items: + type: string + - in: query + name: all + description: >- + whether to use ALL (flagTags) semantics (ANY by default): + `?tags=foo,bar&all=true` is equivalent to postEvaluationBatch's + `flagTagsOperator: "ALL"` + required: false + type: boolean + default: false + responses: + '200': + description: evaluation batch result + schema: + $ref: '#/definitions/evaluationBatchResponse' + default: + description: generic error response + schema: + $ref: '#/definitions/error' post: tags: - evaluation @@ -1402,6 +1524,16 @@ definitions: type: string entityContext: type: object + getEvaluationEntity: + type: object + description: evaluationEntity's "query optimized" serialization + properties: + id: + type: string + type: + type: string + ctx: + type: object evaluationBatchRequest: type: object required: diff --git a/pkg/handler/eval.go b/pkg/handler/eval.go index 99f7568c..8a6302fa 100644 --- a/pkg/handler/eval.go +++ b/pkg/handler/eval.go @@ -23,6 +23,8 @@ import ( // Eval is the Eval interface type Eval interface { + GetEvaluation(evaluation.GetEvaluationParams) middleware.Responder + GetEvaluationBatch(evaluation.GetEvaluationBatchParams) middleware.Responder PostEvaluation(evaluation.PostEvaluationParams) middleware.Responder PostEvaluationBatch(evaluation.PostEvaluationBatchParams) middleware.Responder } @@ -34,6 +36,79 @@ func NewEval() Eval { type eval struct{} +func (e *eval) GetEvaluation(params evaluation.GetEvaluationParams) middleware.Responder { + var evaluationEntity models.GetEvaluationEntity + err := json.Unmarshal([]byte(params.Entity), &evaluationEntity) + if err != nil { + return evaluation.NewGetEvaluationDefault(400).WithPayload( + ErrorMessage("entity in not a valid evaluation entity")) + } + flagTagsOperator := "ANY" + if params.All != nil && *params.All { + flagTagsOperator = "ALL" + } + evalContext := models.EvalContext{ + EntityID: evaluationEntity.ID, + EntityType: evaluationEntity.Type, + EntityContext: evaluationEntity.Ctx, + FlagTags: params.Tags, + FlagTagsOperator: &flagTagsOperator, + } + if params.Dbg != nil && *params.Dbg { + evalContext.EnableDebug = true + } + if params.ID != nil { + evalContext.FlagID = *params.ID + } + if params.Key != nil { + evalContext.FlagKey = *params.Key + } + + evalResult := EvalFlag(evalContext) + resp := evaluation.NewPostEvaluationOK() + resp.SetPayload(evalResult) + return resp +} + +func (e *eval) GetEvaluationBatch(params evaluation.GetEvaluationBatchParams) middleware.Responder { + var evaluationEntities []*models.EvaluationEntity + for _, rawEntity := range params.Entity { + var getEvaluationEntity models.GetEvaluationEntity + err := json.Unmarshal([]byte(rawEntity), &getEvaluationEntity) + evaluationEntity := models.EvaluationEntity{ + EntityID: getEvaluationEntity.ID, + EntityContext: getEvaluationEntity.Ctx, + EntityType: getEvaluationEntity.Type, + } + if err != nil { + return evaluation.NewGetEvaluationBatchDefault(400).WithPayload( + ErrorMessage("entity is not a valid evaluation entity: %s", rawEntity)) + } + evaluationEntities = append(evaluationEntities, &evaluationEntity) + } + flagTagsOperator := "ANY" + if params.All != nil && *params.All { + flagTagsOperator = "ALL" + } + var enableDebug = false + if params.Dbg != nil && *params.Dbg { + enableDebug = true + } + + results := EvaluateBatch( + evaluationEntities, + params.Ids, + params.Keys, + params.Tags, + &flagTagsOperator, + enableDebug, + ) + + resp := evaluation.NewPostEvaluationBatchOK() + resp.SetPayload(results) + return resp +} + func (e *eval) PostEvaluation(params evaluation.PostEvaluationParams) middleware.Responder { evalContext := params.Body if evalContext == nil { @@ -48,21 +123,38 @@ func (e *eval) PostEvaluation(params evaluation.PostEvaluationParams) middleware } func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams) middleware.Responder { - entities := params.Body.Entities - flagIDs := params.Body.FlagIDs - flagKeys := params.Body.FlagKeys - flagTags := params.Body.FlagTags - flagTagsOperator := params.Body.FlagTagsOperator + results := EvaluateBatch( + params.Body.Entities, + params.Body.FlagIDs, + params.Body.FlagKeys, + params.Body.FlagTags, + params.Body.FlagTagsOperator, + params.Body.EnableDebug, + ) + + resp := evaluation.NewPostEvaluationBatchOK() + resp.SetPayload(results) + return resp +} + +func EvaluateBatch( + evaluationEntities []*models.EvaluationEntity, + flagIDs []int64, + flagKeys []string, + flagTags []string, + flagTagsOperator *string, + enableDebug bool, +) *models.EvaluationBatchResponse { results := &models.EvaluationBatchResponse{} // TODO make it concurrent - for _, entity := range entities { + for _, evaluationEntity := range evaluationEntities { if len(flagTags) > 0 { evalContext := models.EvalContext{ - EnableDebug: params.Body.EnableDebug, - EntityContext: entity.EntityContext, - EntityID: entity.EntityID, - EntityType: entity.EntityType, + EnableDebug: enableDebug, + EntityContext: evaluationEntity.EntityContext, + EntityID: evaluationEntity.EntityID, + EntityType: evaluationEntity.EntityType, FlagTags: flagTags, FlagTagsOperator: flagTagsOperator, } @@ -71,10 +163,10 @@ func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams) } for _, flagID := range flagIDs { evalContext := models.EvalContext{ - EnableDebug: params.Body.EnableDebug, - EntityContext: entity.EntityContext, - EntityID: entity.EntityID, - EntityType: entity.EntityType, + EnableDebug: enableDebug, + EntityContext: evaluationEntity.EntityContext, + EntityID: evaluationEntity.EntityID, + EntityType: evaluationEntity.EntityType, FlagID: flagID, } @@ -83,10 +175,10 @@ func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams) } for _, flagKey := range flagKeys { evalContext := models.EvalContext{ - EnableDebug: params.Body.EnableDebug, - EntityContext: entity.EntityContext, - EntityID: entity.EntityID, - EntityType: entity.EntityType, + EnableDebug: enableDebug, + EntityContext: evaluationEntity.EntityContext, + EntityID: evaluationEntity.EntityID, + EntityType: evaluationEntity.EntityType, FlagKey: flagKey, } @@ -95,9 +187,7 @@ func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams) } } - resp := evaluation.NewPostEvaluationBatchOK() - resp.SetPayload(results) - return resp + return results } // BlankResult creates a blank result diff --git a/pkg/handler/eval_test.go b/pkg/handler/eval_test.go index 3fb3002a..1a82753f 100644 --- a/pkg/handler/eval_test.go +++ b/pkg/handler/eval_test.go @@ -478,6 +478,46 @@ func TestEvalFlagsByTags(t *testing.T) { }) } +func TestGetEvaluation(t *testing.T) { + t.Run("test empty query", func(t *testing.T) { + defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset() + e := NewEval() + resp := e.GetEvaluation(evaluation.GetEvaluationParams{}) + assert.NotNil(t, resp) + }) + + t.Run("test happy code path", func(t *testing.T) { + defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset() + e := NewEval() + enableDebug := true + flagID := int64(100) + resp := e.GetEvaluation(evaluation.GetEvaluationParams{ + Entity: "{\"id\":\"entityID1\",\"type\":\"entityType1\",\"ctx\":{\"dl_state\":\"CA\",\"state\":\"NY\"}}", + ID: &flagID, + Dbg: &enableDebug, + }) + assert.NotNil(t, resp) + }) +} + +func TestGetEvaluationBatch(t *testing.T) { + t.Run("test happy code path", func(t *testing.T) { + defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset() + e := NewEval() + enableDebug := true + resp := e.GetEvaluationBatch(evaluation.GetEvaluationBatchParams{ + Dbg: &enableDebug, + Entity: []string{ + "{\"id\":\"entityID1\",\"type\":\"entityType1\",\"ctx\":{\"dl_state\":\"CA\",\"state\":\"NY\"}}", + "{\"id\":\"entityID2\",\"type\":\"entityType2\",\"ctx\":{\"dl_state\":\"CA\",\"state\":\"NY\"}}", + }, + Ids: []int64{100, 200}, + Keys: []string{"flag_key_1", "flag_key_2"}, + }) + assert.NotNil(t, resp) + }) +} + func TestPostEvaluation(t *testing.T) { t.Run("test empty body", func(t *testing.T) { defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset() diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 43bbfbd1..96b40f52 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -81,6 +81,8 @@ func setupEvaluation(api *operations.FlagrAPI) { ec.Start() e := NewEval() + api.EvaluationGetEvaluationHandler = evaluation.GetEvaluationHandlerFunc(e.GetEvaluation) + api.EvaluationGetEvaluationBatchHandler = evaluation.GetEvaluationBatchHandlerFunc(e.GetEvaluationBatch) api.EvaluationPostEvaluationHandler = evaluation.PostEvaluationHandlerFunc(e.PostEvaluation) api.EvaluationPostEvaluationBatchHandler = evaluation.PostEvaluationBatchHandlerFunc(e.PostEvaluationBatch) diff --git a/swagger/evaluation.yaml b/swagger/evaluation.yaml index b5a09865..c47d8cc4 100644 --- a/swagger/evaluation.yaml +++ b/swagger/evaluation.yaml @@ -1,3 +1,60 @@ +get: + tags: + - evaluation + operationId: getEvaluation + parameters: + - in: query + name: entity + description: >- + JSON encoded "query optimized" evaluation entity: + ?entity={"id":"1","type":"a","ctx":{"foo":"bar"}} + required: true + type: string + - in: query + name: dbg + description: >- + "query optimized" enableDebug parameter + type: boolean + default: false + - in: query + name: id + description: >- + "query optimized" flagID parameter + required: false + type: integer + format: int64 + - in: query + name: key + description: >- + "query optimized" flagKey parameter + required: false + type: string + - in: query + name: tags + description: >- + "query optimized" flagTags parameter + required: false + type: array + collectionFormat: csv + items: + type: string + - in: query + name: all + description: >- + whether to use ALL (flagTags) semantics (ANY by default): + `?tags=foo,bar&all=true` is equivalent to postEvaluation's `flagTagsOperator: "ALL"` + required: false + type: boolean + default: false + responses: + 200: + description: evaluation result + schema: + $ref: "#/definitions/evalResult" + default: + description: generic error response + schema: + $ref: "#/definitions/error" post: tags: - evaluation diff --git a/swagger/evaluation_batch.yaml b/swagger/evaluation_batch.yaml index 76a101d4..846fb0ec 100644 --- a/swagger/evaluation_batch.yaml +++ b/swagger/evaluation_batch.yaml @@ -1,3 +1,74 @@ +get: + tags: + - evaluation + operationId: getEvaluationBatch + parameters: + - in: query + name: entity + description: >- + JSON encoded "query optimized" evaluation entities: + ?entity={"id":"1","type":"a","ctx":{"foo":"bar"}}&entity={"id":"2","ctx":{"baz":42}} + required: true + type: array + collectionFormat: multi + minItems: 1 + items: + type: string + - in: query + name: dbg + description: >- + "query optimized" enableDebug parameter + required: false + type: boolean + default: false + - in: query + name: ids + description: >- + "query optimized" flagIDs parameter + required: false + type: array + collectionFormat: csv + minItems: 1 + items: + type: integer + format: int64 + - in: query + name: keys + description: >- + "query optimized" flagKeys parameter + required: false + type: array + collectionFormat: csv + minItems: 1 + items: + type: string + minLength: 1 + - in: query + name: tags + description: >- + "query optimized" flagTags parameter + required: false + type: array + collectionFormat: csv + items: + type: string + - in: query + name: all + description: >- + whether to use ALL (flagTags) semantics (ANY by default): + `?tags=foo,bar&all=true` is equivalent to postEvaluationBatch's `flagTagsOperator: "ALL"` + required: false + type: boolean + default: false + responses: + 200: + description: evaluation batch result + schema: + $ref: "#/definitions/evaluationBatchResponse" + default: + description: generic error response + schema: + $ref: "#/definitions/error" post: tags: - evaluation diff --git a/swagger/index.yaml b/swagger/index.yaml index a2421b25..d7e65af4 100644 --- a/swagger/index.yaml +++ b/swagger/index.yaml @@ -532,6 +532,16 @@ definitions: type: string entityContext: type: object + getEvaluationEntity: + type: object + description: evaluationEntity's "query optimized" serialization + properties: + id: + type: string + type: + type: string + ctx: + type: object evaluationBatchRequest: type: object required: diff --git a/swagger_gen/models/get_evaluation_entity.go b/swagger_gen/models/get_evaluation_entity.go new file mode 100644 index 00000000..ddcf0b63 --- /dev/null +++ b/swagger_gen/models/get_evaluation_entity.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// GetEvaluationEntity evaluationEntity's "query optimized" serialization +// +// swagger:model getEvaluationEntity +type GetEvaluationEntity struct { + + // ctx + Ctx interface{} `json:"ctx,omitempty"` + + // id + ID string `json:"id,omitempty"` + + // type + Type string `json:"type,omitempty"` +} + +// Validate validates this get evaluation entity +func (m *GetEvaluationEntity) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this get evaluation entity based on context it is used +func (m *GetEvaluationEntity) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *GetEvaluationEntity) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *GetEvaluationEntity) UnmarshalBinary(b []byte) error { + var res GetEvaluationEntity + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/swagger_gen/restapi/embedded_spec.go b/swagger_gen/restapi/embedded_spec.go index 5051dc3a..00e4efd9 100644 --- a/swagger_gen/restapi/embedded_spec.go +++ b/swagger_gen/restapi/embedded_spec.go @@ -36,6 +36,72 @@ func init() { "basePath": "/api/v1", "paths": { "/evaluation": { + "get": { + "tags": [ + "evaluation" + ], + "operationId": "getEvaluation", + "parameters": [ + { + "type": "string", + "description": "JSON encoded \"query optimized\" evaluation entity: ?entity={\"id\":\"1\",\"type\":\"a\",\"ctx\":{\"foo\":\"bar\"}}", + "name": "entity", + "in": "query", + "required": true + }, + { + "type": "boolean", + "default": false, + "description": "\"query optimized\" enableDebug parameter", + "name": "dbg", + "in": "query" + }, + { + "type": "integer", + "format": "int64", + "description": "\"query optimized\" flagID parameter", + "name": "id", + "in": "query" + }, + { + "type": "string", + "description": "\"query optimized\" flagKey parameter", + "name": "key", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagTags parameter", + "name": "tags", + "in": "query" + }, + { + "type": "boolean", + "default": false, + "description": "whether to use ALL (flagTags) semantics (ANY by default): ` + "`" + `?tags=foo,bar\u0026all=true` + "`" + ` is equivalent to postEvaluation's ` + "`" + `flagTagsOperator: \"ALL\"` + "`" + `", + "name": "all", + "in": "query" + } + ], + "responses": { + "200": { + "description": "evaluation result", + "schema": { + "$ref": "#/definitions/evalResult" + } + }, + "default": { + "description": "generic error response", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, "post": { "tags": [ "evaluation" @@ -69,6 +135,88 @@ func init() { } }, "/evaluation/batch": { + "get": { + "tags": [ + "evaluation" + ], + "operationId": "getEvaluationBatch", + "parameters": [ + { + "minItems": 1, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi", + "description": "JSON encoded \"query optimized\" evaluation entities: ?entity={\"id\":\"1\",\"type\":\"a\",\"ctx\":{\"foo\":\"bar\"}}\u0026entity={\"id\":\"2\",\"ctx\":{\"baz\":42}}", + "name": "entity", + "in": "query", + "required": true + }, + { + "type": "boolean", + "default": false, + "description": "\"query optimized\" enableDebug parameter", + "name": "dbg", + "in": "query" + }, + { + "minItems": 1, + "type": "array", + "items": { + "type": "integer", + "format": "int64" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagIDs parameter", + "name": "ids", + "in": "query" + }, + { + "minItems": 1, + "type": "array", + "items": { + "minLength": 1, + "type": "string" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagKeys parameter", + "name": "keys", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagTags parameter", + "name": "tags", + "in": "query" + }, + { + "type": "boolean", + "default": false, + "description": "whether to use ALL (flagTags) semantics (ANY by default): ` + "`" + `?tags=foo,bar\u0026all=true` + "`" + ` is equivalent to postEvaluationBatch's ` + "`" + `flagTagsOperator: \"ALL\"` + "`" + `", + "name": "all", + "in": "query" + } + ], + "responses": { + "200": { + "description": "evaluation batch result", + "schema": { + "$ref": "#/definitions/evaluationBatchResponse" + } + }, + "default": { + "description": "generic error response", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, "post": { "tags": [ "evaluation" @@ -1843,6 +1991,21 @@ func init() { } } }, + "getEvaluationEntity": { + "description": "evaluationEntity's \"query optimized\" serialization", + "type": "object", + "properties": { + "ctx": { + "type": "object" + }, + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, "health": { "type": "object", "properties": { @@ -2133,6 +2296,72 @@ func init() { "basePath": "/api/v1", "paths": { "/evaluation": { + "get": { + "tags": [ + "evaluation" + ], + "operationId": "getEvaluation", + "parameters": [ + { + "type": "string", + "description": "JSON encoded \"query optimized\" evaluation entity: ?entity={\"id\":\"1\",\"type\":\"a\",\"ctx\":{\"foo\":\"bar\"}}", + "name": "entity", + "in": "query", + "required": true + }, + { + "type": "boolean", + "default": false, + "description": "\"query optimized\" enableDebug parameter", + "name": "dbg", + "in": "query" + }, + { + "type": "integer", + "format": "int64", + "description": "\"query optimized\" flagID parameter", + "name": "id", + "in": "query" + }, + { + "type": "string", + "description": "\"query optimized\" flagKey parameter", + "name": "key", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagTags parameter", + "name": "tags", + "in": "query" + }, + { + "type": "boolean", + "default": false, + "description": "whether to use ALL (flagTags) semantics (ANY by default): ` + "`" + `?tags=foo,bar\u0026all=true` + "`" + ` is equivalent to postEvaluation's ` + "`" + `flagTagsOperator: \"ALL\"` + "`" + `", + "name": "all", + "in": "query" + } + ], + "responses": { + "200": { + "description": "evaluation result", + "schema": { + "$ref": "#/definitions/evalResult" + } + }, + "default": { + "description": "generic error response", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, "post": { "tags": [ "evaluation" @@ -2166,6 +2395,88 @@ func init() { } }, "/evaluation/batch": { + "get": { + "tags": [ + "evaluation" + ], + "operationId": "getEvaluationBatch", + "parameters": [ + { + "minItems": 1, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi", + "description": "JSON encoded \"query optimized\" evaluation entities: ?entity={\"id\":\"1\",\"type\":\"a\",\"ctx\":{\"foo\":\"bar\"}}\u0026entity={\"id\":\"2\",\"ctx\":{\"baz\":42}}", + "name": "entity", + "in": "query", + "required": true + }, + { + "type": "boolean", + "default": false, + "description": "\"query optimized\" enableDebug parameter", + "name": "dbg", + "in": "query" + }, + { + "minItems": 1, + "type": "array", + "items": { + "type": "integer", + "format": "int64" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagIDs parameter", + "name": "ids", + "in": "query" + }, + { + "minItems": 1, + "type": "array", + "items": { + "minLength": 1, + "type": "string" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagKeys parameter", + "name": "keys", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "\"query optimized\" flagTags parameter", + "name": "tags", + "in": "query" + }, + { + "type": "boolean", + "default": false, + "description": "whether to use ALL (flagTags) semantics (ANY by default): ` + "`" + `?tags=foo,bar\u0026all=true` + "`" + ` is equivalent to postEvaluationBatch's ` + "`" + `flagTagsOperator: \"ALL\"` + "`" + `", + "name": "all", + "in": "query" + } + ], + "responses": { + "200": { + "description": "evaluation batch result", + "schema": { + "$ref": "#/definitions/evaluationBatchResponse" + } + }, + "default": { + "description": "generic error response", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, "post": { "tags": [ "evaluation" @@ -3942,6 +4253,21 @@ func init() { } } }, + "getEvaluationEntity": { + "description": "evaluationEntity's \"query optimized\" serialization", + "type": "object", + "properties": { + "ctx": { + "type": "object" + }, + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, "health": { "type": "object", "properties": { diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation.go b/swagger_gen/restapi/operations/evaluation/get_evaluation.go new file mode 100644 index 00000000..7ca1e55e --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetEvaluationHandlerFunc turns a function with the right signature into a get evaluation handler +type GetEvaluationHandlerFunc func(GetEvaluationParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetEvaluationHandlerFunc) Handle(params GetEvaluationParams) middleware.Responder { + return fn(params) +} + +// GetEvaluationHandler interface for that can handle valid get evaluation params +type GetEvaluationHandler interface { + Handle(GetEvaluationParams) middleware.Responder +} + +// NewGetEvaluation creates a new http.Handler for the get evaluation operation +func NewGetEvaluation(ctx *middleware.Context, handler GetEvaluationHandler) *GetEvaluation { + return &GetEvaluation{Context: ctx, Handler: handler} +} + +/* + GetEvaluation swagger:route GET /evaluation evaluation getEvaluation + +GetEvaluation get evaluation API +*/ +type GetEvaluation struct { + Context *middleware.Context + Handler GetEvaluationHandler +} + +func (o *GetEvaluation) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetEvaluationParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_batch.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch.go new file mode 100644 index 00000000..90a41f51 --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetEvaluationBatchHandlerFunc turns a function with the right signature into a get evaluation batch handler +type GetEvaluationBatchHandlerFunc func(GetEvaluationBatchParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetEvaluationBatchHandlerFunc) Handle(params GetEvaluationBatchParams) middleware.Responder { + return fn(params) +} + +// GetEvaluationBatchHandler interface for that can handle valid get evaluation batch params +type GetEvaluationBatchHandler interface { + Handle(GetEvaluationBatchParams) middleware.Responder +} + +// NewGetEvaluationBatch creates a new http.Handler for the get evaluation batch operation +func NewGetEvaluationBatch(ctx *middleware.Context, handler GetEvaluationBatchHandler) *GetEvaluationBatch { + return &GetEvaluationBatch{Context: ctx, Handler: handler} +} + +/* + GetEvaluationBatch swagger:route GET /evaluation/batch evaluation getEvaluationBatch + +GetEvaluationBatch get evaluation batch API +*/ +type GetEvaluationBatch struct { + Context *middleware.Context + Handler GetEvaluationBatchHandler +} + +func (o *GetEvaluationBatch) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetEvaluationBatchParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_parameters.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_parameters.go new file mode 100644 index 00000000..80d22871 --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_parameters.go @@ -0,0 +1,334 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// NewGetEvaluationBatchParams creates a new GetEvaluationBatchParams object +// with the default values initialized. +func NewGetEvaluationBatchParams() GetEvaluationBatchParams { + + var ( + // initialize parameters with default values + + allDefault = bool(false) + dbgDefault = bool(false) + ) + + return GetEvaluationBatchParams{ + All: &allDefault, + + Dbg: &dbgDefault, + } +} + +// GetEvaluationBatchParams contains all the bound params for the get evaluation batch operation +// typically these are obtained from a http.Request +// +// swagger:parameters getEvaluationBatch +type GetEvaluationBatchParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*whether to use ALL (flagTags) semantics (ANY by default): `?tags=foo,bar&all=true` is equivalent to postEvaluationBatch's `flagTagsOperator: "ALL"` + In: query + Default: false + */ + All *bool + /*"query optimized" enableDebug parameter + In: query + Default: false + */ + Dbg *bool + /*JSON encoded "query optimized" evaluation entities: ?entity={"id":"1","type":"a","ctx":{"foo":"bar"}}&entity={"id":"2","ctx":{"baz":42}} + Required: true + Min Items: 1 + In: query + Collection Format: multi + */ + Entity []string + /*"query optimized" flagIDs parameter + Min Items: 1 + In: query + Collection Format: csv + */ + Ids []int64 + /*"query optimized" flagKeys parameter + Min Items: 1 + In: query + Collection Format: csv + */ + Keys []string + /*"query optimized" flagTags parameter + In: query + Collection Format: csv + */ + Tags []string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetEvaluationBatchParams() beforehand. +func (o *GetEvaluationBatchParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qAll, qhkAll, _ := qs.GetOK("all") + if err := o.bindAll(qAll, qhkAll, route.Formats); err != nil { + res = append(res, err) + } + + qDbg, qhkDbg, _ := qs.GetOK("dbg") + if err := o.bindDbg(qDbg, qhkDbg, route.Formats); err != nil { + res = append(res, err) + } + + qEntity, qhkEntity, _ := qs.GetOK("entity") + if err := o.bindEntity(qEntity, qhkEntity, route.Formats); err != nil { + res = append(res, err) + } + + qIds, qhkIds, _ := qs.GetOK("ids") + if err := o.bindIds(qIds, qhkIds, route.Formats); err != nil { + res = append(res, err) + } + + qKeys, qhkKeys, _ := qs.GetOK("keys") + if err := o.bindKeys(qKeys, qhkKeys, route.Formats); err != nil { + res = append(res, err) + } + + qTags, qhkTags, _ := qs.GetOK("tags") + if err := o.bindTags(qTags, qhkTags, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindAll binds and validates parameter All from query. +func (o *GetEvaluationBatchParams) bindAll(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetEvaluationBatchParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("all", "query", "bool", raw) + } + o.All = &value + + return nil +} + +// bindDbg binds and validates parameter Dbg from query. +func (o *GetEvaluationBatchParams) bindDbg(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetEvaluationBatchParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("dbg", "query", "bool", raw) + } + o.Dbg = &value + + return nil +} + +// bindEntity binds and validates array parameter Entity from query. +// +// Arrays are parsed according to CollectionFormat: "multi" (defaults to "csv" when empty). +func (o *GetEvaluationBatchParams) bindEntity(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("entity", "query", rawData) + } + // CollectionFormat: multi + entityIC := rawData + if len(entityIC) == 0 { + return errors.Required("entity", "query", entityIC) + } + + var entityIR []string + for _, entityIV := range entityIC { + entityI := entityIV + + entityIR = append(entityIR, entityI) + } + + o.Entity = entityIR + if err := o.validateEntity(formats); err != nil { + return err + } + + return nil +} + +// validateEntity carries on validations for parameter Entity +func (o *GetEvaluationBatchParams) validateEntity(formats strfmt.Registry) error { + + entitySize := int64(len(o.Entity)) + + // minItems: 1 + if err := validate.MinItems("entity", "query", entitySize, 1); err != nil { + return err + } + return nil +} + +// bindIds binds and validates array parameter Ids from query. +// +// Arrays are parsed according to CollectionFormat: "csv" (defaults to "csv" when empty). +func (o *GetEvaluationBatchParams) bindIds(rawData []string, hasKey bool, formats strfmt.Registry) error { + var qvIds string + if len(rawData) > 0 { + qvIds = rawData[len(rawData)-1] + } + + // CollectionFormat: csv + idsIC := swag.SplitByFormat(qvIds, "csv") + if len(idsIC) == 0 { + return nil + } + + var idsIR []int64 + for i, idsIV := range idsIC { + // items.Format: "int64" + idsI, err := swag.ConvertInt64(idsIV) + if err != nil { + return errors.InvalidType(fmt.Sprintf("%s.%v", "ids", i), "query", "int64", idsI) + } + + idsIR = append(idsIR, idsI) + } + + o.Ids = idsIR + if err := o.validateIds(formats); err != nil { + return err + } + + return nil +} + +// validateIds carries on validations for parameter Ids +func (o *GetEvaluationBatchParams) validateIds(formats strfmt.Registry) error { + + idsSize := int64(len(o.Ids)) + + // minItems: 1 + if err := validate.MinItems("ids", "query", idsSize, 1); err != nil { + return err + } + return nil +} + +// bindKeys binds and validates array parameter Keys from query. +// +// Arrays are parsed according to CollectionFormat: "csv" (defaults to "csv" when empty). +func (o *GetEvaluationBatchParams) bindKeys(rawData []string, hasKey bool, formats strfmt.Registry) error { + var qvKeys string + if len(rawData) > 0 { + qvKeys = rawData[len(rawData)-1] + } + + // CollectionFormat: csv + keysIC := swag.SplitByFormat(qvKeys, "csv") + if len(keysIC) == 0 { + return nil + } + + var keysIR []string + for i, keysIV := range keysIC { + keysI := keysIV + + if err := validate.MinLength(fmt.Sprintf("%s.%v", "keys", i), "query", keysI, 1); err != nil { + return err + } + + keysIR = append(keysIR, keysI) + } + + o.Keys = keysIR + if err := o.validateKeys(formats); err != nil { + return err + } + + return nil +} + +// validateKeys carries on validations for parameter Keys +func (o *GetEvaluationBatchParams) validateKeys(formats strfmt.Registry) error { + + keysSize := int64(len(o.Keys)) + + // minItems: 1 + if err := validate.MinItems("keys", "query", keysSize, 1); err != nil { + return err + } + return nil +} + +// bindTags binds and validates array parameter Tags from query. +// +// Arrays are parsed according to CollectionFormat: "csv" (defaults to "csv" when empty). +func (o *GetEvaluationBatchParams) bindTags(rawData []string, hasKey bool, formats strfmt.Registry) error { + var qvTags string + if len(rawData) > 0 { + qvTags = rawData[len(rawData)-1] + } + + // CollectionFormat: csv + tagsIC := swag.SplitByFormat(qvTags, "csv") + if len(tagsIC) == 0 { + return nil + } + + var tagsIR []string + for _, tagsIV := range tagsIC { + tagsI := tagsIV + + tagsIR = append(tagsIR, tagsI) + } + + o.Tags = tagsIR + + return nil +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_responses.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_responses.go new file mode 100644 index 00000000..b7415dac --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_responses.go @@ -0,0 +1,118 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/openflagr/flagr/swagger_gen/models" +) + +// GetEvaluationBatchOKCode is the HTTP code returned for type GetEvaluationBatchOK +const GetEvaluationBatchOKCode int = 200 + +/* +GetEvaluationBatchOK evaluation batch result + +swagger:response getEvaluationBatchOK +*/ +type GetEvaluationBatchOK struct { + + /* + In: Body + */ + Payload *models.EvaluationBatchResponse `json:"body,omitempty"` +} + +// NewGetEvaluationBatchOK creates GetEvaluationBatchOK with default headers values +func NewGetEvaluationBatchOK() *GetEvaluationBatchOK { + + return &GetEvaluationBatchOK{} +} + +// WithPayload adds the payload to the get evaluation batch o k response +func (o *GetEvaluationBatchOK) WithPayload(payload *models.EvaluationBatchResponse) *GetEvaluationBatchOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get evaluation batch o k response +func (o *GetEvaluationBatchOK) SetPayload(payload *models.EvaluationBatchResponse) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetEvaluationBatchOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/* +GetEvaluationBatchDefault generic error response + +swagger:response getEvaluationBatchDefault +*/ +type GetEvaluationBatchDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetEvaluationBatchDefault creates GetEvaluationBatchDefault with default headers values +func NewGetEvaluationBatchDefault(code int) *GetEvaluationBatchDefault { + if code <= 0 { + code = 500 + } + + return &GetEvaluationBatchDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get evaluation batch default response +func (o *GetEvaluationBatchDefault) WithStatusCode(code int) *GetEvaluationBatchDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get evaluation batch default response +func (o *GetEvaluationBatchDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get evaluation batch default response +func (o *GetEvaluationBatchDefault) WithPayload(payload *models.Error) *GetEvaluationBatchDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get evaluation batch default response +func (o *GetEvaluationBatchDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetEvaluationBatchDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_urlbuilder.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_urlbuilder.go new file mode 100644 index 00000000..882b8c3e --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_batch_urlbuilder.go @@ -0,0 +1,183 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + + "github.com/go-openapi/swag" +) + +// GetEvaluationBatchURL generates an URL for the get evaluation batch operation +type GetEvaluationBatchURL struct { + All *bool + Dbg *bool + Entity []string + Ids []int64 + Keys []string + Tags []string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetEvaluationBatchURL) WithBasePath(bp string) *GetEvaluationBatchURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetEvaluationBatchURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetEvaluationBatchURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/evaluation/batch" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/api/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var allQ string + if o.All != nil { + allQ = swag.FormatBool(*o.All) + } + if allQ != "" { + qs.Set("all", allQ) + } + + var dbgQ string + if o.Dbg != nil { + dbgQ = swag.FormatBool(*o.Dbg) + } + if dbgQ != "" { + qs.Set("dbg", dbgQ) + } + + var entityIR []string + for _, entityI := range o.Entity { + entityIS := entityI + if entityIS != "" { + entityIR = append(entityIR, entityIS) + } + } + + entity := swag.JoinByFormat(entityIR, "multi") + + for _, qsv := range entity { + qs.Add("entity", qsv) + } + + var idsIR []string + for _, idsI := range o.Ids { + idsIS := swag.FormatInt64(idsI) + if idsIS != "" { + idsIR = append(idsIR, idsIS) + } + } + + ids := swag.JoinByFormat(idsIR, "csv") + + if len(ids) > 0 { + qsv := ids[0] + if qsv != "" { + qs.Set("ids", qsv) + } + } + + var keysIR []string + for _, keysI := range o.Keys { + keysIS := keysI + if keysIS != "" { + keysIR = append(keysIR, keysIS) + } + } + + keys := swag.JoinByFormat(keysIR, "csv") + + if len(keys) > 0 { + qsv := keys[0] + if qsv != "" { + qs.Set("keys", qsv) + } + } + + var tagsIR []string + for _, tagsI := range o.Tags { + tagsIS := tagsI + if tagsIS != "" { + tagsIR = append(tagsIR, tagsIS) + } + } + + tags := swag.JoinByFormat(tagsIR, "csv") + + if len(tags) > 0 { + qsv := tags[0] + if qsv != "" { + qs.Set("tags", qsv) + } + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetEvaluationBatchURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetEvaluationBatchURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetEvaluationBatchURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetEvaluationBatchURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetEvaluationBatchURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetEvaluationBatchURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_parameters.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_parameters.go new file mode 100644 index 00000000..63badfa8 --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_parameters.go @@ -0,0 +1,257 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// NewGetEvaluationParams creates a new GetEvaluationParams object +// with the default values initialized. +func NewGetEvaluationParams() GetEvaluationParams { + + var ( + // initialize parameters with default values + + allDefault = bool(false) + dbgDefault = bool(false) + ) + + return GetEvaluationParams{ + All: &allDefault, + + Dbg: &dbgDefault, + } +} + +// GetEvaluationParams contains all the bound params for the get evaluation operation +// typically these are obtained from a http.Request +// +// swagger:parameters getEvaluation +type GetEvaluationParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*whether to use ALL (flagTags) semantics (ANY by default): `?tags=foo,bar&all=true` is equivalent to postEvaluation's `flagTagsOperator: "ALL"` + In: query + Default: false + */ + All *bool + /*"query optimized" enableDebug parameter + In: query + Default: false + */ + Dbg *bool + /*JSON encoded "query optimized" evaluation entity: ?entity={"id":"1","type":"a","ctx":{"foo":"bar"}} + Required: true + In: query + */ + Entity string + /*"query optimized" flagID parameter + In: query + */ + ID *int64 + /*"query optimized" flagKey parameter + In: query + */ + Key *string + /*"query optimized" flagTags parameter + In: query + Collection Format: csv + */ + Tags []string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetEvaluationParams() beforehand. +func (o *GetEvaluationParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qAll, qhkAll, _ := qs.GetOK("all") + if err := o.bindAll(qAll, qhkAll, route.Formats); err != nil { + res = append(res, err) + } + + qDbg, qhkDbg, _ := qs.GetOK("dbg") + if err := o.bindDbg(qDbg, qhkDbg, route.Formats); err != nil { + res = append(res, err) + } + + qEntity, qhkEntity, _ := qs.GetOK("entity") + if err := o.bindEntity(qEntity, qhkEntity, route.Formats); err != nil { + res = append(res, err) + } + + qID, qhkID, _ := qs.GetOK("id") + if err := o.bindID(qID, qhkID, route.Formats); err != nil { + res = append(res, err) + } + + qKey, qhkKey, _ := qs.GetOK("key") + if err := o.bindKey(qKey, qhkKey, route.Formats); err != nil { + res = append(res, err) + } + + qTags, qhkTags, _ := qs.GetOK("tags") + if err := o.bindTags(qTags, qhkTags, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindAll binds and validates parameter All from query. +func (o *GetEvaluationParams) bindAll(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetEvaluationParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("all", "query", "bool", raw) + } + o.All = &value + + return nil +} + +// bindDbg binds and validates parameter Dbg from query. +func (o *GetEvaluationParams) bindDbg(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetEvaluationParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("dbg", "query", "bool", raw) + } + o.Dbg = &value + + return nil +} + +// bindEntity binds and validates parameter Entity from query. +func (o *GetEvaluationParams) bindEntity(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("entity", "query", rawData) + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + + if err := validate.RequiredString("entity", "query", raw); err != nil { + return err + } + o.Entity = raw + + return nil +} + +// bindID binds and validates parameter ID from query. +func (o *GetEvaluationParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertInt64(raw) + if err != nil { + return errors.InvalidType("id", "query", "int64", raw) + } + o.ID = &value + + return nil +} + +// bindKey binds and validates parameter Key from query. +func (o *GetEvaluationParams) bindKey(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + o.Key = &raw + + return nil +} + +// bindTags binds and validates array parameter Tags from query. +// +// Arrays are parsed according to CollectionFormat: "csv" (defaults to "csv" when empty). +func (o *GetEvaluationParams) bindTags(rawData []string, hasKey bool, formats strfmt.Registry) error { + var qvTags string + if len(rawData) > 0 { + qvTags = rawData[len(rawData)-1] + } + + // CollectionFormat: csv + tagsIC := swag.SplitByFormat(qvTags, "csv") + if len(tagsIC) == 0 { + return nil + } + + var tagsIR []string + for _, tagsIV := range tagsIC { + tagsI := tagsIV + + tagsIR = append(tagsIR, tagsI) + } + + o.Tags = tagsIR + + return nil +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_responses.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_responses.go new file mode 100644 index 00000000..f63a0cf9 --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_responses.go @@ -0,0 +1,118 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/openflagr/flagr/swagger_gen/models" +) + +// GetEvaluationOKCode is the HTTP code returned for type GetEvaluationOK +const GetEvaluationOKCode int = 200 + +/* +GetEvaluationOK evaluation result + +swagger:response getEvaluationOK +*/ +type GetEvaluationOK struct { + + /* + In: Body + */ + Payload *models.EvalResult `json:"body,omitempty"` +} + +// NewGetEvaluationOK creates GetEvaluationOK with default headers values +func NewGetEvaluationOK() *GetEvaluationOK { + + return &GetEvaluationOK{} +} + +// WithPayload adds the payload to the get evaluation o k response +func (o *GetEvaluationOK) WithPayload(payload *models.EvalResult) *GetEvaluationOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get evaluation o k response +func (o *GetEvaluationOK) SetPayload(payload *models.EvalResult) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetEvaluationOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/* +GetEvaluationDefault generic error response + +swagger:response getEvaluationDefault +*/ +type GetEvaluationDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetEvaluationDefault creates GetEvaluationDefault with default headers values +func NewGetEvaluationDefault(code int) *GetEvaluationDefault { + if code <= 0 { + code = 500 + } + + return &GetEvaluationDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get evaluation default response +func (o *GetEvaluationDefault) WithStatusCode(code int) *GetEvaluationDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get evaluation default response +func (o *GetEvaluationDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get evaluation default response +func (o *GetEvaluationDefault) WithPayload(payload *models.Error) *GetEvaluationDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get evaluation default response +func (o *GetEvaluationDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetEvaluationDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/swagger_gen/restapi/operations/evaluation/get_evaluation_urlbuilder.go b/swagger_gen/restapi/operations/evaluation/get_evaluation_urlbuilder.go new file mode 100644 index 00000000..948e7785 --- /dev/null +++ b/swagger_gen/restapi/operations/evaluation/get_evaluation_urlbuilder.go @@ -0,0 +1,156 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package evaluation + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + + "github.com/go-openapi/swag" +) + +// GetEvaluationURL generates an URL for the get evaluation operation +type GetEvaluationURL struct { + All *bool + Dbg *bool + Entity string + ID *int64 + Key *string + Tags []string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetEvaluationURL) WithBasePath(bp string) *GetEvaluationURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetEvaluationURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetEvaluationURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/evaluation" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/api/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var allQ string + if o.All != nil { + allQ = swag.FormatBool(*o.All) + } + if allQ != "" { + qs.Set("all", allQ) + } + + var dbgQ string + if o.Dbg != nil { + dbgQ = swag.FormatBool(*o.Dbg) + } + if dbgQ != "" { + qs.Set("dbg", dbgQ) + } + + entityQ := o.Entity + if entityQ != "" { + qs.Set("entity", entityQ) + } + + var idQ string + if o.ID != nil { + idQ = swag.FormatInt64(*o.ID) + } + if idQ != "" { + qs.Set("id", idQ) + } + + var keyQ string + if o.Key != nil { + keyQ = *o.Key + } + if keyQ != "" { + qs.Set("key", keyQ) + } + + var tagsIR []string + for _, tagsI := range o.Tags { + tagsIS := tagsI + if tagsIS != "" { + tagsIR = append(tagsIR, tagsIS) + } + } + + tags := swag.JoinByFormat(tagsIR, "csv") + + if len(tags) > 0 { + qsv := tags[0] + if qsv != "" { + qs.Set("tags", qsv) + } + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetEvaluationURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetEvaluationURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetEvaluationURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetEvaluationURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetEvaluationURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetEvaluationURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/swagger_gen/restapi/operations/flagr_api.go b/swagger_gen/restapi/operations/flagr_api.go index 40457e65..ab8c9b05 100644 --- a/swagger_gen/restapi/operations/flagr_api.go +++ b/swagger_gen/restapi/operations/flagr_api.go @@ -104,6 +104,12 @@ func NewFlagrAPI(spec *loads.Document) *FlagrAPI { VariantFindVariantsHandler: variant.FindVariantsHandlerFunc(func(params variant.FindVariantsParams) middleware.Responder { return middleware.NotImplemented("operation variant.FindVariants has not yet been implemented") }), + EvaluationGetEvaluationHandler: evaluation.GetEvaluationHandlerFunc(func(params evaluation.GetEvaluationParams) middleware.Responder { + return middleware.NotImplemented("operation evaluation.GetEvaluation has not yet been implemented") + }), + EvaluationGetEvaluationBatchHandler: evaluation.GetEvaluationBatchHandlerFunc(func(params evaluation.GetEvaluationBatchParams) middleware.Responder { + return middleware.NotImplemented("operation evaluation.GetEvaluationBatch has not yet been implemented") + }), ExportGetExportEvalCacheJSONHandler: export.GetExportEvalCacheJSONHandlerFunc(func(params export.GetExportEvalCacheJSONParams) middleware.Responder { return middleware.NotImplemented("operation export.GetExportEvalCacheJSON has not yet been implemented") }), @@ -226,6 +232,10 @@ type FlagrAPI struct { TagFindTagsHandler tag.FindTagsHandler // VariantFindVariantsHandler sets the operation handler for the find variants operation VariantFindVariantsHandler variant.FindVariantsHandler + // EvaluationGetEvaluationHandler sets the operation handler for the get evaluation operation + EvaluationGetEvaluationHandler evaluation.GetEvaluationHandler + // EvaluationGetEvaluationBatchHandler sets the operation handler for the get evaluation batch operation + EvaluationGetEvaluationBatchHandler evaluation.GetEvaluationBatchHandler // ExportGetExportEvalCacheJSONHandler sets the operation handler for the get export eval cache JSON operation ExportGetExportEvalCacheJSONHandler export.GetExportEvalCacheJSONHandler // ExportGetExportSqliteHandler sets the operation handler for the get export sqlite operation @@ -389,6 +399,12 @@ func (o *FlagrAPI) Validate() error { if o.VariantFindVariantsHandler == nil { unregistered = append(unregistered, "variant.FindVariantsHandler") } + if o.EvaluationGetEvaluationHandler == nil { + unregistered = append(unregistered, "evaluation.GetEvaluationHandler") + } + if o.EvaluationGetEvaluationBatchHandler == nil { + unregistered = append(unregistered, "evaluation.GetEvaluationBatchHandler") + } if o.ExportGetExportEvalCacheJSONHandler == nil { unregistered = append(unregistered, "export.GetExportEvalCacheJSONHandler") } @@ -598,6 +614,14 @@ func (o *FlagrAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) } + o.handlers["GET"]["/evaluation"] = evaluation.NewGetEvaluation(o.context, o.EvaluationGetEvaluationHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/evaluation/batch"] = evaluation.NewGetEvaluationBatch(o.context, o.EvaluationGetEvaluationBatchHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } o.handlers["GET"]["/export/eval_cache/json"] = export.NewGetExportEvalCacheJSON(o.context, o.ExportGetExportEvalCacheJSONHandler) if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler)