ripRigPanic
ripRigPanic
CDCloudflare Developers
Created by ripRigPanic on 2/11/2024 in #workers-help
Specifying multiple content-types in itty-router-openapi responses
I'm looking to return response content-type conditional on request accept header. OpenAPI spec has an example https://swagger.io/docs/specification/describing-responses/
get:
summary: Get all users
responses:
'200':
description: A list of users
content:
application/json:
schema:
$ref: '#/components/schemas/ArrayOfUsers'
application/xml:
schema:
$ref: '#/components/schemas/ArrayOfUsers'
text/plain:
schema:
type: string
get:
summary: Get all users
responses:
'200':
description: A list of users
content:
application/json:
schema:
$ref: '#/components/schemas/ArrayOfUsers'
application/xml:
schema:
$ref: '#/components/schemas/ArrayOfUsers'
text/plain:
schema:
type: string
but I can't find a way to accomplish that with itty-router-openapi response format. I tried something like
responses: {
'200': {
content: {
'application/json': {
schema: new Obj({
type: new Str({ description: "the type of object", default: 'foo', example: 'foo' }),
})
},
'text/plain': {
schema: { type: 'string' }
},
},
},
responses: {
'200': {
content: {
'application/json': {
schema: new Obj({
type: new Str({ description: "the type of object", default: 'foo', example: 'foo' }),
})
},
'text/plain': {
schema: { type: 'string' }
},
},
},
but it seems that the object with the status code key must satisfy
export interface ResponseSchema {
description?: string;
schema?: Record<any, any>;
contentType?: string;
}
export interface ResponseSchema {
description?: string;
schema?: Record<any, any>;
contentType?: string;
}
Is there a way to specify multiple content types there?
1 replies
CDCloudflare Developers
Created by ripRigPanic on 2/5/2024 in #workers-help
Workers with Postgres - recommended ways?
There are a number of ways to connect to Postgres from workers. I wonder what are pros and cons of each. 1. https://developers.cloudflare.com/hyperdrive/ 2. https://developers.cloudflare.com/workers/tutorials/postgres/ - requires old node_compat mode 3. Data API (for AWS RDS serverless Aurora v1 (and v2 now?)) - uses HTTP. I believe v1 has some scaling limitations and at least some of which are addressed in v2. In our particular case we are using RDS for prod and staging/dev.
2 replies