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

[WIP] feature: add History API #1653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
173 changes: 173 additions & 0 deletions src/api/history/openApi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"openapi": "3.0.0",
"info": {
"version": "0.0.1",
"title": "Signal K History API",
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"servers": [
{
"url": "/signalk/v2/api/history"
}
],
"components": {},
"security": [
{
"cookieAuth": []
},
{
"bearerAuth": []
}
],
"paths": {
"/values": {
"get": {
"summary": "Retrive historical data",
"description": "Returns historical data series for the paths and time range specified in query parameters",
"parameters": [
{
"in": "query",
"name": "from",
"description": "Start of the time range, inclusive",
"schema": {
"type": "string",
"format": "date-time"
},
"required": true
},
{
"in": "query",
"name": "to",
"description": "End of the time range, inclusive",
"schema": {
"type": "string",
"format": "date-time"
},
"required": true
},
{
"in": "query",
"name": "context",
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "interval",
"description": "Length of data sample time windows",
"schema": {
"type": "number",
"format": "integer"
}
},
{
"in": "query",
"name": "paths",
"description": "Comma separated ist of Signal K paths whose data should be retrieved, optional aggregation methods for each path as postfix separated by a colon. Aggregation methods: average(default), min, max, first",
"example": "navigation.speedOverGround,navigation.speedThroughWater:max",
"schema": {
"type": "string"
},
"required": true
},
{
"in": "query",
"name": "format",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Series data with header",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["context", "", "target"],
"properties": {
"context": {
"type": "string",
"description": "Signal K context that the data is about",
"example": "vessels.urn:mrn:imo:mmsi:123456789"
},
"range": {
"type": "object",
"properties": {
"from": {
"type": "string",
"format": "date-time",
"description": "Start of the time range, inclusive",
"example": "2018-03-20T09:12:28Z"
},
"to": {
"type": "string",
"format": "date-time",
"description": "End of the time range, inclusive",
"example": "2018-03-20T09:13:28Z"
}
}
},
"values": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Signal K path"
},
"method": {
"type": "string",
"description": "Aggregation method"
}
}
}
},
"data": {
"type": "array",
"items": {
"type": "array",
"items": {
"description": "Data for a point in time. The first array element is the timestamp in ISO 8601 format",
"oneOf": [
{
"type": "string"
},
{
"type": "number"
},
{
"type": "array",
"items": {
"type": "number"
}
}
]
}
},
"example": [
["2023-11-09T02:45:38.160Z", 13.2, null, [-120.5, 59.2]]
]
}
}
}
}
}
}
}
}
},
"/contexts": {
"get": {}
},
"/paths": {
"get": {}
}
}
}
15 changes: 15 additions & 0 deletions src/api/history/openApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { OpenApiDescription } from '../swagger'
import courseApiDoc from './openApi.json'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be historyApiDoc?


export const historyApiRecord = {
name: 'history',
path: '/signalk/v2/api/history',
apiDoc: courseApiDoc as unknown as OpenApiDescription
}

const yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)
courseApiDoc.paths['/values'].get.parameters[0].example =
yesterday.toISOString()
courseApiDoc.paths['/values'].get.parameters[1].example =
new Date().toISOString()
4 changes: 3 additions & 1 deletion src/api/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { resourcesApiRecord } from './resources/openApi'
import { securityApiRecord } from './security/openApi'
import { discoveryApiRecord } from './discovery/openApi'
import { appsApiRecord } from './apps/openApi'
import { historyApiRecord } from './history/openApi'
import { PluginId, PluginManager } from '../interfaces/plugins'
import { Brand } from '@signalk/server-api'

Expand All @@ -29,7 +30,8 @@ const apiDocs = [
securityApiRecord,
courseApiRecord,
notificationsApiRecord,
resourcesApiRecord
resourcesApiRecord,
historyApiRecord
].reduce<ApiRecords>((acc, apiRecord: OpenApiRecord) => {
acc[apiRecord.name] = apiRecord
return acc
Expand Down
Loading