From fed5fc967794cb3d9d9abf3d48283908eff36cc9 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Mon, 18 Jan 2021 12:34:38 +0100 Subject: [PATCH] Rejecting EI types with no schema Change-Id: I316cb5c2a0b7a1e38d7aa602b289afe588728ded Signed-off-by: PatrikBuhr Issue-ID: NONRTRIC-378 --- enrichment-coordinator-service/api/ecs-api.json | 10 ++++++---- enrichment-coordinator-service/api/ecs-api.yaml | 13 +++++++++---- .../controllers/producer/ProducerController.java | 9 +++++++++ .../controllers/producer/ProducerEiTypeInfo.java | 4 ++-- .../test/java/org/oransc/enrichment/ApplicationTest.java | 14 ++++++++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/enrichment-coordinator-service/api/ecs-api.json b/enrichment-coordinator-service/api/ecs-api.json index f1517df7..d55dc184 100644 --- a/enrichment-coordinator-service/api/ecs-api.json +++ b/enrichment-coordinator-service/api/ecs-api.json @@ -252,11 +252,12 @@ "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"} @@ -651,6 +652,7 @@ "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" diff --git a/enrichment-coordinator-service/api/ecs-api.yaml b/enrichment-coordinator-service/api/ecs-api.yaml index 7b3d011e..d7d5eb3a 100644 --- a/enrichment-coordinator-service/api/ecs-api.yaml +++ b/enrichment-coordinator-service/api/ecs-api.yaml @@ -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: diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java index 349e5d56..4b7063cd 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java @@ -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 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); } diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java index 35220810..d2b89ef3 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java @@ -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) { diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java index 3a52fbc2..b2ec0b14 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java @@ -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); -- 2.16.6