Skip to content

Commit

Permalink
Update swagger to include new event tracking. (#49)
Browse files Browse the repository at this point in the history
* Update swagger to include event tracking route.
* Use middleware.GetLogger(r) to include necessary structured fields.
  • Loading branch information
Mike Davis authored Oct 21, 2019
1 parent 21a9879 commit 18b420c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
30 changes: 30 additions & 0 deletions api/openapi-spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,28 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/UserEvent'
/users/{userId}/events/{eventKey}:
parameters:
- $ref: '#/components/parameters/sdkKeyParam'
- $ref: '#/components/parameters/userIdParam'
- $ref: '#/components/parameters/eventKeyParam'
- $ref: '#/components/parameters/attributesParam'
post:
summary: Track event for the given user.
operationId: trackEvent
description: todo
responses:
'204':
description: No content, user not included in the experiment
'404':
description: Event does not exist
requestBody:
required: false
content:
application/json:
schema:
type: object
additionalProperties: true
/users/{userId}/experiments/{experimentKey}:
parameters:
- $ref: '#/components/parameters/sdkKeyParam'
Expand Down Expand Up @@ -265,10 +287,18 @@ components:
attributesParam:
in: query
name: attributes
required: false
schema:
type: object
additionalProperties:
type: string
eventKeyParam:
in: path
name: eventKey
required: true
description: Key of the event we're tracking
schema:
type: string
experimentKeyParam:
in: path
name: experimentKey
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/handlers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"net/http"

"github.com/go-chi/render"
"github.com/optimizely/sidedoor/pkg/api/middleware"
"github.com/optimizely/sidedoor/pkg/api/models"
"github.com/rs/zerolog/log"
)

// RenderError sets the request status and renders the error message.
Expand All @@ -41,19 +41,19 @@ func ParseRequestBody(r *http.Request, v interface{}) error {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
msg := "error reading request body"
log.Error().Err(err).Msg(msg)
middleware.GetLogger(r).Error().Err(err).Msg(msg)
return fmt.Errorf(msg)
}

if len(body) == 0 {
log.Debug().Msg("body was empty skip JSON unmarshal")
middleware.GetLogger(r).Debug().Msg("body was empty skip JSON unmarshal")
return nil
}

err = json.Unmarshal(body, &v)
if err != nil {
msg := "error parsing request body"
log.Error().Err(err).Msg(msg)
middleware.GetLogger(r).Error().Err(err).Msg(msg)
return fmt.Errorf(msg)
}

Expand Down

0 comments on commit 18b420c

Please sign in to comment.