Skip to content

Commit 0081aa8

Browse files
authored
docs(openapi): Add generic 4xx errors to OpenAPI spec (#2328)
## Summary - Add Agents directives about 4xx errors in the OpenAPI spec - Add generic 4xx errors where suitable based on the directives. ## Motivation - Solve OpenAPI validation errors for missing error responses ## Issues Partially implements: #2286
1 parent 808b78a commit 0081aa8

File tree

75 files changed

+1110
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1110
-32
lines changed

AGENTS.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,21 @@ Add code samples by creating files in `apify-api/openapi/code_samples/{javascrip
5555

5656
- Prefer re-use of existing objects via `$ref` over duplication. Reusable components can be found in `/openapi/components`.
5757
- Components most suitable for re-use are:
58-
- Request parameters and path parameters defined in `/openapi/components/parameters`
59-
- Request/response schemas defined in `/openapi/components/schemas`
60-
- Explicit non-automatic examples defined in `/openapi/components/examples`
58+
- Request parameters and path parameters defined in `/openapi/components/parameters`
59+
- Request/response schemas defined in `/openapi/components/schemas`
60+
- Explicit non-automatic examples defined in `/openapi/components/examples`
6161
- When changing files in `/openapi/paths` look for opportunities to extract shared duplicate objects into re-usable components saved in `/openapi/components`.
6262
- When adding new endpoints, check first if any existing path is similar and if yes, try to re-use same components. If by adding new paths you create new duplication, try to extract it into a new components and reference it instead.
6363
- Prefer automatically generated examples from schema over explicit examples.
6464

65+
#### Error responses
66+
- Re-use schemas for error responses defined in `/apify-api/openapi/components/responses`
67+
- Each endpoint should have at least following error responses: 400 (Bad Request), 405 (Method Not Allowed), 429 (Too Many Requests).
68+
- Endpoints that define `security: []` do not use any authentication.
69+
- Each endpoint that uses authentication should have at least following error responses: 401 (Unauthorized), 403 (Forbidden).
70+
- Each endpoint that has `runs/last` in its path or that has any ID related parameter (for example `actorId`, `buildId`, `runId`, `datasetId` and so on) should have at least one 404 (Not Found) error.
71+
- Each endpoint that has `requestBody` should have at least following error responses: 413 (Payload Too Large), 415 (Unsupported Media Type).
72+
6573
### Theme system
6674

6775
Uses `@apify/docs-theme` package - a shared theme across all 6+ documentation repos. Don't modify theme files directly. Changes to the theme propagate via CI to all projects.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: Method not allowed.
2+
content:
3+
application/json:
4+
schema:
5+
$ref: ../schemas/common/ErrorResponse.yaml
6+
example:
7+
error:
8+
type: method-not-allowed
9+
message: "This API end-point can only be accessed using the following HTTP methods: OPTIONS,GET"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: Payload too large - the request body exceeds the size limit.
2+
content:
3+
application/json:
4+
schema:
5+
$ref: ../schemas/common/ErrorResponse.yaml
6+
example:
7+
error:
8+
type: request-too-large
9+
message: "The POST payload is too large (limit: 9437184 bytes, actual length: 10485760 bytes)."
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: Too many requests - rate limit exceeded.
2+
content:
3+
application/json:
4+
schema:
5+
$ref: ../schemas/common/ErrorResponse.yaml
6+
example:
7+
error:
8+
type: rate-limit-exceeded
9+
message: You have exceeded the rate limit. Please try again later.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: Unsupported media type - the Content-Encoding of the request is not supported.
2+
content:
3+
application/json:
4+
schema:
5+
$ref: ../schemas/common/ErrorResponse.yaml
6+
example:
7+
error:
8+
type: unsupported-content-encoding
9+
message: Content-Encoding "bla" is not supported.

apify-api/openapi/paths/actor-builds/actor-builds.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ get:
3232
$ref: ../../components/schemas/actor-builds/ListOfBuildsResponse.yaml
3333
"400":
3434
$ref: ../../components/responses/BadRequest.yaml
35+
"401":
36+
$ref: ../../components/responses/Unauthorized.yaml
3537
"403":
3638
$ref: ../../components/responses/Forbidden.yaml
39+
"405":
40+
$ref: ../../components/responses/MethodNotAllowed.yaml
41+
"429":
42+
$ref: ../../components/responses/TooManyRequests.yaml
3743
deprecated: false

apify-api/openapi/paths/actor-builds/actor-builds@{buildId}.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ get:
3838
application/json:
3939
schema:
4040
$ref: "../../components/schemas/common/errors/ActorErrors.yaml#/ActorBuildNotFoundError"
41+
"405":
42+
$ref: ../../components/responses/MethodNotAllowed.yaml
43+
"429":
44+
$ref: ../../components/responses/TooManyRequests.yaml
4145
deprecated: false
4246
x-legacy-doc-urls:
4347
- https://docs.apify.com/api/v2#/reference/actor-builds/build-object/get-build
@@ -71,12 +75,18 @@ delete:
7175
$ref: ../../components/responses/BadRequest.yaml
7276
"401":
7377
$ref: ../../components/responses/Unauthorized.yaml
78+
"403":
79+
$ref: ../../components/responses/Forbidden.yaml
7480
"404":
7581
description: Not found - the requested resource was not found.
7682
content:
7783
application/json:
7884
schema:
7985
$ref: "../../components/schemas/common/errors/ActorErrors.yaml#/ActorBuildNotFoundError"
86+
"405":
87+
$ref: ../../components/responses/MethodNotAllowed.yaml
88+
"429":
89+
$ref: ../../components/responses/TooManyRequests.yaml
8090
deprecated: false
8191
x-legacy-doc-urls:
8292
- https://docs.apify.com/api/v2#/reference/actor-builds/delete-build/delete-build

apify-api/openapi/paths/actor-builds/actor-builds@{buildId}@abort.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ post:
3232
application/json:
3333
schema:
3434
$ref: "../../components/schemas/common/errors/ActorErrors.yaml#/ActorBuildNotFoundError"
35+
"405":
36+
$ref: ../../components/responses/MethodNotAllowed.yaml
37+
"429":
38+
$ref: ../../components/responses/TooManyRequests.yaml
3539
deprecated: false
3640
x-legacy-doc-urls:
3741
- https://docs.apify.com/api/v2#/reference/actor-builds/abort-build/abort-build

apify-api/openapi/paths/actor-builds/actor-builds@{buildId}@log.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ get:
2727
2017-07-14T06:00:49.752Z Some useful debug information follows.
2828
"400":
2929
$ref: ../../components/responses/BadRequest.yaml
30+
"401":
31+
$ref: ../../components/responses/Unauthorized.yaml
32+
"403":
33+
$ref: ../../components/responses/Forbidden.yaml
3034
"404":
3135
description: Not found - the requested resource was not found.
3236
content:
3337
application/json:
3438
schema:
3539
$ref: "../../components/schemas/common/errors/ActorErrors.yaml#/ActorBuildNotFoundError"
40+
"405":
41+
$ref: ../../components/responses/MethodNotAllowed.yaml
42+
"429":
43+
$ref: ../../components/responses/TooManyRequests.yaml
3644
deprecated: false
3745
x-legacy-doc-urls:
3846
- https://docs.apify.com/api/v2#/reference/actor-builds/build-log/get-log

apify-api/openapi/paths/actor-builds/actor-builds@{buildId}@openapi.json.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ get:
3737
application/json:
3838
schema:
3939
$ref: "../../components/schemas/common/errors/ActorErrors.yaml#/ActorBuildNotFoundError"
40+
"405":
41+
$ref: ../../components/responses/MethodNotAllowed.yaml
42+
"429":
43+
$ref: ../../components/responses/TooManyRequests.yaml
4044
x-js-parent: BuildClient
4145
x-js-name: getOpenApiDefinition
4246
x-js-doc-url: https://docs.apify.com/api/client/js/reference/class/BuildClient#getOpenApiDefinition

0 commit comments

Comments
 (0)