Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes to YAML export of OpenAPI schema. #15187

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions scripts/dump_openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@

import click
import yaml
from pydantic.networks import (
AnyUrl,
url_regex,
)

from galaxy.webapps.galaxy.fast_app import get_openapi_schema


def _any_url_representer(dumper, data):
return dumper.represent_scalar("!anyurl", str(data))


class YamlDumper(yaml.SafeDumper):
pass


YamlDumper.add_representer(AnyUrl, _any_url_representer)
YamlDumper.add_implicit_resolver("!anyurl", url_regex(), None)


@click.command("Write openapi schema to path")
@click.argument("schema_path", type=click.Path(dir_okay=False, writable=True), required=False)
def write_open_api_schema(schema_path):
openapi_schema = get_openapi_schema()
if schema_path:
if schema_path.endswith((".yml", ".yml")):
if schema_path.endswith((".yml", ".yaml")):
with open(schema_path, "w") as f:
yaml.safe_dump(openapi_schema, f)
yaml.dump(openapi_schema, f, YamlDumper)
else:
with open(schema_path, "w") as f:
json.dump(openapi_schema, f, sort_keys=True)
Expand Down