Skip to content

Commit

Permalink
add more examples to openapi.yaml (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerinus authored Nov 13, 2022
1 parent 96e7b71 commit b9b6394
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
38 changes: 35 additions & 3 deletions api/message_bus/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ paths:
The connection will be upgraded to a WebSocket connection and the client will receive actions as they are triggered.
components:

securitySchemes:
access_token:
type: apiKey
Expand Down Expand Up @@ -296,7 +295,7 @@ components:
items:
type: string
example: "local-storage:disk:added,local-storage:disk:removed"

ActionName:
name: name
in: path
Expand Down Expand Up @@ -463,7 +462,7 @@ components:
name:
type: string
description: property name
example: "local-storage:path"
example: "local-storage:vendor"

EventType:
type: object
Expand All @@ -487,31 +486,62 @@ components:
type: array
items:
$ref: "#/components/schemas/PropertyType"
example:
- "local-storage:vendor"
- "local-storage:model"
- "local-storage:uuid"
- "casaos-ui:type"
- "casaos-ui:title"
- "casaos-ui:icon-1"
- "casaos-ui:message-1"

Property:
type: object
properties:
name:
type: string
description: property name
example: "local-storage:vendor"
value:
type: string
description: property value
example: "SanDisk"

Event:
type: object
required:
- "sourceID"
- "name"
- "properties"
properties:
sourceID:
type: string
description: associated source id
example: "local-storage"
name:
type: string
description: event name
example: "local-storage:disk:added"
properties:
type: array
description: event properties
items:
$ref: "#/components/schemas/Property"
example:
- name: local-storage:vendor
value: SanDisk
- name: local-storage:model
value: Cruzer
- name: local-storage:uuid
value: 442e0e5b-9d3e-4fe8-b46f-9c4141fdecd7
- name: casaos-ui:type
value: notification-style-2
- name: casaos-ui:title
value: "New disk found"
- name: casaos-ui:icon-1
value: casaos-icon-disk
- name: casaos-ui:message-1
value: "A new disk, SanDisk Cruzer, is added."
timestamp:
type: string
description: timestamp this event took place
Expand Down Expand Up @@ -546,9 +576,11 @@ components:
sourceID:
type: string
description: associated source id
example: "local-storage"
name:
type: string
description: action name
example: "local-storage:disk:format"
properties:
type: array
description: action properties
Expand Down
6 changes: 3 additions & 3 deletions route/adapter/in/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func EventAdapter(event codegen.Event) model.Event {
properties := make([]model.Property, 0)
for _, property := range *event.Properties {
for _, property := range event.Properties {
properties = append(properties, PropertyAdapter(property))
}

Expand All @@ -17,8 +17,8 @@ func EventAdapter(event codegen.Event) model.Event {
}

return model.Event{
SourceID: *event.SourceID,
Name: *event.Name,
SourceID: event.SourceID,
Name: event.Name,
Properties: properties,
Timestamp: timestamp,
}
Expand Down
6 changes: 3 additions & 3 deletions route/adapter/out/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func EventAdapter(event model.Event) codegen.Event {
}

return codegen.Event{
SourceID: &event.SourceID,
Name: &event.Name,
Properties: &properties,
SourceID: event.SourceID,
Name: event.Name,
Properties: properties,
Timestamp: utils.Ptr(time.Unix(event.Timestamp, 0)),
}
}
6 changes: 3 additions & 3 deletions route/api_route_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func (r *APIRoute) PublishEvent(ctx echo.Context, sourceID codegen.SourceID, nam
}

event := codegen.Event{
SourceID: &sourceID,
Name: &name,
Properties: &properties,
SourceID: sourceID,
Name: name,
Properties: properties,
Timestamp: utils.Ptr(time.Now()),
}

Expand Down

0 comments on commit b9b6394

Please sign in to comment.