diff --git a/api/client-server/account-data.yaml b/api/client-server/account-data.yaml index 5921dc29..95b6d18f 100644 --- a/api/client-server/account-data.yaml +++ b/api/client-server/account-data.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/user/{userId}/account_data/{type}": put: diff --git a/api/client-server/admin.yaml b/api/client-server/admin.yaml index 349dfbf4..44f02301 100644 --- a/api/client-server/admin.yaml +++ b/api/client-server/admin.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/admin/whois/{userId}": get: diff --git a/api/client-server/administrative_contact.yaml b/api/client-server/administrative_contact.yaml index 479f2dd0..50a808c7 100644 --- a/api/client-server/administrative_contact.yaml +++ b/api/client-server/administrative_contact.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/account/password": post: diff --git a/api/client-server/banning.yaml b/api/client-server/banning.yaml index 87326608..59eab4bc 100644 --- a/api/client-server/banning.yaml +++ b/api/client-server/banning.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/ban": post: diff --git a/api/client-server/create_room.yaml b/api/client-server/create_room.yaml index cd73db68..ece16961 100644 --- a/api/client-server/create_room.yaml +++ b/api/client-server/create_room.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/createRoom": post: diff --git a/api/client-server/definitions/security.yaml b/api/client-server/definitions/security.yaml new file mode 100644 index 00000000..c4130689 --- /dev/null +++ b/api/client-server/definitions/security.yaml @@ -0,0 +1,5 @@ +accessToken: + type: apiKey + description: The access_token returned by a call to ``/login`` or ``/tokenrefresh`` + name: access_token + in: query diff --git a/api/client-server/directory.yaml b/api/client-server/directory.yaml index 773706a7..22680145 100644 --- a/api/client-server/directory.yaml +++ b/api/client-server/directory.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/room/{roomAlias}": put: diff --git a/api/client-server/event_context.yaml b/api/client-server/event_context.yaml index 2957a3e3..5492591b 100644 --- a/api/client-server/event_context.yaml +++ b/api/client-server/event_context.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/context/{eventId}": get: diff --git a/api/client-server/filter.yaml b/api/client-server/filter.yaml index bf81f60e..ad3d7a9b 100644 --- a/api/client-server/filter.yaml +++ b/api/client-server/filter.yaml @@ -11,11 +11,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/user/{userId}/filter": post: diff --git a/api/client-server/inviting.yaml b/api/client-server/inviting.yaml index 1dd7de5f..c162aca2 100644 --- a/api/client-server/inviting.yaml +++ b/api/client-server/inviting.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: # With an extra " " to disambiguate from the 3pid invite endpoint # The extra space makes it sort first for what I'm sure is a good reason. diff --git a/api/client-server/joining.yaml b/api/client-server/joining.yaml index 46289c2a..912c4bfa 100644 --- a/api/client-server/joining.yaml +++ b/api/client-server/joining.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/join": post: diff --git a/api/client-server/kicking.yaml b/api/client-server/kicking.yaml index 41db8b48..fc33e646 100644 --- a/api/client-server/kicking.yaml +++ b/api/client-server/kicking.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/kick": post: diff --git a/api/client-server/leaving.yaml b/api/client-server/leaving.yaml index 95a2133a..6287950c 100644 --- a/api/client-server/leaving.yaml +++ b/api/client-server/leaving.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/leave": post: diff --git a/api/client-server/login.yaml b/api/client-server/login.yaml index 359a8e91..bbe0befa 100644 --- a/api/client-server/login.yaml +++ b/api/client-server/login.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/login": post: diff --git a/api/client-server/message_pagination.yaml b/api/client-server/message_pagination.yaml index b1d4cfb7..8829b9db 100644 --- a/api/client-server/message_pagination.yaml +++ b/api/client-server/message_pagination.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/messages": get: diff --git a/api/client-server/old_sync.yaml b/api/client-server/old_sync.yaml index c51023ae..0df8809a 100644 --- a/api/client-server/old_sync.yaml +++ b/api/client-server/old_sync.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/events": get: diff --git a/api/client-server/peeking_events.yaml b/api/client-server/peeking_events.yaml index f3f9e872..60168f6f 100644 --- a/api/client-server/peeking_events.yaml +++ b/api/client-server/peeking_events.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/events": get: diff --git a/api/client-server/presence.yaml b/api/client-server/presence.yaml index d9a1b866..a21b5a19 100644 --- a/api/client-server/presence.yaml +++ b/api/client-server/presence.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/presence/{userId}/status": put: diff --git a/api/client-server/profile.yaml b/api/client-server/profile.yaml index db3148cd..285be849 100644 --- a/api/client-server/profile.yaml +++ b/api/client-server/profile.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/profile/{userId}/displayname": put: diff --git a/api/client-server/pusher.yaml b/api/client-server/pusher.yaml index d5c01d3a..0bf84eee 100644 --- a/api/client-server/pusher.yaml +++ b/api/client-server/pusher.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/pushers": get: diff --git a/api/client-server/pushrules.yaml b/api/client-server/pushrules.yaml index d11d1ef7..fc5c7895 100644 --- a/api/client-server/pushrules.yaml +++ b/api/client-server/pushrules.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/pushrules/": get: diff --git a/api/client-server/receipts.yaml b/api/client-server/receipts.yaml index 791e3938..153fdf23 100644 --- a/api/client-server/receipts.yaml +++ b/api/client-server/receipts.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/receipt/{receiptType}/{eventId}": post: diff --git a/api/client-server/redaction.yaml b/api/client-server/redaction.yaml index 91948b2b..bca596f1 100644 --- a/api/client-server/redaction.yaml +++ b/api/client-server/redaction.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/redact/{eventId}/{txnId}": put: diff --git a/api/client-server/room_send.yaml b/api/client-server/room_send.yaml index b7ccbcfb..49e657ba 100644 --- a/api/client-server/room_send.yaml +++ b/api/client-server/room_send.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/send/{eventType}/{txnId}": put: diff --git a/api/client-server/room_state.yaml b/api/client-server/room_state.yaml index e28dfde4..e0022e2a 100644 --- a/api/client-server/room_state.yaml +++ b/api/client-server/room_state.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/state/{eventType}/{stateKey}": put: diff --git a/api/client-server/rooms.yaml b/api/client-server/rooms.yaml index 0af8316d..12881604 100644 --- a/api/client-server/rooms.yaml +++ b/api/client-server/rooms.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/state/{eventType}/{stateKey}": get: diff --git a/api/client-server/search.yaml b/api/client-server/search.yaml index 0ddbfe0a..828154bc 100644 --- a/api/client-server/search.yaml +++ b/api/client-server/search.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/search": post: diff --git a/api/client-server/sync.yaml b/api/client-server/sync.yaml index ed5addda..28480b6b 100644 --- a/api/client-server/sync.yaml +++ b/api/client-server/sync.yaml @@ -11,11 +11,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/sync": get: diff --git a/api/client-server/tags.yaml b/api/client-server/tags.yaml index 1324b865..e7ff5545 100644 --- a/api/client-server/tags.yaml +++ b/api/client-server/tags.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/user/{userId}/rooms/{roomId}/tags": get: diff --git a/api/client-server/third_party_membership.yaml b/api/client-server/third_party_membership.yaml index da3d4160..c249dc31 100644 --- a/api/client-server/third_party_membership.yaml +++ b/api/client-server/third_party_membership.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/invite": post: diff --git a/api/client-server/typing.yaml b/api/client-server/typing.yaml index 02ad0efd..07cf8298 100644 --- a/api/client-server/typing.yaml +++ b/api/client-server/typing.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/rooms/{roomId}/typing/{userId}": put: diff --git a/api/client-server/voip.yaml b/api/client-server/voip.yaml index bdeeaa8d..1acff156 100644 --- a/api/client-server/voip.yaml +++ b/api/client-server/voip.yaml @@ -12,11 +12,7 @@ consumes: produces: - application/json securityDefinitions: - accessToken: - type: apiKey - description: The user_id or application service access_token - name: access_token - in: query + $ref: definitions/security.yaml paths: "/voip/turnServer": get: diff --git a/scripts/dump-swagger.py b/scripts/dump-swagger.py index f826cadc..d706737a 100755 --- a/scripts/dump-swagger.py +++ b/scripts/dump-swagger.py @@ -12,9 +12,12 @@ import os.path import re import shutil import sys +import yaml scripts_dir = os.path.dirname(os.path.abspath(__file__)) templating_dir = os.path.join(os.path.dirname(scripts_dir), "templating") +api_dir = os.path.join(os.path.dirname(scripts_dir), "api") + sys.path.insert(0, templating_dir) from matrix_templates.units import resolve_references, MatrixUnits @@ -50,10 +53,15 @@ output = { "title": "Matrix Client-Server API", "version": release_label, }, + "securityDefinitions": {}, "paths": {}, "swagger": "2.0", } +with open(os.path.join(api_dir, 'client-server', 'definitions', + 'security.yaml')) as f: + output['securityDefinitions'] = yaml.load(f) + for file, contents in apis.items(): for path, methods in contents["paths"].items(): for method, spec in methods.items(): @@ -62,6 +70,8 @@ for file, contents in apis.items(): output["paths"][path] = {} output["paths"][path][method] = spec + + print "Generating %s" % output_file try: