Skip to content

Commit 91e0b17

Browse files
add missing /collections/{collectionId}/items POST api
* openapi.go: add paramFeatureID
1 parent 3915996 commit 91e0b17

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

internal/api/openapi.go

+41-10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ func GetOpenAPIContent(urlBase string) *openapi3.Swagger {
5353
AllowEmptyValue: false,
5454
},
5555
}
56+
paramFeatureID := openapi3.ParameterRef{
57+
Value: &openapi3.Parameter{
58+
Name: "featureId",
59+
Description: "Id of feature in collection to retrieve data for.",
60+
In: "path",
61+
Required: true,
62+
Schema: &openapi3.SchemaRef{Value: openapi3.NewStringSchema()},
63+
AllowEmptyValue: false,
64+
},
65+
}
5666
paramBbox := openapi3.ParameterRef{
5767
Value: &openapi3.Parameter{
5868
Name: "bbox",
@@ -365,6 +375,36 @@ func GetOpenAPIContent(urlBase string) *openapi3.Swagger {
365375
},
366376
},
367377
},
378+
Post: &openapi3.Operation{
379+
OperationID: "createCollectionFeature",
380+
Parameters: openapi3.Parameters{
381+
&paramCollectionID,
382+
&paramFeatureID,
383+
// TODO keep it for the next evolution
384+
// &paramCrs,
385+
},
386+
RequestBody: &openapi3.RequestBodyRef{
387+
Value: &openapi3.RequestBody{
388+
Description: "Add a new feature",
389+
Required: true,
390+
Content: openapi3.NewContentWithJSONSchema(&FeatureSchema),
391+
},
392+
},
393+
Responses: openapi3.Responses{
394+
"201": &openapi3.ResponseRef{
395+
Value: &openapi3.Response{
396+
Description: "Empty body with location header",
397+
Headers: map[string]*openapi3.HeaderRef{
398+
"location": {
399+
Value: &openapi3.Header{
400+
Description: "Contains a link to access to the new feature data",
401+
},
402+
},
403+
},
404+
},
405+
},
406+
},
407+
},
368408
},
369409
apiBase + "collections/{collectionId}/schema": &openapi3.PathItem{
370410
Summary: "Feature schema for collection",
@@ -399,16 +439,7 @@ func GetOpenAPIContent(urlBase string) *openapi3.Swagger {
399439
OperationID: "getCollectionFeature",
400440
Parameters: openapi3.Parameters{
401441
&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-
},
442+
&paramFeatureID,
412443
&paramProperties,
413444
&paramTransform,
414445
&paramCrs,

internal/service/handler_post_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,23 @@ func TestApiContainsCollectionSchemas(t *testing.T) {
4242
util.Assert(t, path != nil, "schema path exists")
4343
util.Equals(t, "Provides access to data representation (schema) for any features in specified collection", path.Description, "schema path present")
4444
util.Equals(t, "getCollectionSchema", path.Get.OperationID, "schema path get present")
45-
util.Equals(t, 2, len(path.Get.Parameters), "schema path get present")
45+
util.Equals(t, 2, len(path.Get.Parameters), "# path")
4646
util.Assert(t, path.Get.Parameters.GetByInAndName("path", "collectionId") != nil, "collectionId path parameter exists")
4747
util.Assert(t, path.Get.Parameters.GetByInAndName("query", "type") != nil, "type query parameter exists")
4848
}
4949

50+
// checks swagger api contains method PATCH for updating a feaure from a specified collection
51+
func TestApiContainsMethodPostFeature(t *testing.T) {
52+
resp := hTest.DoRequest(t, "/api")
53+
body, _ := ioutil.ReadAll(resp.Body)
54+
55+
var v openapi3.Swagger
56+
err := json.Unmarshal(body, &v)
57+
util.Assert(t, err == nil, fmt.Sprintf("%v", err))
58+
59+
util.Equals(t, "createCollectionFeature", v.Paths.Find("/collections/{collectionId}/items").Post.OperationID, "method POST present")
60+
}
61+
5062
// checks collection schema contains valid data description
5163
func TestGetCollectionCreateSchema(t *testing.T) {
5264
path := "/collections/mock_a/schema?type=create"

0 commit comments

Comments
 (0)