Skip to content

Dereference OpenAPI schema returned by Function.openapi_schema #439

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

Merged
merged 3 commits into from
Jun 12, 2025

Conversation

aron
Copy link
Contributor

@aron aron commented Jun 12, 2025

This PR updates the openapi_schema method in Function and AsyncFunction to return a dereferenced API schema. This fixes a bug with transformation for models that output objects with named interfaces.

This PR also introduces a breaking change in that Function.openapi_schema() is now a method rather than a property to match AsyncFunction.openapi_schema() the latter needs to be a method because the lookup of the version is both lazy and async.

Lastly, the PR fixes an issue with the implementation where the latest OpenAPI schema was always returned. Now we return the version specified in the ref (or the latest if unspecified).

@aron aron requested a review from Copilot June 12, 2025 12:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that Function.openapi_schema() and AsyncFunction.openapi_schema() return a fully dereferenced OpenAPI schema, honors version qualifiers in the model reference, and unifies the sync and async schema APIs.

  • Introduces a _dereference_schema helper to inline $ref entries under components/schemas.
  • Converts the sync openapi_schema from a property to a method (using a cached _openapi_schema) to match the async version.
  • Fixes version lookup so that a specific version in the model ref is returned (or latest if unspecified).

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/test_use.py Added test_use_function_openapi_schema_dereferenced to verify inlined schemas and removal of unused definitions.
replicate/use.py Added _dereference_schema, refactored/renamed openapi_schema logic for sync and async, and removed obsolete helpers.
Comments suppressed due to low confidence (3)

replicate/use.py:62

  • The removal of _download_file likely breaks _process_output_with_schema, which still references it for file downloads. Restoring this helper or refactoring the download logic would prevent a NameError when handling file-based outputs.
def _download_file(url: str) -> Path:

replicate/use.py:450

  • There’s no test covering the new behavior when a version is explicitly specified in the ref string. Adding a test that uses replicate.use("owner/model@v1.2.3") and asserts the correct schema is fetched would ensure this path stays validated.
_, _, model_version = self._parsed_ref

replicate/use.py:669

  • [nitpick] The error message here differs from the sync variant (has no latest version). Consider unifying these messages for consistency (e.g. always has no latest version).
msg = f"Model {model.owner}/{model.name} has no version"

aron added 2 commits June 12, 2025 13:51
This commit also fixes the implementation to return the OpenAPI schema
for the requested version rather than always the latest version.
@aron aron force-pushed the beta-fix-openapi-schema branch from 9d72c7b to 7963a85 Compare June 12, 2025 12:51
@aron aron merged commit 36df860 into beta Jun 12, 2025
5 checks passed
@aron aron deleted the beta-fix-openapi-schema branch June 12, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant