fix(openapi): Fix OpenAPI specification errors in /v2/actor-builds#2287
fix(openapi): Fix OpenAPI specification errors in /v2/actor-builds#2287
/v2/actor-builds#2287Conversation
|
Preview for this PR was built for commit |
|
Preview for this PR was built for commit |
/v2/actor-builds
fnesveda
left a comment
There was a problem hiding this comment.
The changes themselves look good, so approving.
I also had a thought about this process in general. If I understand it correctly, you've written an API middleware to check whether the requests sent to and responses returned from the API match its OpenAPI schema, and then you've ran the integration tests to generate some API requests to find the places where it doesn't match?
I think almost all of our endpoints can return any of 400, 401, 403 and 404 statuses, however, for some of the endpoints changed here, I see that you didn't need to add those errors to the endpoints' response schema. This leads me to think that we have a gap in our integration tests, which don't cover all of the possible situations, and don't generate all of the errors that can happen during real usage.
This initiative gives us a good opportunity to discover what those gaps are. Basically:
- We fix the OpenAPI schema to be correct for how our API behaves during integration tests
- We turn on the API middleware in production, and see what errors does it produce. Those errors then point us to behaviors we don't have covered by integration tests.
- We add integration tests for these behaviors (if it makes sense).
CC @tobice what do you think? I think it's a good chance to discover some gaps in our testing coverage.
Exactly. It will be an iterative process. So the fixes in the upcoming PRs are not complete, but incremental, based on the feedback from the validator only. There is one point I am a little unsure about. I work with the assumption that the actual implementation is correct and the specification is not, which will be a good assumption in the majority of cases, but there is a risk that such approach could also propagate some bad implementation to the specification. |
Thanks 👍
I don't think there's much we can do about that except manually report whenever a change to the spec feels wrong. |
If the middleware doesn't tank performance too much, then yes, the endgame is to turn it on in production. |
|
Using the schema to check what's missing in the integration tests makes sense to me, although I wouldn't treat it as a top priority right now. Also, we are not always consistent with the error codes... especially with Anyway, I can file a ticket for this and add it to our backlog. Then for anything weird you find in there, feel free to file an issue in And btw thanks a lot for this! ❤️ I know this should be our job 🙈 |
If it would, we could turn it on only for a small percentage of requests. It would take longer to gather all the errors, but it could still work. |
I was thinking the same. The only issue I can think of that after some time, errors will be most likely to appear in seldom-called endpoints. I guess we could adjust for that in the sampling algorithm. |
And so did I :-) |
| If `true` or `1` then the logs will be streamed as long as the run or | ||
| build is running. | ||
| required: true | ||
| required: false |
There was a problem hiding this comment.
isn't required: false the default option? not a request
|
I will gradually write all the stuff I am not sure about here: Once there is enough open questions there, I will invite @tobice to review it. (Not all will be issues, some will be just my lack of understanding of the API) |
Summary
Fixes OpenAPI specification validation errors detected at runtime for the
/v2/actor-buildsendpoints.Validation errors being fixed
These are lines from the error log generated by the unmerged validator running on integration tests https://github.com/apify/apify-core/pull/26052:
Changes
New file:
components/responses/Forbidden.yamlAdded a shared
403 Forbiddenresponse component, following the same pattern as the existingUnauthorized.yamlandNotFound.yamlcomponents. Reused across all endpoints in this PR that can return 403.paths/actor-builds/actor-builds.yaml-GET /v2/actor-builds403response - returned when the caller lacks permission to list builds.paths/actor-builds/actor-builds@{buildId}.yaml-GETandDELETE /v2/actor-builds/{buildId}401response - returned when no valid token is provided.404response - returned when the build ID does not exist.404response - returned when the build ID does not exist.paths/actor-builds/actor-builds@{buildId}@abort.yaml-POST /v2/actor-builds/{buildId}/abort401response - returned when no valid token is provided.403response - returned when the caller does not own the build.paths/actor-builds/actor-builds@{buildId}@log.yaml-GET /v2/actor-builds/{buildId}/logstreamquery parameter fromrequired: truetorequired: false- it is an optional modifier, not required on every request.downloadquery parameter fromrequired: truetorequired: false- same reason.404response - returned when the build ID does not exist.paths/actor-builds/actor-builds@{buildId}@openapi.json.yaml-GET /v2/actor-builds/{buildId}/openapi.json404response - returned when the build ID does not exist.Issues
Partially implements: #2286
🤖 Generated with Claude Code
Note
Low Risk
Low risk: OpenAPI-spec-only changes that add missing error responses and relax query param requirements; no runtime logic is modified.
Overview
Fixes OpenAPI validation issues for
/v2/actor-buildsby adding missing response definitions and correcting parameter requirements.Introduces a reusable
403component (components/responses/Forbidden.yaml) and wires401/403/404responses into the relevant build endpoints (list, get, delete, abort, log, andopenapi.json). Also makesstreamanddownloadquery params optional on the build log endpoint to match actual usage.Written by Cursor Bugbot for commit dd5b774. Configure here.