@@ -14,13 +14,76 @@ package api
14
14
*/
15
15
16
16
import (
17
+ "encoding/json"
17
18
"net/url"
18
19
19
20
"github.com/CrunchyData/pg_featureserv/internal/conf"
20
21
"github.com/getkin/kin-openapi/openapi3"
21
22
log "github.com/sirupsen/logrus"
22
23
)
23
24
25
+ func getFeatureExample () map [string ]interface {} {
26
+ var result map [string ]interface {}
27
+ var jsonStr = `{"type":"Feature","geometry":{"type":"Point","coordinates":[-70.88461956597838,47.807897059236495]},"properties":{"prop_a":"propA","prop_b":1,"prop_c":"propC","prop_d":1}}`
28
+ err := json .Unmarshal ([]byte (jsonStr ), & result )
29
+ if err != nil {
30
+ return nil
31
+ }
32
+ return result
33
+ }
34
+
35
+ var FeatureSchema openapi3.Schema = openapi3.Schema {
36
+ Type : "object" ,
37
+ Required : []string {},
38
+ Properties : map [string ]* openapi3.SchemaRef {
39
+ "id" : {
40
+ Value : & openapi3.Schema {
41
+ OneOf : []* openapi3.SchemaRef {
42
+ openapi3 .NewSchemaRef ("" , & openapi3.Schema {
43
+ Type : "number" , Format : "long" ,
44
+ }),
45
+ openapi3 .NewSchemaRef ("" , & openapi3.Schema {
46
+ Type : "string" ,
47
+ }),
48
+ },
49
+ },
50
+ },
51
+ "type" : {
52
+ Value : & openapi3.Schema {
53
+ Type : "string" ,
54
+ Default : "Feature" ,
55
+ },
56
+ },
57
+ "geometry" : {
58
+ Value : & openapi3.Schema {
59
+ Type : "string" , // mandatory to validate the schema
60
+ OneOf : []* openapi3.SchemaRef {
61
+ openapi3 .NewSchemaRef ("https://geojson.org/schema/Point.json" , & openapi3.Schema {Type : "string" }),
62
+ openapi3 .NewSchemaRef ("https://geojson.org/schema/LineString.json" , & openapi3.Schema {Type : "string" }),
63
+ openapi3 .NewSchemaRef ("https://geojson.org/schema/Polygon.json" , & openapi3.Schema {Type : "string" }),
64
+ openapi3 .NewSchemaRef ("https://geojson.org/schema/MultiPoint.json" , & openapi3.Schema {Type : "string" }),
65
+ openapi3 .NewSchemaRef ("https://geojson.org/schema/MultiLineString.json" , & openapi3.Schema {Type : "string" }),
66
+ openapi3 .NewSchemaRef ("https://geojson.org/schema/MultiPolygon.json" , & openapi3.Schema {Type : "string" }),
67
+ },
68
+ },
69
+ },
70
+ "properties" : {
71
+ Value : & openapi3.Schema {
72
+ Type : "object" ,
73
+ },
74
+ },
75
+ "bbox" : {
76
+ Value : & openapi3.Schema {
77
+ Type : "array" ,
78
+ MinItems : 4 ,
79
+ MaxItems : openapi3 .Uint64Ptr (4 ),
80
+ Items : openapi3 .NewSchemaRef ("" , openapi3 .NewFloat64Schema ().WithMin (- 180 ).WithMax (180 )),
81
+ },
82
+ },
83
+ },
84
+ Example : getFeatureExample (),
85
+ }
86
+
24
87
// GetOpenAPIContent returns a Swagger OpenAPI structure
25
88
func GetOpenAPIContent (urlBase string ) * openapi3.Swagger {
26
89
@@ -53,6 +116,16 @@ func GetOpenAPIContent(urlBase string) *openapi3.Swagger {
53
116
AllowEmptyValue : false ,
54
117
},
55
118
}
119
+ paramFeatureID := openapi3.ParameterRef {
120
+ Value : & openapi3.Parameter {
121
+ Name : "featureId" ,
122
+ Description : "Id of feature in collection to retrieve data for." ,
123
+ In : "path" ,
124
+ Required : true ,
125
+ Schema : & openapi3.SchemaRef {Value : openapi3 .NewStringSchema ()},
126
+ AllowEmptyValue : false ,
127
+ },
128
+ }
56
129
paramBbox := openapi3.ParameterRef {
57
130
Value : & openapi3.Parameter {
58
131
Name : "bbox" ,
@@ -365,6 +438,36 @@ func GetOpenAPIContent(urlBase string) *openapi3.Swagger {
365
438
},
366
439
},
367
440
},
441
+ Post : & openapi3.Operation {
442
+ OperationID : "createCollectionFeature" ,
443
+ Parameters : openapi3.Parameters {
444
+ & paramCollectionID ,
445
+ & paramFeatureID ,
446
+ // TODO keep it for the next evolution
447
+ // ¶mCrs,
448
+ },
449
+ RequestBody : & openapi3.RequestBodyRef {
450
+ Value : & openapi3.RequestBody {
451
+ Description : "Add a new feature" ,
452
+ Required : true ,
453
+ Content : openapi3 .NewContentWithJSONSchema (& FeatureSchema ),
454
+ },
455
+ },
456
+ Responses : openapi3.Responses {
457
+ "201" : & openapi3.ResponseRef {
458
+ Value : & openapi3.Response {
459
+ Description : "Empty body with location header" ,
460
+ Headers : map [string ]* openapi3.HeaderRef {
461
+ "location" : {
462
+ Value : & openapi3.Header {
463
+ Description : "Contains a link to access to the new feature data" ,
464
+ },
465
+ },
466
+ },
467
+ },
468
+ },
469
+ },
470
+ },
368
471
},
369
472
apiBase + "collections/{collectionId}/schema" : & openapi3.PathItem {
370
473
Summary : "Feature schema for collection" ,
@@ -399,16 +502,7 @@ func GetOpenAPIContent(urlBase string) *openapi3.Swagger {
399
502
OperationID : "getCollectionFeature" ,
400
503
Parameters : openapi3.Parameters {
401
504
& paramCollectionID ,
402
- & openapi3.ParameterRef {
403
- Value : & openapi3.Parameter {
404
- Name : "featureId" ,
405
- Description : "Id of feature in collection to retrieve data for." ,
406
- In : "path" ,
407
- Required : true ,
408
- Schema : & openapi3.SchemaRef {Value : openapi3 .NewStringSchema ()},
409
- AllowEmptyValue : false ,
410
- },
411
- },
505
+ & paramFeatureID ,
412
506
& paramProperties ,
413
507
& paramTransform ,
414
508
& paramCrs ,
0 commit comments