Skip to content

Commit

Permalink
Merge pull request #18 from flagship-io/FS3-600
Browse files Browse the repository at this point in the history
Fs3 600
  • Loading branch information
kjose authored Aug 26, 2022
2 parents b787120 + 21e37f0 commit d0eacee
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 37 deletions.
154 changes: 142 additions & 12 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
// This file was generated by swaggo/swag
package docs

import "github.com/swaggo/swag"
import (
"bytes"
"encoding/json"
"strings"
"text/template"

const docTemplate = `{
"github.com/swaggo/swag"
)

var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
Expand Down Expand Up @@ -169,6 +176,56 @@ const docTemplate = `{
}
}
},
"/flags": {
"post": {
"description": "Get all flags value and metadata for a visitor ID and context",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Flags"
],
"summary": "Get all flags",
"operationId": "get-flags",
"parameters": [
{
"description": "Flag request body",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handlers.campaignsBodySwagger"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/handlers.FlagInfo"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.errorMessage"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.errorMessage"
}
}
}
}
},
"/metrics": {
"get": {
"description": "Gets the metrics like memory consumption \u0026 allocation as well as response time histograms to use with monitoring tools",
Expand All @@ -192,6 +249,38 @@ const docTemplate = `{
}
},
"definitions": {
"handlers.FlagInfo": {
"type": "object",
"properties": {
"metadata": {
"$ref": "#/definitions/handlers.FlagMetadata"
},
"value": {}
}
},
"handlers.FlagMetadata": {
"type": "object",
"properties": {
"campaignId": {
"type": "string"
},
"reference": {
"type": "boolean"
},
"slug": {
"type": "string"
},
"type": {
"type": "string"
},
"variationGroupId": {
"type": "string"
},
"variationId": {
"type": "string"
}
}
},
"handlers.MetricsResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -291,6 +380,9 @@ const docTemplate = `{
"trigger_hit": {
"type": "boolean"
},
"visitor_consent": {
"type": "boolean"
},
"visitor_id": {
"type": "string"
}
Expand Down Expand Up @@ -350,18 +442,56 @@ const docTemplate = `{
}
}`

type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "2.0",
Host: "",
BasePath: "/v2",
Schemes: []string{},
Title: "Flagship Decision API",
Description: "This is the Flagship Decision API documentation",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
var SwaggerInfo = swaggerInfo{
Version: "2.0",
Host: "",
BasePath: "/v2",
Schemes: []string{},
Title: "Flagship Decision API",
Description: "This is the Flagship Decision API documentation",
}

type s struct{}

func (s *s) ReadDoc() string {
sInfo := SwaggerInfo
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)

t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
},
"escape": func(v interface{}) string {
// escape tabs
str := strings.Replace(v.(string), "\t", "\\t", -1)
// replace " with \", and if that results in \\", replace that with \\\"
str = strings.Replace(str, "\"", "\\\"", -1)
return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
},
}).Parse(doc)
if err != nil {
return doc
}

var tpl bytes.Buffer
if err := t.Execute(&tpl, sInfo); err != nil {
return doc
}

return tpl.String()
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
swag.Register("swagger", &s{})
}
85 changes: 85 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,56 @@
}
}
},
"/flags": {
"post": {
"description": "Get all flags value and metadata for a visitor ID and context",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Flags"
],
"summary": "Get all flags",
"operationId": "get-flags",
"parameters": [
{
"description": "Flag request body",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handlers.campaignsBodySwagger"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/handlers.FlagInfo"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.errorMessage"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.errorMessage"
}
}
}
}
},
"/metrics": {
"get": {
"description": "Gets the metrics like memory consumption \u0026 allocation as well as response time histograms to use with monitoring tools",
Expand All @@ -184,6 +234,38 @@
}
},
"definitions": {
"handlers.FlagInfo": {
"type": "object",
"properties": {
"metadata": {
"$ref": "#/definitions/handlers.FlagMetadata"
},
"value": {}
}
},
"handlers.FlagMetadata": {
"type": "object",
"properties": {
"campaignId": {
"type": "string"
},
"reference": {
"type": "boolean"
},
"slug": {
"type": "string"
},
"type": {
"type": "string"
},
"variationGroupId": {
"type": "string"
},
"variationId": {
"type": "string"
}
}
},
"handlers.MetricsResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -283,6 +365,9 @@
"trigger_hit": {
"type": "boolean"
},
"visitor_consent": {
"type": "boolean"
},
"visitor_id": {
"type": "string"
}
Expand Down
56 changes: 56 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
basePath: /v2
definitions:
handlers.FlagInfo:
properties:
metadata:
$ref: '#/definitions/handlers.FlagMetadata'
value: {}
type: object
handlers.FlagMetadata:
properties:
campaignId:
type: string
reference:
type: boolean
slug:
type: string
type:
type: string
variationGroupId:
type: string
variationId:
type: string
type: object
handlers.MetricsResponse:
properties:
cmdline:
Expand Down Expand Up @@ -64,6 +85,8 @@ definitions:
$ref: '#/definitions/handlers.campaignsBodyContextSwagger'
trigger_hit:
type: boolean
visitor_consent:
type: boolean
visitor_id:
type: string
required:
Expand Down Expand Up @@ -210,6 +233,39 @@ paths:
summary: Get a single campaigns for the visitor
tags:
- Campaigns
/flags:
post:
consumes:
- application/json
description: Get all flags value and metadata for a visitor ID and context
operationId: get-flags
parameters:
- description: Flag request body
in: body
name: request
required: true
schema:
$ref: '#/definitions/handlers.campaignsBodySwagger'
produces:
- application/json
responses:
"200":
description: OK
schema:
additionalProperties:
$ref: '#/definitions/handlers.FlagInfo'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/handlers.errorMessage'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.errorMessage'
summary: Get all flags
tags:
- Flags
/metrics:
get:
description: Gets the metrics like memory consumption & allocation as well as
Expand Down
6 changes: 6 additions & 0 deletions internal/apilogic/handle_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apilogic

import (
"net/http"
"strings"

"github.com/flagship-io/decision-api/internal/handle"
"github.com/flagship-io/decision-api/internal/utils"
Expand All @@ -23,6 +24,11 @@ func BuildHandleRequest(req *http.Request) (*handle.Request, error) {
handleRequest.Mode = mode
}

// exposeAllKeys default true for flags route
if strings.Contains(req.URL.String(), "/flags") {
handleRequest.ExposeAllKeys = true
}
// exposeAllKeys url param extend
exposeAllKeys := req.URL.Query().Get("exposeAllKeys")
if exposeAllKeys != "" {
handleRequest.ExposeAllKeys = exposeAllKeys == "true"
Expand Down
Loading

0 comments on commit d0eacee

Please sign in to comment.