Rejecting EI types with no schema 56/5456/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 18 Jan 2021 11:34:38 +0000 (12:34 +0100)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 18 Jan 2021 11:35:17 +0000 (12:35 +0100)
Change-Id: I316cb5c2a0b7a1e38d7aa602b289afe588728ded
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-378

enrichment-coordinator-service/api/ecs-api.json
enrichment-coordinator-service/api/ecs-api.yaml
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java
enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java

index f1517df..d55dc18 100644 (file)
                 "produces": ["application/json"],
                 "operationId": "putEiTypeUsingPUT",
                 "responses": {
-                    "200": {
-                        "schema": {"type": "object"},
-                        "description": "OK"
-                    },
+                    "200": {"description": "OK"},
                     "201": {"description": "Created"},
+                    "400": {
+                        "schema": {"$ref": "#/definitions/ProblemDetails"},
+                        "description": "Bad request"
+                    },
                     "401": {"description": "Unauthorized"},
                     "403": {"description": "Forbidden"},
                     "404": {"description": "Not Found"}
             "description": "Information for an EI type",
             "type": "object",
             "title": "producer_ei_type_info",
+            "required": ["ei_job_data_schema"],
             "properties": {"ei_job_data_schema": {
                 "description": "Json schema for the job data",
                 "type": "object"
index 7b3d011..d7d5eb3 100644 (file)
@@ -314,13 +314,16 @@ paths:
       responses:
         200:
           description: OK
-          content:
-            application/json:
-              schema:
-                type: object
+          content: {}
         201:
           description: Created
           content: {}
+        400:
+          description: Bad request
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ProblemDetails'
         401:
           description: Unauthorized
           content: {}
@@ -787,6 +790,8 @@ components:
       type: object
     producer_ei_type_info:
       title: producer_ei_type_info
+      required:
+      - ei_job_data_schema
       type: object
       properties:
         ei_job_data_schema:
index 349e5d5..4b7063c 100644 (file)
@@ -112,11 +112,20 @@ public class ProducerController {
     }
 
     @PutMapping(path = ProducerConsts.API_ROOT + "/eitypes/{eiTypeId}", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ApiResponses(
+        value = { //
+            @ApiResponse(code = 200, message = "OK", response = VoidResponse.class), @ApiResponse(
+                code = 400, //
+                message = "Bad request",
+                response = ErrorResponse.ErrorInfo.class)})
     @ApiOperation(value = "Individual EI type", notes = "")
     public ResponseEntity<Object> putEiType( //
         @PathVariable("eiTypeId") String eiTypeId, @RequestBody ProducerEiTypeInfo registrationInfo) {
 
         EiType previousDefinition = this.eiTypes.get(eiTypeId);
+        if (registrationInfo.jobDataSchema == null) {
+            return ErrorResponse.create("No schema provided", HttpStatus.BAD_REQUEST);
+        }
         this.eiTypes.put(new EiType(eiTypeId, registrationInfo.jobDataSchema));
         return new ResponseEntity<>(previousDefinition == null ? HttpStatus.CREATED : HttpStatus.OK);
     }
index 3522081..d2b89ef 100644 (file)
@@ -32,9 +32,9 @@ import org.immutables.gson.Gson;
 @ApiModel(value = "producer_ei_type_info", description = "Information for an EI type")
 public class ProducerEiTypeInfo {
 
-    @ApiModelProperty(value = "Json schema for the job data")
+    @ApiModelProperty(value = "Json schema for the job data", required = true)
     @SerializedName("ei_job_data_schema")
-    @JsonProperty("ei_job_data_schema")
+    @JsonProperty(value = "ei_job_data_schema", required = true)
     public Object jobDataSchema;
 
     public ProducerEiTypeInfo(Object jobDataSchema) {
index 3a52fbc..b2ec0b1 100644 (file)
@@ -197,6 +197,13 @@ class ApplicationTest {
         assertThat(putEiType(EI_TYPE_ID)).isEqualTo(HttpStatus.OK);
     }
 
+    @Test
+    void testPutEiType_noSchema() {
+        String url = ProducerConsts.API_ROOT + "/eitypes/" + EI_TYPE_ID;
+        String body = "{}";
+        testErrorCode(restClient().put(url, body), HttpStatus.BAD_REQUEST, "No schema provided");
+    }
+
     @Test
     void testGetEiType() throws Exception {
         putEiProducerWithOneType(EI_PRODUCER_ID, "test");
@@ -429,6 +436,13 @@ class ApplicationTest {
         assertThat(request.id).isEqualTo("jobId");
     }
 
+    @Test
+    void testPutEiProducer_noType() throws Exception {
+        String url = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId";
+        String body = gson.toJson(producerEiRegistratioInfo(EI_TYPE_ID));
+        testErrorCode(restClient().put(url, body), HttpStatus.NOT_FOUND, "EI type not found");
+    }
+
     @Test
     void testPutProducerAndEiJob() throws Exception {
         this.putEiType(EI_TYPE_ID);