Add swagger docs for POST /api/v1/points

This commit is contained in:
Eugene Burmakin
2025-01-20 20:17:27 +01:00
parent 983768a572
commit 112f13587c
5 changed files with 170 additions and 2 deletions

View File

@@ -1 +1 @@
0.22.4
0.22.5

View File

@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.22.5 - 2025-01-20
### Added
- `POST /api/v1/points/create` endpoint added to create points from a file.
# 0.22.4 - 2025-01-20
### Added

View File

@@ -67,7 +67,7 @@ Rails.application.routes.draw do
get 'settings', to: 'settings#index'
resources :areas, only: %i[index create update destroy]
resources :points, only: %i[index destroy update]
resources :points, only: %i[index create update destroy]
resources :visits, only: %i[update]
resources :stats, only: :index

View File

@@ -67,6 +67,87 @@ describe 'Points API', type: :request do
run_test!
end
end
post 'Creates a batch of points' do
request_body_example value: {
locations: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.40530871, 37.74430413]
},
properties: {
timestamp: '2025-01-17T21:03:01Z',
horizontal_accuracy: 5,
vertical_accuracy: -1,
altitude: 0,
speed: 92.088,
speed_accuracy: 0,
course: 27.07,
course_accuracy: 0,
track_id: '799F32F5-89BB-45FB-A639-098B1B95B09F',
device_id: '8D5D4197-245B-4619-A88B-2049100ADE46'
}
}
]
}
tags 'Batches'
consumes 'application/json'
parameter name: :locations, in: :body, schema: {
type: :object,
properties: {
type: { type: :string },
geometry: {
type: :object,
properties: {
type: { type: :string },
coordinates: { type: :array, items: { type: :number } }
}
},
properties: {
type: :object,
properties: {
timestamp: { type: :string },
horizontal_accuracy: { type: :number },
vertical_accuracy: { type: :number },
altitude: { type: :number },
speed: { type: :number },
speed_accuracy: { type: :number },
course: { type: :number },
course_accuracy: { type: :number },
track_id: { type: :string },
device_id: { type: :string }
}
}
},
required: %w[geometry properties]
}
parameter name: :api_key, in: :query, type: :string, required: true, description: 'API Key'
response '200', 'Batch of points being processed' do
let(:file_path) { 'spec/fixtures/files/points/geojson_example.json' }
let(:file) { File.open(file_path) }
let(:json) { JSON.parse(file.read) }
let(:params) { json }
let(:locations) { params['locations'] }
let(:api_key) { create(:user).api_key }
run_test!
end
response '401', 'Unauthorized' do
let(:file_path) { 'spec/fixtures/files/points/geojson_example.json' }
let(:file) { File.open(file_path) }
let(:json) { JSON.parse(file.read) }
let(:params) { json }
let(:locations) { params['locations'] }
let(:api_key) { 'invalid_api_key' }
run_test!
end
end
end
path '/api/v1/points/{id}' do

View File

@@ -696,6 +696,87 @@ paths:
type: string
visit_id:
type: string
post:
summary: Creates a batch of points
tags:
- Batches
parameters:
- name: api_key
in: query
required: true
description: API Key
schema:
type: string
responses:
'200':
description: Batch of points being processed
'401':
description: Unauthorized
requestBody:
content:
application/json:
schema:
type: object
properties:
type:
type: string
geometry:
type: object
properties:
type:
type: string
coordinates:
type: array
items:
type: number
properties:
type: object
properties:
timestamp:
type: string
horizontal_accuracy:
type: number
vertical_accuracy:
type: number
altitude:
type: number
speed:
type: number
speed_accuracy:
type: number
course:
type: number
course_accuracy:
type: number
track_id:
type: string
device_id:
type: string
required:
- geometry
- properties
examples:
'0':
summary: Creates a batch of points
value:
locations:
- type: Feature
geometry:
type: Point
coordinates:
- -122.40530871
- 37.74430413
properties:
timestamp: '2025-01-17T21:03:01Z'
horizontal_accuracy: 5
vertical_accuracy: -1
altitude: 0
speed: 92.088
speed_accuracy: 0
course: 27.07
course_accuracy: 0
track_id: 799F32F5-89BB-45FB-A639-098B1B95B09F
device_id: 8D5D4197-245B-4619-A88B-2049100ADE46
"/api/v1/points/{id}":
delete:
summary: Deletes a point