From b9b63946301bf14d089f4a4b31b92761b80f2b57 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 13 Nov 2022 00:21:29 -0500 Subject: [PATCH] add more examples to openapi.yaml (#7) --- api/message_bus/openapi.yaml | 38 +++++++++++++++++++++++++++++++++--- route/adapter/in/event.go | 6 +++--- route/adapter/out/event.go | 6 +++--- route/api_route_event.go | 6 +++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/api/message_bus/openapi.yaml b/api/message_bus/openapi.yaml index 28e630b..f97bc01 100644 --- a/api/message_bus/openapi.yaml +++ b/api/message_bus/openapi.yaml @@ -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 @@ -296,7 +295,7 @@ components: items: type: string example: "local-storage:disk:added,local-storage:disk:removed" - + ActionName: name: name in: path @@ -463,7 +462,7 @@ components: name: type: string description: property name - example: "local-storage:path" + example: "local-storage:vendor" EventType: type: object @@ -487,6 +486,14 @@ 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 @@ -494,24 +501,47 @@ components: 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 @@ -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 diff --git a/route/adapter/in/event.go b/route/adapter/in/event.go index 2e4bb96..5d1717f 100644 --- a/route/adapter/in/event.go +++ b/route/adapter/in/event.go @@ -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)) } @@ -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, } diff --git a/route/adapter/out/event.go b/route/adapter/out/event.go index 1b0d6c2..7eca2dc 100644 --- a/route/adapter/out/event.go +++ b/route/adapter/out/event.go @@ -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)), } } diff --git a/route/api_route_event.go b/route/api_route_event.go index 9342ea8..c941673 100644 --- a/route/api_route_event.go +++ b/route/api_route_event.go @@ -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()), }