Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fs3 600 #20

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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