Skip to content

Commit

Permalink
Small fixes to YAML export of OpenAPI schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Dec 13, 2022
1 parent c90e1e3 commit 4a619ea
Showing 1 changed file with 18 additions and 2 deletions.
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

0 comments on commit 4a619ea

Please sign in to comment.