Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ jobs:
- name: Commit version bump
if: ${{ !inputs.dry_run }}
run: |
git add -A
git add src/amigo_sdk/__init__.py src/amigo_sdk/generated/model.py specs/openapi-baseline.json CHANGELOG.md
git commit -m "Bump version to ${{ steps.new_version.outputs.version }}"
git push origin HEAD

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:

- name: Upload coverage reports to Codecov
if: inputs.skip_codecov != true && matrix.python-version == '3.13'
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
Expand Down
62 changes: 27 additions & 35 deletions scripts/gen_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@
"amigo_lib__",
]

# The live classic API can omit org-branding fields even though the published
# OpenAPI snapshot still marks them required. Relax them after generation so
# released SDK models match the payloads customers actually receive.
ORGANIZATION_RESPONSE_COMPAT_FIXES = (
(
re.compile(r"(?ms)^ title: [^=\n]+ = Field\(\s*\.\.\.,"),
" title: str | None = Field(\n None,",
),
(
re.compile(r"(?ms)^ main_description: [^=\n]+ = Field\(\s*\.\.\.,"),
" main_description: str | None = Field(\n None,",
),
(
re.compile(r"(?ms)^ sub_description: [^=\n]+ = Field\(\s*\.\.\.,"),
" sub_description: str | None = Field(\n None,",
),
(
re.compile(r"(?ms)^ onboarding_instructions: [^=\n]+ = Field\(\s*\.\.\.,"),
" onboarding_instructions: list[str] | None = Field(\n None,",
),
)


def strip_prefixes_from_schema(spec: dict) -> dict:
"""
Expand Down Expand Up @@ -120,18 +98,6 @@ def load_spec(spec_path: Path) -> dict:
return spec


def apply_output_compat_fixes(output_file: Path) -> None:
text = output_file.read_text()
for pattern, replacement in ORGANIZATION_RESPONSE_COMPAT_FIXES:
text, count = pattern.subn(replacement, text, count=1)
if count != 1:
raise RuntimeError(
"Unable to apply generated-model compatibility fix for "
f"pattern: {pattern.pattern}"
)
output_file.write_text(text)


def main() -> None:
args = parse_args()
root = Path(__file__).parent.parent
Expand Down Expand Up @@ -167,10 +133,36 @@ def main() -> None:
field_constraints=True,
use_operation_id_as_name=True,
reuse_model=True,
set_default_enum_member=True,
aliases=aliases,
collapse_root_models=False,
)
apply_output_compat_fixes(output_file)
# Keep the already-public optional branding attributes for older responses.
# Current OpenAPI no longer exposes them. Scope compatibility to this one
# response model so similarly named fields in other models stay canonical.
text = output_file.read_text()
pattern = r"(?ms)^(class OrganizationGetOrganizationResponse\(BaseModel\):\n)(.*?)(?=^class |\Z)"

def retain_branding(match: re.Match[str]) -> str:
fields = {
"title": "str",
"main_description": "str",
"sub_description": "str",
"onboarding_instructions": "list[str]",
}
additions = "".join(
f" {name}: {kind} | None = None\n"
for name, kind in fields.items()
if not re.search(rf"^ {name}:", match[2], re.MULTILINE)
)
return match[1] + additions + match[2]

text, count = re.subn(pattern, retain_branding, text)
if count != 1:
raise RuntimeError(
"Organization response model changed; review compatibility attributes"
)
output_file.write_text(text)

print(f"Generated models from {spec_path} -> {output_file}")

Expand Down
2 changes: 1 addition & 1 deletion specs/openapi-baseline.json

Large diffs are not rendered by default.

Loading
Loading