|
|
@ -37,11 +37,18 @@ def resolve_references(path, schema):
|
|
|
|
# do $ref first
|
|
|
|
# do $ref first
|
|
|
|
if '$ref' in schema:
|
|
|
|
if '$ref' in schema:
|
|
|
|
value = schema['$ref']
|
|
|
|
value = schema['$ref']
|
|
|
|
|
|
|
|
previous_path = path
|
|
|
|
path = os.path.join(os.path.dirname(path), value)
|
|
|
|
path = os.path.join(os.path.dirname(path), value)
|
|
|
|
with open(path, encoding="utf-8") as f:
|
|
|
|
try:
|
|
|
|
ref = yaml.safe_load(f)
|
|
|
|
with open(path, encoding="utf-8") as f:
|
|
|
|
result = resolve_references(path, ref)
|
|
|
|
ref = yaml.safe_load(f)
|
|
|
|
del schema['$ref']
|
|
|
|
result = resolve_references(path, ref)
|
|
|
|
|
|
|
|
del schema['$ref']
|
|
|
|
|
|
|
|
path = previous_path
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
|
|
|
print("Resolving {}".format(schema))
|
|
|
|
|
|
|
|
print("File not found: {}".format(path))
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
result = {}
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
|
|
|
@ -87,11 +94,24 @@ parser.add_argument(
|
|
|
|
%(default)s""",
|
|
|
|
%(default)s""",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument(
|
|
|
|
"--client_release", "-c", metavar="LABEL",
|
|
|
|
"--spec-release", "-r", metavar="LABEL",
|
|
|
|
default="unstable",
|
|
|
|
default="unstable",
|
|
|
|
help="""The client-server release version to generate for. Default:
|
|
|
|
help="""The spec release version to generate for. Default:
|
|
|
|
%(default)s""",
|
|
|
|
%(default)s""",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
available_apis = {
|
|
|
|
|
|
|
|
"client-server": "Matrix Client-Server API",
|
|
|
|
|
|
|
|
"server-server": "Matrix Server-Server API",
|
|
|
|
|
|
|
|
"application-service": "Matrix Application Service API",
|
|
|
|
|
|
|
|
"identity": "Matrix Identity Service API",
|
|
|
|
|
|
|
|
"push-gateway": "Matrix Push Gateway API",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
|
|
"--api",
|
|
|
|
|
|
|
|
default="client-server",
|
|
|
|
|
|
|
|
choices=available_apis,
|
|
|
|
|
|
|
|
help="""The API to generate for. Default: %(default)s""",
|
|
|
|
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument(
|
|
|
|
"-o", "--output",
|
|
|
|
"-o", "--output",
|
|
|
|
default=os.path.join(scripts_dir, "swagger", "api-docs.json"),
|
|
|
|
default=os.path.join(scripts_dir, "swagger", "api-docs.json"),
|
|
|
@ -100,7 +120,8 @@ parser.add_argument(
|
|
|
|
args = parser.parse_args()
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
output_file = os.path.abspath(args.output)
|
|
|
|
output_file = os.path.abspath(args.output)
|
|
|
|
release_label = args.client_release
|
|
|
|
release_label = args.spec_release
|
|
|
|
|
|
|
|
selected_api = args.api
|
|
|
|
|
|
|
|
|
|
|
|
major_version = release_label
|
|
|
|
major_version = release_label
|
|
|
|
match = re.match("^(r\d+)(\.\d+)*$", major_version)
|
|
|
|
match = re.match("^(r\d+)(\.\d+)*$", major_version)
|
|
|
@ -119,18 +140,20 @@ output = {
|
|
|
|
# The servers value will be picked up by RapiDoc to provide a way
|
|
|
|
# The servers value will be picked up by RapiDoc to provide a way
|
|
|
|
# to switch API servers. Useful when one wants to test compliance
|
|
|
|
# to switch API servers. Useful when one wants to test compliance
|
|
|
|
# of their server with the API.
|
|
|
|
# of their server with the API.
|
|
|
|
"servers": [{
|
|
|
|
"servers": [
|
|
|
|
"url": "https://{homeserver_address}/",
|
|
|
|
{
|
|
|
|
"variables": {
|
|
|
|
"url": "https://{homeserver_address}/",
|
|
|
|
"homeserver_address": {
|
|
|
|
"variables": {
|
|
|
|
"default": "matrix-client.matrix.org",
|
|
|
|
"homeserver_address": {
|
|
|
|
"description": "The base URL for your homeserver",
|
|
|
|
"default": "matrix-client.matrix.org",
|
|
|
|
}
|
|
|
|
"description": "The base URL for your homeserver",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
],
|
|
|
|
"schemes": ["https"],
|
|
|
|
"schemes": ["https"],
|
|
|
|
"info": {
|
|
|
|
"info": {
|
|
|
|
"title": "Matrix Client-Server API",
|
|
|
|
"title": available_apis[selected_api],
|
|
|
|
"version": release_label,
|
|
|
|
"version": release_label,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"securityDefinitions": {},
|
|
|
|
"securityDefinitions": {},
|
|
|
@ -138,15 +161,17 @@ output = {
|
|
|
|
"swagger": "2.0",
|
|
|
|
"swagger": "2.0",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cs_api_dir = os.path.join(api_dir, 'client-server')
|
|
|
|
selected_api_dir = os.path.join(api_dir, selected_api)
|
|
|
|
with open(os.path.join(cs_api_dir, 'definitions',
|
|
|
|
try:
|
|
|
|
'security.yaml')) as f:
|
|
|
|
with open(os.path.join(selected_api_dir, 'definitions', 'security.yaml')) as f:
|
|
|
|
output['securityDefinitions'] = yaml.safe_load(f)
|
|
|
|
output['securityDefinitions'] = yaml.safe_load(f)
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
|
|
|
print("No security definitions available for this API")
|
|
|
|
|
|
|
|
|
|
|
|
for filename in os.listdir(cs_api_dir):
|
|
|
|
for filename in os.listdir(selected_api_dir):
|
|
|
|
if not filename.endswith(".yaml"):
|
|
|
|
if not filename.endswith(".yaml"):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
filepath = os.path.join(cs_api_dir, filename)
|
|
|
|
filepath = os.path.join(selected_api_dir, filename)
|
|
|
|
|
|
|
|
|
|
|
|
print("Reading swagger API: %s" % filepath)
|
|
|
|
print("Reading swagger API: %s" % filepath)
|
|
|
|
with open(filepath, "r") as f:
|
|
|
|
with open(filepath, "r") as f:
|
|
|
|