docs(openapi): Autofix OpenAPI spec validation errors#2484
Draft
docs(openapi): Autofix OpenAPI spec validation errors#2484
Conversation
…t 403 and add missing enum members
Error: WARN Response OpenAPI validation error {"url":"/v2/acts/{actorId}/builds/default","method":"GET","statusCode":403,"errors":[{"message":"must be equal to constant","errorCode":"const.openapi.validation","path":"/response/error/type"}]}
Files: apify-api/openapi/paths/actors/acts@{actorId}@builds@default.yaml:28-37
Root cause: The 403 response schema was hard-pinned to the const "unknown-build-tag" via UnknownBuildTagError, but the endpoint also returns 403 with type "insufficient-permissions" when an unauthenticated or non-owner caller requests a private Actor's default build. Switching the schema to the standard ErrorResponse (which references the ErrorType enum) covers both cases without losing the enum constraint.
Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/api/src/routes/actors/build_default.ts#L33
Error: WARN Response OpenAPI validation error {"url":"/v2/schedules","method":"POST","statusCode":400,"errors":[{"message":"must be equal to one of the allowed values: ...[truncated]","errorCode":"enum.openapi.validation","path":"/response/error/type"}]}
Files: apify-api/openapi/components/schemas/common/ErrorType.yaml:301
Root cause: When a Schedule is created with a non-JSON runInput.body, the API throws errors.scheduling.runInputBodyNotValidJson() with type "run-input-body-not-valid-json", which was missing from the ErrorType enum.
Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/packages/errors/src/errors/scheduling.ts#L63
Error: WARN Response OpenAPI validation error {"url":"/v2/acts/{actorId}/runs","method":"POST","statusCode":403,"errors":[{"message":"must be equal to one of the allowed values: ...[truncated]","errorCode":"enum.openapi.validation","path":"/response/error/type"}]}
Files: apify-api/openapi/components/schemas/common/ErrorType.yaml:129
Root cause: Running a public full-permission Actor without prior approval throws errors.actor.fullPermissionActorNotApproved with type "full-permission-actor-not-approved", which was missing from the ErrorType enum.
Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/packages/errors/src/errors/actor.ts#L58
|
Preview for this PR was built for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Autogenerated OpenAPI fixes suggestions based on validation errors generated from running API integration tests with OpenAPI validator turned on.
Error log: https://apify-pr-test-env-logs.s3.us-east-1.amazonaws.com/apify/apify-core/26794/api-b9787cbfc4c016266791e89ef8614c7d32e9175a.html
apify-core version: https://github.com/apify/apify-core/commit/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6
Stop reason: Enough errors fixed in this iteration. The remaining response-validation errors fall under known false positives (nullable
format: date-timefields), and the remaining request-validation errors are either intentional bad-input tests or out-of-scope (missing endpoints).Detailed changes description
Error fixes
Allow
insufficient-permissionsonGET /v2/acts/{actorId}/builds/default403Files:
apify-api/openapi/paths/actors/acts@{actorId}@builds@default.yaml:28-37Error:
WARN Response OpenAPI validation error {"url":"/v2/acts/{actorId}/builds/default","method":"GET","statusCode":403,"errors":[{"message":"must be equal to constant","errorCode":"const.openapi.validation","path":"/response/error/type"}]}Root cause: The 403 response schema was hard-pinned to the const
unknown-build-tagviaUnknownBuildTagError, but the endpoint also returns 403 with typeinsufficient-permissionswhen an unauthenticated or non-owner caller requests a private Actor's default build (iamManager.ensureAccessthrowserrors.iam.insufficientPermissions). Switching the schema to the standardErrorResponse(which references theErrorTypeenum) covers both cases without losing the enum constraint.Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/api/src/routes/actors/build_default.ts#L33
Add
run-input-body-not-valid-jsontoErrorTypeenumFiles:
apify-api/openapi/components/schemas/common/ErrorType.yaml:301Error:
WARN Response OpenAPI validation error {"url":"/v2/schedules","method":"POST","statusCode":400,"errors":[{"message":"must be equal to one of the allowed values: 3d-secure-auth-failed, access-right-already-exists, action-not-foun...[truncated]","errorCode":"enum.openapi.validation","path":"/response/error/type"}]}Root cause: When a Schedule is created with a non-JSON
runInput.body, the API throwserrors.scheduling.runInputBodyNotValidJson()with typerun-input-body-not-valid-json, which was missing from theErrorTypeenum.Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/packages/errors/src/errors/scheduling.ts#L63
Add
full-permission-actor-not-approvedtoErrorTypeenumFiles:
apify-api/openapi/components/schemas/common/ErrorType.yaml:129Error:
WARN Response OpenAPI validation error {"url":"/v2/acts/{actorId}/runs","method":"POST","statusCode":403,"errors":[{"message":"must be equal to one of the allowed values: 3d-secure-auth-failed, access-right-already-exists, action-not-foun...[truncated]","errorCode":"enum.openapi.validation","path":"/response/error/type"}]}Root cause: Running a public full-permission Actor without prior approval throws
errors.actor.fullPermissionActorNotApprovedwith typefull-permission-actor-not-approved, which was missing from theErrorTypeenum.Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/packages/errors/src/errors/actor.ts#L58
Refactoring
None.
Issues
Partially implements: #2286
Unfixed errors
False positives
Nullable
date-timefields trigger validator cascade ontaggedBuilds,lastDispatch, schedule run timestamps, buildfinishedAt, and webhook dispatchcalls[].startedAt/finishedAtError:
WARN Response OpenAPI validation error {"url":"/v2/acts/{actorId}","method":"GET","statusCode":200,"errors":[{"message":"must be string,null","errorCode":"type.openapi.validation","path":"/response/data/taggedBuilds/latest/finishedAt"}, ...]}(and equivalents on/v2/webhooks/{id},/v2/webhook-dispatches/{id},/v2/actor-builds/{id}/abort,/v2/schedules,/v2/schedules/{id})Root cause: The fields are correctly declared as
type: [string, "null"]withformat: date-time. The validator (express-openapi-validator/Ajv) does not honor multi-type definitions for formatted strings and reportsmust be string,nullfor validnullvalues. PerCLAUDE.md, this is a documented validator false positive. The cascadingmust match a schema in anyOf/must be nullerrors at the parent paths (taggedBuilds.latest,taggedBuilds,lastDispatch) are downstream effects of the same root cause: when theTaggedBuildInfo/ExampleWebhookDispatchbranch fails on a (false)finishedAtmismatch, the validator then tries thenullbranch, which fails because the value is an object.Reference: https://github.com/apify/apify-core/tree/57a2fbf9848fa2f64043cdb855a7b95c2a6caad6/src/api/src/lib/api_server.ts
Out of scope errors
Missing endpoints
actor-tasks/{taskId}/runs/last/{abort,reboot,metamorph}Error:
WARN Request OpenAPI validation error {"url":"/v2/actor-tasks/{taskId}/runs/last/abort","method":"POST","errors":[{"message":"not found","path":"/actor-runs/{runId}/abort/"}]}(andreboot,metamorphvariants, plus/v2/acts/{actorId}/runs/last/reboot)Root cause: These endpoints exist in
apify-corebut are not yet defined in the OpenAPI spec. PerCLAUDE.md, adding new endpoints is out of scope for this autofix workflow.Intentional malformed-input request validations
Error: Multiple
WARN Request OpenAPI validation errorlines forbody/generalAccessenum/type,bodymust be object/oneOfonPOST /v2/datasets/{id}/items,body/handledAtmust match format date-time,headers/content-encodingenum,query/startedAfter/startedBeforemust match format date-time,query/method/query/statusUnknown query parameter,query/filterenum,OPTIONS method not allowedon/v2/users/test-user,XXX method not allowedon/v2/browser-info,unsupported media type application/x-www-form-urlencodedonPOST /v2/acts,unsupported media type text/plainonPOST /v2/tools/encode-and-sign,body must be arrayonDELETE /v2/request-queues/{id}/requests/batch,must have required property 'id'/'uniqueKey'on request-queue requests,body/eventTypes/0enum onPOST /v2/webhooks,body/options/timeoutSecsandbody/inputanyOfonactor-tasksPOST/PUT,must have required property 'actId'onPOST /v2/actor-tasks.Root cause: All of these are followed by
SFAILlog lines showing the API correctly rejects the malformed request. The integration tests deliberately send invalid input to verify error handling. PerCLAUDE.md, request-validation errors caused by intentional bad-input tests are not spec issues and must not be "fixed".Generated by Claude Code