Merge branch '178-api-documentation' into 'develop'

Resolve "Document important API features"

Closes #178

See merge request funkwhale/funkwhale!166
This commit is contained in:
Eliot Berriot 2018-04-26 16:29:44 +00:00
commit 99ff8169fc
13 changed files with 263 additions and 5 deletions

6
docs/api.rst Normal file
View file

@ -0,0 +1,6 @@
Funkwhale API
=============
Funkwhale API is still a work in progress and should not be considered as
stable. We offer an `interactive documentation using swagger </swagger/>`_
were you can browse available endpoints and try the API.

5
docs/build_docs.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash -eux
# Building sphinx and swagger docs
python -m sphinx . $BUILD_PATH
TARGET_PATH="$BUILD_PATH/swagger" ./build_swagger.sh

9
docs/build_swagger.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash -eux
SWAGGER_VERSION="3.13.6"
TARGET_PATH=${TARGET_PATH-"swagger"}
rm -rf $TARGET_PATH /tmp/swagger-ui
git clone --branch="v$SWAGGER_VERSION" --depth=1 "https://github.com/swagger-api/swagger-ui.git" /tmp/swagger-ui
mv /tmp/swagger-ui/dist $TARGET_PATH
cp swagger.yml $TARGET_PATH
sed -i "s,http://petstore.swagger.io/v2/swagger.json,swagger.yml,g" $TARGET_PATH/index.html

View file

@ -16,6 +16,7 @@ Funkwhale is a self-hosted, modern free and open-source music server, heavily in
configuration
importing-music
federation
api
upgrading
third-party
changelog

186
docs/swagger.yml Normal file
View file

@ -0,0 +1,186 @@
openapi: "3.0"
info:
description: "Documentation for [Funkwhale](https://funkwhale.audio) API. The API is **not** stable yet."
version: "1.0.0"
title: "Funkwhale API"
servers:
- url: https://demo.funkwhale.audio/api/v1
description: Demo server
- url: https://node1.funkwhale.test/api/v1
description: Node 1 (local)
components:
securitySchemes:
jwt:
type: http
scheme: bearer
bearerFormat: JWT
description: "You can get a token by using the /token endpoint"
security:
- jwt: []
paths:
/token/:
post:
tags:
- "auth"
description:
Obtain a JWT token you can use for authenticating your next requests.
security: []
responses:
'200':
description: Successfull auth
'400':
description: Invalid credentials
requestBody:
required: true
content:
application/json:
schema:
type: "object"
properties:
username:
type: "string"
example: "demo"
password:
type: "string"
example: "demo"
/artists/:
get:
tags:
- "artists"
parameters:
- name: "q"
in: "query"
description: "Search query used to filter artists"
schema:
required: false
type: "string"
example: "carpenter"
- name: "listenable"
in: "query"
description: "Filter/exclude artists with listenable tracks"
schema:
required: false
type: "boolean"
responses:
200:
content:
application/json:
schema:
type: "object"
properties:
count:
$ref: "#/properties/resultsCount"
results:
type: "array"
items:
$ref: "#/definitions/ArtistNested"
properties:
resultsCount:
type: "integer"
format: "int64"
description: "The total number of resources matching the request"
mbid:
type: "string"
formats: "uuid"
description: "A musicbrainz ID"
definitions:
Artist:
type: "object"
properties:
mbid:
required: false
$ref: "#/properties/mbid"
id:
type: "integer"
format: "int64"
example: 42
name:
type: "string"
example: "System of a Down"
creation_date:
type: "string"
format: "date-time"
ArtistNested:
type: "object"
allOf:
- $ref: "#/definitions/Artist"
- type: "object"
properties:
albums:
type: "array"
items:
$ref: "#/definitions/AlbumNested"
Album:
type: "object"
properties:
mbid:
required: false
$ref: "#/properties/mbid"
id:
type: "integer"
format: "int64"
example: 16
artist:
type: "integer"
format: "int64"
example: 42
title:
type: "string"
example: "Toxicity"
creation_date:
type: "string"
format: "date-time"
release_date:
type: "string"
required: false
format: "date"
example: "2001-01-01"
AlbumNested:
type: "object"
allOf:
- $ref: "#/definitions/Album"
- type: "object"
properties:
tracks:
type: "array"
items:
$ref: "#/definitions/Track"
Track:
type: "object"
properties:
mbid:
required: false
$ref: "#/properties/mbid"
id:
type: "integer"
format: "int64"
example: 66
artist:
type: "integer"
format: "int64"
example: 42
album:
type: "integer"
format: "int64"
example: 16
title:
type: "string"
example: "Chop Suey!"
position:
required: false
description: "Position of the track in the album"
type: "number"
minimum: 1
example: 1
creation_date:
type: "string"
format: "date-time"