Skip to content

Instantly share code, notes, and snippets.

@yangyer
Last active July 17, 2024 16:40
Show Gist options
  • Save yangyer/e35cefe9c69f6f3ffbf2c0a94e5e4dee to your computer and use it in GitHub Desktop.
Save yangyer/e35cefe9c69f6f3ffbf2c0a94e5e4dee to your computer and use it in GitHub Desktop.
openapi: 3.0.3
info:
title: Risk Review
description: |-
description goes here ....
termsOfService: http://swagger.io/terms/
contact:
email: dev@availcarsharing.com
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: https://risk-review.goavail.io/api
tags:
- name: Risk review
description: Order new risk reviews and get the status of a previous order.
- name: Webhooks
description: >-
Webhooks provides the ability to subscribe to key events and receive realtime updates from the risk review system.
paths:
/v1/risk-review:
post:
tags:
- Risk review
summary: Order a new risk review
description: >-
The resulting response will return a `riskReviewOrderId`. The `riskReviewOrderId` acts as a
unique primary id on subsequent risk review calls.
operationId: createRiskReview
requestBody:
description: Payload use to create a Risk Review
content:
application/json:
schema:
$ref: '#/components/schemas/RequestRiskReview'
required: true
responses:
'200':
description: Successful creation of a risk review order.
content:
application/json:
schema:
$ref: '#/components/schemas/RequestRiskReviewResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestError'
example: |-
{
"name": "BadRequestError",
"message": "A risk review with status 'pending' already exists for the 'reservationId'.",
"code": "BAD_REQUEST",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
'401':
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
security:
- api_key: []
/v1/risk-review/{riskReviewOrderId}:
get:
tags:
- Risk review
summary: Get the status of a previously created risk review order.
description: >-
Provided a `riskReviewOrderId` will return the status of the previous order
risk review. The status can be any of the following:
* `fail` - The risk review checks found found risky indicators
* `pass` - The risk review checks did not find any risky indicators
* `pending` - The risk review is still in progress
* `conditional-pass` - A optional check failed and require manual review
operationId: patchRiskReview
parameters:
- name: riskReviewOrderId
in: path
description: >-
The unqiue id provided during risk review order creation.
required: true
schema:
type: string
responses:
'200':
description: Successfully retrieve order status
content:
application/json:
schema:
$ref: '#/components/schemas/RequestRiskReviewResponse'
'400':
description: Bad Request Error
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestError'
example: |-
{
"name": "BadRequestError",
"message": "The 'riskReviewOrderId' provided is invalid.",
"code": "BAD_REQUEST",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
'401':
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
'404':
description: Not Found Error
content:
application/json:
schema:
$ref: '#/components/schemas/NotFoundError'
example: |-
{
"name": "NotFoundError",
"message": "Risk review order can not be found for id '65381cc1784b770f9d51c4b7'",
"code": "RESOURCE_NOT_FOUND",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
/v1/webhooks:
post:
tags:
- Webhooks
summary: Create a Subscription
description: >-
Subscribe a callbackUrl to one ore more webhook event(s).
**Events**
* `risk-review:started`
* `risk-review:completed`
* `risk-review:timedout`
operationId: registerWebhook
requestBody:
description: >-
Payload use to subscribe to event(s)
- `callbackUrl` (string, required): The callback URL where event notifications will be sent.
- `events` (array, string, required): The array of event names to recieve notifacations on.
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookRegistrationRequest'
required: true
responses:
'201':
description: Successful registration
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookRegistrationResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestError'
example: |-
{
"name": "BadRequestError",
"message": "Cannot register a webhook with the same callbackUrl.",
"code": "BAD_REQUEST",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
'401':
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
security:
- api_key: []
get:
tags:
- Webhooks
summary: Get webhooks
description: List all registered webhooks.
operationId: listWebhooks
responses:
'200':
description: The response will return all registered webhooks associated with the api key provided.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Webhook'
example:
- subscriptionId: 6377d59b0087cb78b62087ed
createdDate: 2024-07-16T18:41:29.854Z
callbackUrl: https://someHost/webhook/risk-review-notification
events: ['risk-review:started', 'risk-review:completd']
- subscriptionId: 2987d59b0087cb49d22087ab
callbackUrl: https://someHost/webhook/risk-review-notification/errors
createdDate: 2024-07-16T18:41:29.854Z
events: ['risk-review:error', 'risk-review:timedout']
'401':
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
security:
- api_key: []
/v1/webhooks/{subscriptionId}:
patch:
tags:
- Webhooks
summary: Update the callbackUrl or rigister/unregister to events.
operationId: updateWebhook
parameters:
- name: subscriptionId
in: path
description: The unqiue id provided upon succesfully webhook creation.
required: true
schema:
type: string
requestBody:
description: >-
Webhook update request payload. At least one of the following attribute is required to update.
* `callbackUrl` (string, optional) : The callback URL where event notifications will be sent
* `disableEvents` (array, string, optional) : Events provided here will be removed from the list of subscribed events for the associated callbackUrl.
* `enableEvents` (araray, string, optional) : Events provided here will be added to the list of subscribed events for the associated callbackUrl
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookUpdateRequest'
examples:
Update callbackUrl:
value: |-
{
"callbackUrl": "https://someHost/webhook/risk-review-notification/success"
}
Unsubscribe to events:
value: |-
{
"disableEvents": ["risk-review:error"]
}
Subscribe to events:
value: |-
{
"enableEvents": ["risk-review:completed"]
}
responses:
'200':
description: Webhook succussfuly updated
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookUpdateResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestError'
examples:
Send empty payload:
value: |-
{
"name": "BadRequestError",
"message": "One of the following is required, 'callbackUrl', 'disableEvents', or 'enableEvents'.",
"code": "BAD_REQUEST",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
Send invalid event(s):
value: |-
{
"name": "BadRequestError",
"message": "The value 'risk-review:updated' is not a valid event.",
"code": "BAD_REQUEST",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
'404':
description: Webhook not found for the provided id.
'401':
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
security:
- api_key: []
delete:
tags:
- Webhooks
summary: Register web hooks to get risk-review completion data
operationId: unRegisterWebhook
parameters:
- name: subscriptionId
in: path
description: 'The reference id provided during risk-review creation. '
required: true
schema:
type: string
responses:
'200':
description: Successful registration
content:
application/json:
schema:
$ref: '#/components/schemas/WebhookUnRegisterResponse'
'404':
description: Not Found Error
content:
application/json:
schema:
$ref: '#/components/schemas/NotFoundError'
example: |-
{
"name": "NotFoundError",
"message": "No webhook subscription found for subscriptionId '65381cc1784b770f9d51c4b7'",
"code": "RESOURCE_NOT_FOUND",
"status": 404,
"errorId": "01J2WEHHY6DF50WRF3H0V25ZHF"
}
'401':
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
security:
- api_key: []
components:
schemas:
Reservation:
type: object
required:
- reservationId
- customerId
- customerFirstName
- customerLastName
- customerPhoneNumber
- customerEmail
- customerIpAddress
properties:
reservationId:
type: string
example: reservation-abc-123
customerId:
type: string
example: customer-abc-123
customerFirstName:
type: string
example: Joe
customerLastName:
type: string
example: Doe
customerPhoneNumber:
type: string
example: 123-123-1234
customerEmail:
type: string
example: john.doe@gmail.com
requestIpAddress:
type: string
example: 192.158.1.38
RequestRiskReviewResponse:
type: object
properties:
riskReviewOrderId:
type: string
example: 6377d59b0087cb78b62087ed
status:
type: string
enum:
- pending
- pass
- failed
- conditional-pass
example: pending
createdDate:
type: string
format: Date
example: 2024-07-16T18:41:29.854Z
reservation:
allOf:
- $ref: '#/components/schemas/Reservation'
RequestRiskReview:
$ref: '#/components/schemas/Reservation'
WebhookRegistrationRequest:
type: object
properties:
callbackUrl:
type: string
events:
$ref: '#/components/schemas/WebhookEvent'
Webhook:
type: object
properties:
subscriptionId:
type: string
callbackUrl:
type: string
createdDate:
type: string
format: Date
events:
$ref: '#/components/schemas/WebhookEvent'
WebhookRegistrationResponse:
$ref: "#/components/schemas/Webhook"
WebhookUnRegisterResponse:
allOf:
- $ref: "#/components/schemas/Webhook"
properties:
unregisteredDate:
type: string
format: Date
WebhookUpdateRequest:
type: object
properties:
callbackUrl:
type: string
disableEvents:
$ref: '#/components/schemas/WebhookEvent'
enableEvents:
$ref: '#/components/schemas/WebhookEvent'
WebhookUpdateResponse:
$ref: '#/components/schemas/Webhook'
WebhookEvent:
type: array
items:
type: string
enum:
- risk-review:started
- risk-review:completed
- risk-review:timedout
- risk-review:error
description: >
Events
* `risk-review:started` - When risk review starts
* `risk-review:completed` - When risk review completes (pass, fail)
* `risk-review:timedout` - When risk review timed-out
* `risk-review:error` - When risk review error
BadRequestError:
properties:
name:
type: string
example: BadRequestError
message:
type: string
example: Your request contains errors
code:
type: string
example: BAD_REQUEST
status:
type: number
format: double
example: 400
errorId:
type: string
example: 01J2WEHHY6DF50WRF3H0V25ZHF
required:
- name
- message
- code
- status
- errorId
type: object
UnauthorizedError:
description: >-
Unauthorized error
**Suggestions**
* Ensure that `x-api-key` header key is provided in the request.
* Ensure that the api-key is a valid key for the environment.
properties:
name:
type: string
example: UnauthorizedErro'
message:
type: string
example: You are not authorized to perform this action
code:
type: string
example: UNAUTHORIZED_REQUEST
status:
type: number
format: double
example: 401
errorId:
type: string
example: 01J2WEHHY6DF50WRF3H0V25ZHF
required:
- name
- message
- code
- status
- errorId
type: object
NotFoundError:
properties:
name:
type: string
example: NotFoundError
message:
type: string
example: The resource you're looking could not be found
code:
type: string
example: RESOURCE_NOT_FOUND
status:
type: number
format: double
example: 404
errorId:
type: string
example: 01J2WEHHY6DF50WRF3H0V25ZHF
required:
- name
- message
- code
- status
- errorId
type: object
securitySchemes:
api_key:
type: apiKey
name: x-api-key
in: header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment