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

Use ruamel.yaml to format the OpenAPI spec #892

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/openapi_generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pathlib import Path

import fire
import yaml
import ruamel.yaml as yaml

from llama_models import schema_utils

Expand Down Expand Up @@ -61,7 +61,19 @@ def main(output_dir: str):
)

with open(output_dir / "llama-stack-spec.yaml", "w", encoding="utf-8") as fp:
yaml.dump(spec.get_json(), fp, allow_unicode=True)
y = yaml.YAML()
y.default_flow_style = False
y.block_seq_indent = 2
y.map_indent = 2
y.sequence_indent = 4
y.sequence_dash_offset = 2
y.width = 80
y.allow_unicode = True
y.explicit_start = True
y.dump(
spec.get_json(),
fp,
)

with open(output_dir / "llama-stack-spec.html", "w") as fp:
spec.write_html(fp, pretty_print=True)
Expand Down
10 changes: 6 additions & 4 deletions docs/openapi_generator/pyopenapi/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,16 @@ def __init__(self, endpoint: type, options: Options) -> None:
self.responses = {}

def _build_type_tag(self, ref: str, schema: Schema) -> Tag:
definition = f'<SchemaDefinition schemaRef="#/components/schemas/{ref}" />'
# Don't include schema definition in the tag description because for one,
# it is not very valuable and for another, it causes string formatting
# discrepancies via the Stainless Studio.
#
# definition = f'<SchemaDefinition schemaRef="#/components/schemas/{ref}" />'
title = typing.cast(str, schema.get("title"))
description = typing.cast(str, schema.get("description"))
return Tag(
name=ref,
description="\n\n".join(
s for s in (title, description, definition) if s is not None
),
description="\n\n".join(s for s in (title, description) if s is not None),
)

def _build_extra_tag_groups(
Expand Down
Loading