Wikibase
MediaWiki Wikibase extension
|
As of REL1_44, the Wikibase REST API is enabled when the Wikibase repo extension is loaded
To enable the production-ready routes, in versions prior to REL1_44, add the following line to your LocalSettings.php
file:
To enable routes in development (not recommended for production use), also add:
Our REST API specification is provided using an OpenAPI specification in the specs
directory. The latest version is published on doc.wikimedia.org.
The specification can be "built" (i.e., compiled into a single JSON OpenAPI specs file) and validated using the provided npm scripts.
To modify API specs, install npm dependencies first, using a command like the following:
API specs can be validated using the npm test
script, using a command like the following:
API specs can be bundled into a single file using the npm build:spec
script, using a command like the following:
Autodocs can be generated from the API specification using the npm build:docs
script, using a command like the following:
The base URL of the API can be configured by passing an API_URL
environment variable:
The autodocs and the bundled OpenAPI specification files are generated in the ../../docs/rest-api/
directory.
MAJOR.MINOR
versions, omitting .PATCH
, will be created as we see little use for patch versions./info/version
field of the OpenAPI schema.This REST API follows the Hexagonal Architecture approach and takes inspiration from an article about Netflix's use of the hexagonal architecture. This decision is documented in ADR 0001.
The code is divided into three layers: Domain, Application, and Infrastructure. Domain and Application define the core business and application logic of the software, whereas the infrastructure layer deals with any external dependencies and concepts, such as transport or persistence details.
docs/
../../docs/rest-api/
: the built OpenAPI specification and swagger documentationspecs/
: OpenAPI specification sourcesrc/
Domain/
Model/
: Entities and value objects used when persisting dataReadModel/
: Entities and value objects used when retrieving dataServices/
: Secondary ports, i.e. persistence interfaces such as retrievers and updatersApplication/
Serialization/
: Deserializers used for turning user input into write models, serializers used for turning read models into JSON-serializable objectsValidation/
: Generic (not use cases specific) classes for validating user inputUseCases/
: Primary ports of the application coreInfrastructure/
: Secondary adapters, i.e. implementations of interfaces defined in the application coreDataAccess/
: Implementations of persistence servicesRouteHandlers/
: Web controllers acting as primary adapterstests/
mocha/
: tests using the mocha frameworkapi-testing/
: end-to-end tests using MediaWiki's api-testing libraryopenapi-validation/
: tests against the OpenAPI specphpunit/
: integration and unit tests using the phpunit frameworkDescriptions of the different kinds of tests can be found in the respective section of the directory structure overview above.
These tests can be run with the command npm run api-testing
.
The following needs to be correctly set up in order for all the tests to pass:
.api-testing.config
file in repo/rest-api
(next to this README.md file) - see the MediaWiki API integration tests docsX-Config-Override
hack from Wikibase.ci.php to your LocalSettings.php
. Do NOT do this on any sort of production wiki.