diff --git a/controller/RestController.php b/controller/RestController.php index 8e65880b8..c62eb4216 100644 --- a/controller/RestController.php +++ b/controller/RestController.php @@ -709,7 +709,15 @@ public function label($request) return null; } - $labelResults = $request->getVocab()->getAllConceptLabels($request->getUri(), $request->getLang()); + $vocab = $request->getVocab(); + if ($vocab === null) { + $vocab = $this->model->guessVocabularyFromUri($request->getUri()); + } + if ($vocab === null) { + return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>"); + } + + $labelResults = $vocab->getAllConceptLabels($request->getUri(), $request->getLang()); if ($labelResults === null) { return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>"); } diff --git a/rest.php b/rest.php index b335d5bb5..5d276f105 100644 --- a/rest.php +++ b/rest.php @@ -32,6 +32,8 @@ $controller->vocabularies($request); } elseif ($parts[1] == 'search') { $controller->search($request); + } elseif ($parts[1] == 'label') { + $controller->label($request); } elseif ($parts[1] == 'types') { $controller->types($request); } elseif ($parts[1] == 'data') { diff --git a/swagger.json b/swagger.json index 2e936e737..3d564bb1a 100644 --- a/swagger.json +++ b/swagger.json @@ -143,6 +143,47 @@ ] } }, + "/label": { + "get": { + "summary": "List of labels for the requested concept", + "parameters": [ + { + "name": "uri", + "in": "query", + "description": "URI of the concept whose labels to return", + "required": true, + "type": "string" + }, + { + "name": "lang", + "in": "query", + "description": "search language, e.g. \"en\" or \"fi\"", + "required": false, + "type": "string" + } + ], + "produces": [ + "application/ld+json" + ], + "responses": { + "200": { + "description": "labels for the requested concept", + "schema": { + "$ref": "#/definitions/LabelsAndUri" + } + }, + "304": { + "description": "the resource was not modified, so there is no need to retransmit the requested resources" + }, + "404": { + "description": "no concept could be found with the requested URI" + } + }, + "tags": [ + "Global methods" + ] + } + }, "/data": { "get": { "summary": "RDF data of the requested concept", @@ -717,7 +758,7 @@ { "name": "uri", "in": "query", - "description": "URI of the concept whose label to return", + "description": "URI of the concept whose labels to return", "required": true, "type": "string" }, @@ -734,7 +775,7 @@ ], "responses": { "200": { - "description": "preferred label for the requested concept", + "description": "labels for the requested concept", "schema": { "$ref": "#/definitions/LabelsAndUri" } @@ -2232,4 +2273,4 @@ ] } } -} +} \ No newline at end of file diff --git a/tests/RestControllerTest.php b/tests/RestControllerTest.php index 8c01c599d..e5180d00c 100644 --- a/tests/RestControllerTest.php +++ b/tests/RestControllerTest.php @@ -183,6 +183,54 @@ public function testLabelOnePrefOneAltLabel() { $this->assertJsonStringEqualsJsonString($expected, $out); } + /** + * @covers RestController::label + */ + public function testLabelGlobal() { + $request = new Request($this->model); + $request->setQueryParam('format', 'application/json'); + $request->setURI('http://www.skosmos.skos/test/ta112'); + $request->setLang('en'); + + $this->controller->label($request); + $out = $this->getActualOutput(); + + $expected = <<assertJsonStringEqualsJsonString($expected, $out); + } + + /** + * @covers RestController::label + */ + public function testLabelGlobalNonexistentVocab() { + $request = new Request($this->model); + $request->setQueryParam('format', 'application/json'); + $request->setURI('http://www.skosmos.skos/nonexistent/vocab'); + $request->setLang('en'); + + $this->controller->label($request); + $out = $this->getActualOutput(); + + $expected = "404 Not Found : Could not find concept "; + $this->assertEquals($expected, $out); + } + /** * @covers RestController::label */