Skip to content
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

feat: add gnap error response schema to spec #519

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
76 changes: 76 additions & 0 deletions openapi/auth-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,22 @@ paths:
uri: 'https://auth.rafiki.money/continue/4CF492MLVMSW9MKMXKHQ'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
requestBody:
content:
application/json:
Expand Down Expand Up @@ -198,10 +210,22 @@ paths:
wait: 30
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
requestBody:
content:
application/json:
Expand All @@ -228,10 +252,22 @@ paths:
description: No Content
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
description: Cancel a grant request or delete a grant client side.
tags:
- grant
Expand Down Expand Up @@ -279,10 +315,22 @@ paths:
assetScale: 2
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
description: Management endpoint to rotate access token.
tags:
- token
Expand All @@ -295,8 +343,16 @@ paths:
description: No Content
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/gnap-error'
tags:
- token
components:
Expand Down Expand Up @@ -532,6 +588,26 @@ components:
- debitAmount
- required:
- receiveAmount
gnap-error:
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think of having separate objects per error, and then using specific ones per-response?
e.g. we wouldn't have too_fast in a normal grant request, just for grant continuation.

Maybe that is too specific, but curious to hear your opinion

Copy link
Contributor Author

@njlie njlie Nov 14, 2024

Choose a reason for hiding this comment

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

I considered that, but it felt at times overly granular to have a schema for an error that was only referenced once - too_fast is a pretty good example of that, as it's only thrown by the grant continuation endpoint.

In hindsight though, I think it would be more useful to use the specific ones per-response. Biggest reason to me being that these routes may throw the same http code for different reasons, in particular 401 could be thrown by the signature middleware or the actual business logic...

type: object
properties:
error:
type: object
properties:
description:
type: string
code:
type: string
enum:
- invalid_request
- invalid_client
- invalid_interaction
- invalid_rotation
- invalid_continuation
- user_denied
- request_denied
- unknown_interaction
- too_fast
Copy link

@oana-lolea oana-lolea Nov 14, 2024

Choose a reason for hiding this comment

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

I think too_fast shouldn't be indented, because in the generated file "unknown_interaction - too_fast" should be two separated values.

securitySchemes:
GNAP:
name: Authorization
Expand Down
98 changes: 84 additions & 14 deletions packages/open-payments/src/openapi/generated/auth-server-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ export interface components {
receiveAmount?: external["schemas.yaml"]["components"]["schemas"]["amount"];
interval?: components["schemas"]["interval"];
};
"gnap-error": {
error?: {
description?: string;
code?:
| "invalid_request"
| "invalid_client"
| "invalid_interaction"
| "invalid_rotation"
| "invalid_continuation"
| "user_denied"
| "request_denied"
| "unknown_interaction - too_fast";
};
};
};
}

Expand All @@ -195,11 +209,23 @@ export interface operations {
};
};
/** Bad Request */
400: unknown;
400: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Unauthorized */
401: unknown;
401: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Internal Server Error */
500: unknown;
500: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
};
requestBody: {
content: {
Expand Down Expand Up @@ -231,11 +257,23 @@ export interface operations {
};
};
/** Bad Request */
400: unknown;
400: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Unauthorized */
401: unknown;
401: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Not Found */
404: unknown;
404: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
};
requestBody: {
content: {
Expand All @@ -260,11 +298,23 @@ export interface operations {
/** No Content */
204: never;
/** Bad Request */
400: unknown;
400: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Unauthorized */
401: unknown;
401: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Not Found */
404: unknown;
404: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
};
};
/** Management endpoint to rotate access token. */
Expand All @@ -284,11 +334,23 @@ export interface operations {
};
};
/** Bad Request */
400: unknown;
400: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Unauthorized */
401: unknown;
401: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Not Found */
404: unknown;
404: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
};
};
/** Management endpoint to revoke access token. */
Expand All @@ -302,9 +364,17 @@ export interface operations {
/** No Content */
204: never;
/** Bad Request */
400: unknown;
400: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
/** Unauthorized */
401: unknown;
401: {
content: {
"application/json": components["schemas"]["gnap-error"];
};
};
};
};
}
Expand Down
Loading