Reorganized openapi.yml for external API structure

As this document should contain the details of the stable external API, it was refactored and cleaned up.

Co-Authored-By: David Mehren <dmehren1@gmail.com>
Co-Authored-By: Yannick Bungers <git@innay.de>
Co-Authored-By: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Erik Michelson 2020-07-16 01:22:50 +02:00 committed by David Mehren
parent 3969ef3259
commit b5a99b585c
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -1,10 +1,10 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: CodiMD title: HedgeDoc
description: CodiMD is an open source collaborative note editor. Several tasks of CodiMD can be automated through this API. description: HedgeDoc is an open source collaborative note editor. Several tasks of HedgeDoc can be automated through this API.
version: 2.0.0 version: 2.0.0
contact: contact:
name: CodiMD on GitHub name: HedgeDoc on GitHub
url: https://github.com/codimd/server url: https://github.com/codimd/server
license: license:
name: AGPLv3 name: AGPLv3
@ -15,85 +15,9 @@ externalDocs:
servers: servers:
- url: "/api/v2" - url: "/api/v2"
description: The base API Path. description: The base API Path.
security:
- bearerAuth: []
paths: paths:
/auth/email:
post:
tags:
- auth
summary: Trying to login via email
operationId: loginEmail
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/EmailLogin'
responses:
'200':
description: The login was succesful.
headers:
Set-Cookie:
schema:
type: string
/auth/ldap:
post:
tags:
- auth
summary: Trying to login via LDAP
operationId: loginLdap
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/LdapLogin'
responses:
'200':
description: The login was succesful.
headers:
Set-Cookie:
schema:
type: string
/auth/openid:
post:
tags:
- auth
summary: Trying to login via OpenID
operationId: loginOpenId
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/OpenIdLogin'
responses:
'200':
description: The login was succesful.
headers:
Set-Cookie:
schema:
type: string
/auth/register:
post:
tags:
- auth
summary: Trying to register a new user via email
operationId: registerEmail
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/EmailLogin'
responses:
'200':
description: The user was successfully registered and logged-in afterwards.
headers:
Set-Cookies:
schema:
type: string
'409':
description: There is already a user account with the given email address.
/me: /me:
get: get:
tags: tags:
@ -108,59 +32,12 @@ paths:
schema: schema:
"$ref": "#/components/schemas/UserInfo" "$ref": "#/components/schemas/UserInfo"
'401': '401':
description: The user is not logged in. "$ref": "#/components/responses/UnauthorizedError"
content: {}
put:
tags:
- user
summary: Update information about the currently logged-in user
operationId: updateMe
responses:
'200':
description: The user information was changed successfully.
requestBody:
required: true
description: The new user information.
content:
application/json:
schema:
"$ref": "#/components/schemas/UserUpdate"
delete:
tags:
- user
summary: Deletes the currently logged-in user from the backend and removes all their notes
operationId: deleteMe
responses:
'200':
description: The user was deleted successfully.
/me/export:
get:
tags:
- user
- export
summary: Exports a zip-archive with all notes of the currently logged-in user
responses:
'200':
description: The zip-archive with all notes.
/me/password:
post:
tags:
- user
summary: Sets the new password of the currently logged-in user
requestBody:
required: true
description: The new password of the user.
content:
application/json:
schema:
"$ref": "#/components/schemas/UserPasswordChange"
responses:
'200':
description: The password was changed.
/me/history: /me/history:
get: get:
tags: tags:
- history - history
- user
summary: Returns a list of the last viewed notes summary: Returns a list of the last viewed notes
operationId: getHistory operationId: getHistory
description: The list is returned as a JSON object with an array containing for each entry it's id, title, tags, last visit time and pinned status. description: The list is returned as a JSON object with an array containing for each entry it's id, title, tags, last visit time and pinned status.
@ -171,37 +48,13 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/History" "$ref": "#/components/schemas/History"
post: '401':
tags: "$ref": "#/components/responses/UnauthorizedError"
- history
summary: Sets the history if none is already set
operationId: updateHistory
requestBody:
description: The history to update.
content:
application/json:
schema:
"$ref": "#/components/schemas/History"
responses:
'200':
description: The new history.
content:
application/json:
schema:
"$ref": "#/components/schemas/History"
delete:
tags:
- history
summary: Clear the currently logged-in users history
operationId: deleteHistory
responses:
'200':
description: Deleted the history.
content: {}
/me/history/{note}: /me/history/{note}:
put: put:
tags: tags:
- history - history
- user
summary: Update the history object of the note (e.g change it's pin status) summary: Update the history object of the note (e.g change it's pin status)
operationId: updateHistoryObject operationId: updateHistoryObject
requestBody: requestBody:
@ -217,6 +70,10 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/HistoryObject" "$ref": "#/components/schemas/HistoryObject"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'404':
"$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -228,12 +85,16 @@ paths:
delete: delete:
tags: tags:
- history - history
- user
summary: Remove the note from the currently logged-in user's history summary: Remove the note from the currently logged-in user's history
operationId: deleteHistoryObject operationId: deleteHistoryObject
responses: responses:
'200': '204':
description: The new history. "$ref": "#/components/responses/SuccesfullyDeleted"
content: {} '401':
"$ref": "#/components/responses/UnauthorizedError"
'404':
"$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -242,6 +103,25 @@ paths:
content: content:
text/plain: text/plain:
example: my-note example: my-note
/me/notes:
get:
tags:
- user
summary: Returns a list of the notes metadata the user owns
operationId: getOwnNotes
description: The list is returned as a JSON object with an array containing each notes metadata.
responses:
'200':
description: The list of notes owned by the currently logged in user.
content:
application/json:
schema:
type: array
description: The array that contains notes metadata.
items:
"$ref": "#/components/schemas/NoteMetadata"
'401':
"$ref": "#/components/responses/UnauthorizedError"
/notes: /notes:
post: post:
tags: tags:
@ -249,6 +129,9 @@ paths:
summary: Imports some markdown data into a new note summary: Imports some markdown data into a new note
operationId: createNoteFromMarkdown operationId: createNoteFromMarkdown
description: A random id will be assigned and the content will equal to the body of the received HTTP-request. description: A random id will be assigned and the content will equal to the body of the received HTTP-request.
security:
- bearerAuth: []
- {}
requestBody: requestBody:
required: false required: false
description: The content of the note to be imported as markdown. description: The content of the note to be imported as markdown.
@ -266,6 +149,10 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/Note" "$ref": "#/components/schemas/Note"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
/notes/{note}: /notes/{note}:
get: get:
tags: tags:
@ -280,8 +167,12 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/Note" "$ref": "#/components/schemas/Note"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404': '404':
description: Note does not exist. "$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -313,6 +204,10 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/Note" "$ref": "#/components/schemas/Note"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'409': '409':
description: This alias is already in use. description: This alias is already in use.
parameters: parameters:
@ -323,25 +218,90 @@ paths:
content: content:
text/plain: text/plain:
example: my-note example: my-note
/notes/{note}/permissions: delete:
tags:
- note
summary: Remove the note
operationId: deleteNote
responses:
'204':
"$ref": "#/components/responses/SuccesfullyDeleted"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404':
"$ref": "#/components/responses/NotFoundError"
parameters:
- name: note
in: path
required: true
description: The note for which the revision should be shown.
content:
text/plain:
example: my-note
put:
tags:
- note
summary: Imports some markdown data into an existing note, creating a new revision
operationId: createNewRevisionForNote
description: This endpoint equals to the above one except that the alias from the url will be assigned to the note if [FreeURL-mode](https://github.com/codimd/server/tree/master/docs/configuration-env-vars.md#users-and-privileges) is enabled.
requestBody:
required: true
description: The content of the note to be imported as markdown.
content:
'text/markdown':
schema:
type: string
examples:
markdownExample:
"$ref": '#/components/examples/markdownExample'
responses:
'200':
description: The new, changed note
content:
application/json:
schema:
"$ref": "#/components/schemas/Note"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404':
"$ref": "#/components/responses/NotFoundError"
parameters:
- name: note
in: path
required: true
description: The note for which the info should be shown.
content:
text/plain:
example: my-note
/notes/{note}/metadata:
put: put:
tags: tags:
- note - note
summary: Set the permissions of a note summary: Set the permissions of a note
operationId: updateNotePermissions operationId: updateNoteMetadata
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/NotePermissions" "$ref": "#/components/schemas/NoteMetadata"
responses: responses:
'200': '200':
description: The updated permissions of the note. description: The updated permissions of the note.
content: content:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/NotePermissions" "$ref": "#/components/schemas/NoteMetadata"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404':
"$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -354,14 +314,20 @@ paths:
tags: tags:
- note - note
summary: Get the permissions of a note summary: Get the permissions of a note
operationId: getNotePermissions operationId: getNoteMetadata
responses: responses:
'200': '200':
description: The permissions of the note. description: The permissions of the note.
content: content:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/NotePermissions" "$ref": "#/components/schemas/NoteMetadata"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404':
"$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -370,129 +336,6 @@ paths:
content: content:
text/plain: text/plain:
example: my-note example: my-note
/notes/{note}/export/markdown:
get:
tags:
- note
- export
summary: Returns the raw markdown content of a note
operationId: getNoteContent
responses:
'200':
description: The raw markdown content of the note.
content:
'text/markdown':
schema:
type: string
format: binary
'404':
description: Note does not exist.
parameters:
- name: note
in: path
required: true
description: The note for which the markdown should be exported.
content:
text/plain:
example: my-note
/notes/{note}/export/html:
get:
tags:
- note
- export
summary: Returns the content of a note as HTML
operationId: getNoteContentAsHTML
responses:
'200':
description: The raw html content of the note.
content:
'text/html':
schema:
type: string
format: binary
'404':
description: Note does not exist.
parameters:
- name: note
in: path
required: true
description: The note for which the html should be exported.
content:
text/plain:
example: my-note
/notes/{note}/export/gist:
get:
tags:
- note
- export
summary: Exports the content of a note to a gist
operationId: exportNoteToGist
responses:
'200':
description: The link to Gist of the note.
content:
application/json:
schema:
"$ref": '#/components/schemas/GistLink'
'404':
description: Note does not exist.
parameters:
- name: note
in: path
required: true
description: The note which should be exported to gist.
content:
text/plain:
example: my-note
/notes/{note}/export/dropbox:
get:
tags:
- note
- export
summary: Exports the content of a note to dropbox
operationId: exportNoteToDropbox
responses:
'200':
description: The dropbox link of the note.
content:
application/json:
schema:
"$ref": '#/components/schemas/DropboxLink'
'404':
description: Note does not exist.
parameters:
- name: note
in: path
required: true
description: The note which should be exported to dropbox.
content:
text/plain:
example: my-note
/notes/{note}/export/pdf:
get:
tags:
- note
- export
summary: Exports the content of a note as PDF
operationId: exportNoteToPDF
responses:
'200':
description: The note as an PDF.
content:
application/pdf:
schema:
type: string
format: binary
'404':
description: Note does not exist.
parameters:
- name: note
in: path
required: true
description: The note which should be exported to dropbox.
content:
text/plain:
example: my-note
/notes/{note}/revisions: /notes/{note}/revisions:
get: get:
tags: tags:
@ -507,8 +350,12 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/NoteRevisionsMetadata" "$ref": "#/components/schemas/NoteRevisionsMetadata"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404': '404':
description: Note does not exist. "$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -517,7 +364,6 @@ paths:
content: content:
text/plain: text/plain:
example: my-note example: my-note
/notes/{note}/revisions/{revision-id}: /notes/{note}/revisions/{revision-id}:
get: get:
tags: tags:
@ -532,8 +378,12 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/NoteRevision" "$ref": "#/components/schemas/NoteRevision"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
'404': '404':
description: Note does not exist. "$ref": "#/components/responses/NotFoundError"
parameters: parameters:
- name: note - name: note
in: path in: path
@ -549,26 +399,35 @@ paths:
content: content:
text/plain: text/plain:
example: 1570921051959 example: 1570921051959
/media/proxy: /notes/{note}/content:
post: get:
tags: tags:
- media - note
summary: Returns a proxied url for a given image url - export
description: Returns in exchange for an image-url the url for a proxied version of the image. summary: Returns the raw markdown content of a note
operationId: getNoteContent
responses: responses:
'200': '200':
description: An object containing the proxied url description: The raw markdown content of the note.
content: content:
application/json: 'text/markdown':
schema: schema:
"$ref": "#/components/schemas/ImageProxyResponse" type: string
requestBody: format: binary
required: true '401':
description: An object containing the original image url "$ref": "#/components/responses/UnauthorizedError"
content: '403':
application/json: "$ref": "#/components/responses/ForbiddenError"
schema: '404':
"$ref": "#/components/schemas/ImageProxyRequest" "$ref": "#/components/responses/NotFoundError"
parameters:
- name: note
in: path
required: true
description: The note for which the markdown should be exported.
content:
text/plain:
example: my-note
/media/upload: /media/upload:
post: post:
tags: tags:
@ -578,28 +437,24 @@ paths:
requestBody: requestBody:
required: true required: true
description: The binary image to upload. description: The binary image to upload.
content:
image/*:
schema:
type: string
format: binary
responses: responses:
'200': '200':
description: The image was uploaded successfully. description: The image was uploaded successfully.
/config: '401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
/monitoring:
get: get:
tags: tags:
- backend - monitoring
summary: The config of the backend
operationId: getConfig
responses:
'200':
description: The config of the backend in JSON.
content:
application/json:
schema:
"$ref": "#/components/schemas/Config"
/status:
get:
tags:
- backend
summary: Returns the current status of the backend summary: Returns the current status of the backend
operationId: getStatus operationId: getMonitoring
description: The data is returned as a JSON object containing the number of notes stored on the server, (distinct) online users and more. description: The data is returned as a JSON object containing the number of notes stored on the server, (distinct) online users and more.
responses: responses:
'200': '200':
@ -608,22 +463,42 @@ paths:
application/json: application/json:
schema: schema:
"$ref": "#/components/schemas/ServerStatus" "$ref": "#/components/schemas/ServerStatus"
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
/monitoring/prometheus:
get:
tags:
- monitoring
summary: Returns the current status of the backend for Prometheus.
operationId: getPrometheus
description: The data is returned in Prometheus Exposition Format
responses:
'200':
description: Prometheus compatible monitoring data.
content:
text/plain: {}
'401':
"$ref": "#/components/responses/UnauthorizedError"
'403':
"$ref": "#/components/responses/ForbiddenError"
components: components:
schemas: schemas:
UserInfo: UserInfo:
type: object type: object
properties: properties:
id: userName:
type: string type: string
format: UUIDv4 format: UUIDv4
name: displayName:
type: string type: string
photo: photo:
type: string type: string
format: uri format: uri
provider: email:
type: string type: string
enum: ['facebook', 'github', 'twitter', 'gitlab', 'dropbox', 'google', 'saml', 'oauth2', 'email', 'ldap', 'openid'] format: email
UserPasswordChange: UserPasswordChange:
type: object type: object
properties: properties:
@ -652,43 +527,43 @@ components:
properties: properties:
allowAnonymous: allowAnonymous:
type: boolean type: boolean
description: Wether anonymous notes are allowed. description: Whether anonymous notes are allowed.
authProviders: authProviders:
type: object type: object
properties: properties:
facebook: facebook:
type: boolean type: boolean
description: Wether Facebook login is possible. description: Whether Facebook login is possible.
github: github:
type: boolean type: boolean
description: Wether GitHub login is possible. description: Whether GitHub login is possible.
twitter: twitter:
type: boolean type: boolean
description: Wether Twitter login is possible. description: Whether Twitter login is possible.
gitlab: gitlab:
type: boolean type: boolean
description: Wether Gitlab login is possible. description: Whether Gitlab login is possible.
dropbox: dropbox:
type: boolean type: boolean
description: Wether Dropbox login is possible. description: Whether Dropbox login is possible.
google: google:
type: boolean type: boolean
description: Wether Google login is possible. description: Whether Google login is possible.
saml: saml:
type: boolean type: boolean
description: Wether SAML login is possible. description: Whether SAML login is possible.
oauth2: oauth2:
type: boolean type: boolean
description: Wether OAuth2 login is possible. description: Whether OAuth2 login is possible.
email: email:
type: boolean type: boolean
description: Wether E-Mail login is possible. description: Whether E-Mail login is possible.
ldap: ldap:
type: boolean type: boolean
description: Wether LDAP login is possible. description: Whether LDAP login is possible.
openid: openid:
type: boolean type: boolean
description: Wether OpenID login is possible. description: Whether OpenID login is possible.
customAuthNames: customAuthNames:
type: object type: object
properties: properties:
@ -731,6 +606,21 @@ components:
type: string type: string
format: uri format: uri
Note: Note:
type: object
properties:
content:
type: string
description: The markdown content of the note
metadata:
type: object
$ref: "#/components/schemas/NoteMetadata"
editedByAtPosition:
type: array
description: Data which gives insights about who worked where on the note.
items:
type: integer
description: Unique user ids and additional data
NoteMetadata:
type: object type: object
properties: properties:
id: id:
@ -740,41 +630,59 @@ components:
alias: alias:
type: string type: string
description: The alias of the note. description: The alias of the note.
lastChange: title:
type: string
description: Title of the note
description:
type: string
description: Description of the note.
tags:
type: array
description: A list of tags attached to the note.
items:
type: string
description: A tag
updateTime:
type: object type: object
properties: properties:
userId: username:
type: string
format: UUIDv4
description: The id of the user that last changed the note.
user:
type: string type: string
description: The name of the user that last changed the note. description: The name of the user that last changed the note.
timestamp: timestamp:
type: integer type: integer
description: UNIX-timestamp of when the note was last changed. description: UNIX-timestamp of when the note was last changed.
viewcount: viewCount:
type: integer type: integer
minimum: 0 minimum: 0
description: How often the published version of the note was viewed. description: How often the published version of the note was viewed.
createtime: createTime:
type: string type: string
description: The timestamp when the note was created in ISO 8601 format. description: The timestamp when the note was created in ISO 8601 format.
content: editedBy:
type: string
description: The raw markdown content of the note revision.
authorship:
type: array type: array
description: Data which gives insights about who worked on the note. description: List of usernames who edited the note.
items: items:
type: integer type: string
description: Unique user ids and additional data. permissions:
type: object
$ref: "#/components/schemas/NotePermissions"
NotePermissions: NotePermissions:
type: object type: object
properties: properties:
permission: owner:
type: string type: string
enum: ['freely', 'editable', 'limited', 'locked', 'protected', 'private'] description: Username of the owner of the note
sharedTo:
type: array
description: Contains all usernames that can read the note and a boolean that denotes if they can also edit.
items:
type: object
properties:
username:
type: string
canEdit:
type: boolean
NoteRevisionsMetadata: NoteRevisionsMetadata:
type: object type: object
properties: properties:
@ -879,20 +787,9 @@ components:
HistoryObject: HistoryObject:
type: object type: object
properties: properties:
id: metadata:
type: string type: object
description: The id or alias of the note. $ref: "#/components/schemas/NoteMetadata"
title:
type: string
description: The title of the note.
lastVisited:
type: integer
description: The UNIX-timestamp in milliseconds when the note was last accessed by the user.
tags:
type: array
description: The tags that were added by the user to the note.
items:
type: string
pinned: pinned:
type: boolean type: boolean
description: Whether the user has pinned this note. description: Whether the user has pinned this note.
@ -908,3 +805,16 @@ components:
markdownExample: markdownExample:
value: '# Some header\nSome normal text. **Some bold text**' value: '# Some header\nSome normal text. **Some bold text**'
summary: A sample markdown content summary: A sample markdown content
securitySchemes:
bearerAuth:
type: http
scheme: bearer
responses:
UnauthorizedError:
description: Authorization information is missing or invalid.
ForbiddenError:
description: Access to the requested resource is not permitted.
NotFoundError:
description: The requested resource was not found.
SuccesfullyDeleted:
description: The requested resource was sucessfully deleted.