From 564560e07be35d596799084566a7c706dae79153 Mon Sep 17 00:00:00 2001 From: litleleprikon Date: Fri, 18 Oct 2019 16:06:00 +0300 Subject: [PATCH] docs(openapi): Add basic openapi structure Create basic openapi sctructure for future contributions Relates #44 --- api/main.yml | 15 ++++++ api/triggers/methods.yml | 11 ++++ api/triggers/responses/put.yml | 12 +++++ api/triggers/schemas/req_put.yml | 89 ++++++++++++++++++++++++++++++++ api/triggers/schemas/res_put.yml | 18 +++++++ 5 files changed, 145 insertions(+) create mode 100644 api/main.yml create mode 100644 api/triggers/methods.yml create mode 100644 api/triggers/responses/put.yml create mode 100644 api/triggers/schemas/req_put.yml create mode 100644 api/triggers/schemas/res_put.yml diff --git a/api/main.yml b/api/main.yml new file mode 100644 index 0000000..a8443b7 --- /dev/null +++ b/api/main.yml @@ -0,0 +1,15 @@ +openapi: 3.0.0 +info: + description: "This is an API description for Moira Alert project. Please check https://github.com/moira-alert" + version: "2.5.1" + title: "Moira Alert" + # contact: + # link: "https://t.me/moira_alert" + license: + name: "MIT" +servers: + - url: http://localhost:8080/api + description: Localhost server +paths: + /trigger: + $ref: ./triggers/methods.yml diff --git a/api/triggers/methods.yml b/api/triggers/methods.yml new file mode 100644 index 0000000..071367e --- /dev/null +++ b/api/triggers/methods.yml @@ -0,0 +1,11 @@ +put: + summary: "Create new trigger" + description: "" + requestBody: + required: true + content: + application/json: + schema: + $ref: ./schemas/req_put.yml + responses: + $ref: ./responses/put.yml diff --git a/api/triggers/responses/put.yml b/api/triggers/responses/put.yml new file mode 100644 index 0000000..cd81e23 --- /dev/null +++ b/api/triggers/responses/put.yml @@ -0,0 +1,12 @@ +200: + description: "Trigger created" + content: + application/json: + schema: + $ref: ../schemas/res_put.yml#/200 +400: + description: "Invalid input" + content: + application/json: + schema: + $ref: ../schemas/res_put.yml#/400 diff --git a/api/triggers/schemas/req_put.yml b/api/triggers/schemas/req_put.yml new file mode 100644 index 0000000..60dec80 --- /dev/null +++ b/api/triggers/schemas/req_put.yml @@ -0,0 +1,89 @@ +$schema: "http://json-schema.org/draft-04/schema#" +properties: + desc: + type: string + description: Trigger description + example: Dice roll trigger + error_value: + type: number + description: Target value at which error will be fired + example: 7 + expression: + type: string + description: Expression that will be evaluated + example: "t1 > 6 ? ERROR : (t1 > 4)? WARN : OK" + id: + type: string + is_remote: + type: boolean + description: Which storage to use local or remote + example: false + mute_new_metrics: + type: boolean + example: true + name: + type: string + description: Trigger name + example: Dice Roll + patterns: + items: + type: string + type: array + example: + - local.dice.roll + description: Array of possible patterns to check values in simple mode + sched: + $schema: "http://json-schema.org/draft-04/schema#" + $ref: "#/definitions/ScheduleData" + tags: + items: + type: string + type: array + description: Array of tags associated with this trigger + example: + - test + targets: + items: + type: string + type: array + description: Array of targets associated with this trigger + throttling: + type: integer + description: Quantity of events before throttling will be enabled + trigger_type: + type: string + enum: ["rising", "falling", "expression"] + ttl: + type: integer + ttl_state: + type: string + warn_value: + type: number + description: Target value at which warning will be fired + example: 5 +additionalProperties: false +type: object +definitions: + ScheduleData: + properties: + days: + items: + $schema: "http://json-schema.org/draft-04/schema#" + $ref: "#/definitions/ScheduleDataDay" + type: array + endOffset: + type: integer + startOffset: + type: integer + tzOffset: + type: integer + additionalProperties: false + type: object + ScheduleDataDay: + properties: + enabled: + type: boolean + name: + type: string + additionalProperties: false + type: object diff --git a/api/triggers/schemas/res_put.yml b/api/triggers/schemas/res_put.yml new file mode 100644 index 0000000..09924e3 --- /dev/null +++ b/api/triggers/schemas/res_put.yml @@ -0,0 +1,18 @@ +200: + type: object + properties: + id: + type: string + example: trigger_id + message: + type: string + example: trigger created +400: + type: object + properties: + status: + type: string + example: Invalid request + error: + type: string + example: error_value is equal to warn_value, please set exactly one value