浏览代码

Added Header 'application/geo+json' for all endpoints with param 'format=geojson', edited OpenAPI schema of all endpoints acording to the GeoJSON standard

Lukas Cerny 1 年之前
父节点
当前提交
6d6089ef55
共有 2 个文件被更改,包括 121 次插入34 次删除
  1. 15 16
      src/main/java/cz/senslog/telemetry/server/ws/OpenAPIHandler.java
  2. 106 18
      src/main/resources/openAPISpec.yaml

+ 15 - 16
src/main/java/cz/senslog/telemetry/server/ws/OpenAPIHandler.java

@@ -258,7 +258,7 @@ public class OpenAPIHandler {
                                                     "unitId", o.getUnitId(),
                                                     "unitId", o.getUnitId(),
                                                     "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                     "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                     "speed", o.getSpeed(),
                                                     "speed", o.getSpeed(),
-                                                    "observations", o.getObservedValues()
+                                                    "observedValues", o.getObservedValues()
                                             )
                                             )
                                     )).collect(toList()))).encode()))
                                     )).collect(toList()))).encode()))
                     .onFailure(rc::fail);
                     .onFailure(rc::fail);
@@ -379,7 +379,7 @@ public class OpenAPIHandler {
                                                             "unitId", o.getUnitId(),
                                                             "unitId", o.getUnitId(),
                                                             "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                             "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                             "speed", o.getSpeed(),
                                                             "speed", o.getSpeed(),
-                                                            "observations", o.getObservedValues()
+                                                            "observedValues", o.getObservedValues()
                                                     )
                                                     )
                                             )).collect(toList()))).encode()))
                                             )).collect(toList()))).encode()))
                             .onFailure(rc::fail);
                             .onFailure(rc::fail);
@@ -466,11 +466,10 @@ public class OpenAPIHandler {
                             ),
                             ),
                             "features", unitLocation.entrySet().stream().map(entry -> JsonObject.of(
                             "features", unitLocation.entrySet().stream().map(entry -> JsonObject.of(
                                     "type", "Feature",
                                     "type", "Feature",
+                                    "properties", JsonObject.of(
+                                            "unitId", entry.getKey()),
                                     "geometry", JsonObject.of(
                                     "geometry", JsonObject.of(
                                             "type", "MultiPoint",
                                             "type", "MultiPoint",
-                                            "properties", JsonObject.of(
-                                                    "unitId", entry.getKey()
-                                            ),
                                             "coordinates", new JsonArray(entry.getValue().stream().map(l -> JsonArray.of(
                                             "coordinates", new JsonArray(entry.getValue().stream().map(l -> JsonArray.of(
                                                     l.getLocation().getLongitude(),
                                                     l.getLocation().getLongitude(),
                                                     l.getLocation().getLatitude(),
                                                     l.getLocation().getLatitude(),
@@ -959,7 +958,7 @@ public class OpenAPIHandler {
                             "hasNext", paging.hasNext(),
                             "hasNext", paging.hasNext(),
                             "data", new JsonArray(
                             "data", new JsonArray(
                                     paging.data().stream().map(l -> JsonObject.of(
                                     paging.data().stream().map(l -> JsonObject.of(
-                                            "observed_value", l.getValue(),
+                                            "observedValue", l.getValue(),
                                             "timestamp", OffsetDateTime.ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                             "timestamp", OffsetDateTime.ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                             "speed", l.getSpeed(),
                                             "speed", l.getSpeed(),
                                             "location", JsonObject.of(
                                             "location", JsonObject.of(
@@ -991,7 +990,7 @@ public class OpenAPIHandler {
                                                     "unitId", unitId,
                                                     "unitId", unitId,
                                                     "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                     "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                     "speed", o.getSpeed(),
                                                     "speed", o.getSpeed(),
-                                                    "observations", JsonObject.of(
+                                                    "observedValues", JsonObject.of(
                                                             String.valueOf(sensorId), o.getValue()
                                                             String.valueOf(sensorId), o.getValue()
                                                     )
                                                     )
                                             )
                                             )
@@ -1387,7 +1386,7 @@ public class OpenAPIHandler {
                                                     "unitId", o.getUnitId(),
                                                     "unitId", o.getUnitId(),
                                                     "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                     "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
                                                     "speed", o.getSpeed(),
                                                     "speed", o.getSpeed(),
-                                                    "observations", o.getObservedValues()
+                                                    "observedValues", o.getObservedValues()
                                             )
                                             )
                                     )).collect(toList()))).encode()))
                                     )).collect(toList()))).encode()))
                     .onFailure(rc::fail);
                     .onFailure(rc::fail);
@@ -1551,16 +1550,16 @@ public class OpenAPIHandler {
 
 
             case GEOJSON -> Optional.of(rc.body().asJsonObject()).map(j -> j.getJsonArray("features"))
             case GEOJSON -> Optional.of(rc.body().asJsonObject()).map(j -> j.getJsonArray("features"))
                     .map(jsonArray -> jsonArray.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast)
                     .map(jsonArray -> jsonArray.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast)
-                            .map(f -> UnitTelemetry.of(
-                                    f.getJsonObject("properties").getLong("unitId"),
-                                    OffsetDateTime.parse(f.getJsonObject("properties").getString("timestamp")),
+                            .map(feature -> UnitTelemetry.of(
+                                    feature.getJsonObject("properties").getLong("unitId"),
+                                    OffsetDateTime.parse(feature.getJsonObject("properties").getString("timestamp")),
                                     Location.of(
                                     Location.of(
-                                            f.getJsonObject("geometry").getJsonArray("coordinates").getFloat(0),
-                                            f.getJsonObject("geometry").getJsonArray("coordinates").getFloat(1),
-                                            f.getJsonObject("geometry").getJsonArray("coordinates").getFloat(2)
+                                            feature.getJsonObject("geometry").getJsonArray("coordinates").getFloat(0),
+                                            feature.getJsonObject("geometry").getJsonArray("coordinates").getFloat(1),
+                                            feature.getJsonObject("geometry").getJsonArray("coordinates").getFloat(2)
                                     ),
                                     ),
-                                    f.getJsonObject("properties").getInteger("speed"),
-                                    f.getJsonObject("observations")
+                                    feature.getJsonObject("properties").getInteger("speed"),
+                                    feature.getJsonObject("observedValues")
                             )).sorted(comparing(UnitTelemetry::getTimestamp)).collect(toList()))
                             )).sorted(comparing(UnitTelemetry::getTimestamp)).collect(toList()))
                     .ifPresent(orgTels -> repo.findCampaignById(campaignId)
                     .ifPresent(orgTels -> repo.findCampaignById(campaignId)
                             .onSuccess(campaign -> fluentlyOf(telemetriesWithinCampaign(campaign, orgTels))
                             .onSuccess(campaign -> fluentlyOf(telemetriesWithinCampaign(campaign, orgTels))

+ 106 - 18
src/main/resources/openAPISpec.yaml

@@ -116,7 +116,7 @@ paths:
                 $ref: '#/components/schemas/CampaignObservation'
                 $ref: '#/components/schemas/CampaignObservation'
             application/geo+json:
             application/geo+json:
               schema:
               schema:
-                $ref: '#/components/schemas/GeoCampaignObservation'
+                $ref: '#/components/schemas/GeoFeatureCollectionUnit'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -137,21 +137,14 @@ paths:
                 $ref: '#/components/schemas/CampaignDataObservation'
                 $ref: '#/components/schemas/CampaignDataObservation'
           application/geo+json:
           application/geo+json:
             schema:
             schema:
-              $ref: '#/components/schemas/GeoCampaignObservation'
+              $ref: '#/components/schemas/GeoFeatureCollectionUnit'
       responses:
       responses:
         200:
         200:
           description: JSON
           description: JSON
           content:
           content:
             application/json:
             application/json:
               schema:
               schema:
-                type: object
-                properties:
-                  saved:
-                    type: integer
-                    minimum: 0
-                  errors:
-                    type: integer
-                    minimum: 0
+                $ref: '#/components/schemas/PostResponse'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -180,6 +173,9 @@ paths:
             application/json:
             application/json:
               schema:
               schema:
                 $ref: '#/components/schemas/CampaignUnitsLocations'
                 $ref: '#/components/schemas/CampaignUnitsLocations'
+            application/geo+json:
+              schema:
+                $ref: '#/components/schemas/GeoCampaignUnitsLocations'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -232,6 +228,9 @@ paths:
             application/json:
             application/json:
               schema:
               schema:
                 $ref: '#/components/schemas/CampaignUnitObservation'
                 $ref: '#/components/schemas/CampaignUnitObservation'
+            application/geo+json:
+              schema:
+                $ref: '#/components/schemas/GeoFeatureCollectionUnit'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -261,6 +260,9 @@ paths:
             application/json:
             application/json:
               schema:
               schema:
                 $ref: '#/components/schemas/CampaignUnitLocation'
                 $ref: '#/components/schemas/CampaignUnitLocation'
+            application/geo+json:
+              schema:
+                $ref: '#/components/schemas/GeoFeatureUnitMultiLocation'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -295,7 +297,7 @@ paths:
   /campaigns/{campaignId}/units/{unitId}/sensors/{sensorId}:
   /campaigns/{campaignId}/units/{unitId}/sensors/{sensorId}:
     get:
     get:
       operationId: campaignIdUnitIdSensorIdGET
       operationId: campaignIdUnitIdSensorIdGET
-      summary: Publish info about all sensors asociated with the unit and the campaign
+      summary: Publish info about all sensors associated with the unit and the campaign
       parameters:
       parameters:
         - $ref: '#/components/parameters/campaignIdParam'
         - $ref: '#/components/parameters/campaignIdParam'
         - $ref: '#/components/parameters/unitIdParam'
         - $ref: '#/components/parameters/unitIdParam'
@@ -338,6 +340,9 @@ paths:
             application/json:
             application/json:
               schema:
               schema:
                 $ref: '#/components/schemas/CampaignUnitSensorObservation'
                 $ref: '#/components/schemas/CampaignUnitSensorObservation'
+            application/geo+json:
+              schema:
+                $ref: '#/components/schemas/GeoFeatureCollectionUnit'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -890,6 +895,9 @@ paths:
             application/json:
             application/json:
               schema:
               schema:
                 $ref: '#/components/schemas/ActionEventObservation'
                 $ref: '#/components/schemas/ActionEventObservation'
+            application/geo+json:
+              schema:
+                $ref: '#/components/schemas/GeoFeatureCollectionUnit'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -918,6 +926,9 @@ paths:
             application/json:
             application/json:
               schema:
               schema:
                 $ref: '#/components/schemas/ActionEventLocation'
                 $ref: '#/components/schemas/ActionEventLocation'
+            application/geo+json:
+              schema:
+                $ref: '#/components/schemas/GeoFeatureUnitMultiLocation'
         default:
         default:
           description: unexpected error
           description: unexpected error
           content:
           content:
@@ -1455,7 +1466,7 @@ components:
         offset: 0
         offset: 0
         data: []
         data: []
 
 
-    GeoCampaignObservation:
+    GeoFeatureCollectionUnit:
       type: object
       type: object
       required:
       required:
         - type
         - type
@@ -1471,9 +1482,9 @@ components:
           type: array
           type: array
           minLength: 1
           minLength: 1
           items:
           items:
-            $ref: '#/components/schemas/GeoFeatureCampaign'
+            $ref: '#/components/schemas/GeoFeatureUnitObservation'
 
 
-    GeoFeatureCampaign:
+    GeoFeatureUnitObservation:
       type: object
       type: object
       required:
       required:
         - type
         - type
@@ -1502,11 +1513,14 @@ components:
             speed:
             speed:
               type: integer
               type: integer
               format: int64
               format: int64
-            observations:
+            observedValues:
               type: object
               type: object
 
 
     GeoPoint:
     GeoPoint:
       type: object
       type: object
+      required:
+        - type
+        - coordinates
       properties:
       properties:
         type:
         type:
           type: string
           type: string
@@ -1729,7 +1743,7 @@ components:
         timestamp:
         timestamp:
           type: string
           type: string
           format: date-time
           format: date-time
-        observed_value:
+        observedValue:
           type: integer
           type: integer
           format: int64
           format: int64
         speed:
         speed:
@@ -1739,7 +1753,7 @@ components:
           $ref: '#/components/schemas/Location'
           $ref: '#/components/schemas/Location'
       example:
       example:
         timestamp: "2023-01-25 15:35:32Z"
         timestamp: "2023-01-25 15:35:32Z"
-        observed_value: 1434
+        observedValue: 1434
         speed: 34
         speed: 34
         location:
         location:
           longitude: 49.7384
           longitude: 49.7384
@@ -1866,6 +1880,69 @@ components:
               latitude: 13.3736
               latitude: 13.3736
               altitude: 350.3
               altitude: 350.3
 
 
+    GeoCampaignUnitsLocations:
+      type: object
+      required:
+        - type
+        - features
+      properties:
+        type:
+          type: string
+          enum:
+            - FeatureCollection
+        metadata:
+          type: object
+        features:
+          type: array
+          minLength: 1
+          items:
+            $ref: '#/components/schemas/GeoFeatureUnitMultiLocation'
+
+    GeoFeatureUnitMultiLocation:
+      type: object
+      required:
+        - type
+        - properties
+        - geometry
+      properties:
+        type:
+          type: string
+          enum:
+            - Feature
+        properties:
+          type: object
+          required:
+            - unitId
+          properties:
+            unitId:
+              type: integer
+              format: int64
+        geometry:
+          $ref: '#/components/schemas/GeoMultiPoint'
+
+    GeoMultiPoint:
+      type: object
+      required:
+        - type
+        - coordinates
+      properties:
+        type:
+          type: string
+          enum:
+            - MultiPoint
+        coordinates:
+          type: array
+          minLength: 1
+          items:
+            type: array
+            items:
+              type: integer
+              format: float
+              minLength: 3
+              maxLength: 3
+              description: "[lon, lat, alt]"
+
+
     ActionEventLocation:
     ActionEventLocation:
       type: object
       type: object
       required:
       required:
@@ -2802,7 +2879,18 @@ components:
         fromTime: "2023-01-25 15:35:32Z"
         fromTime: "2023-01-25 15:35:32Z"
         toTime: "2023-03-20 10:35:32Z"
         toTime: "2023-03-20 10:35:32Z"
 
 
-
+    PostResponse:
+      type: object
+      required:
+        - saved
+        - errors
+      properties:
+        saved:
+          type: integer
+          minimum: 0
+        errors:
+          type: integer
+          minimum: 0
 
 
     Info:
     Info:
       required:
       required: