When using `contentType` for `requestBody` the it is shown Example values (default)
ashishjullia opened this issue · 6 comments
When using the following:
const SignUpResponse = {
message: "User Added!"
}
export class SignUp extends OpenAPIRoute {
static schema = {
tags: ["Users"],
summary: "User Sign Up",
requestBody: {
contentType: 'text/plain',
firstname: new Str({
description: "User Firstname",
required: true,
example: "Ashish"
}),
lastname: new Str({
description: "User Lastname",
required: true,
example: "Jullia"
}),
email: new Str({
description: "User Email",
required: true,
example: "username@example.com"
}),
password: new Str({
description: "User Password",
required: true,
example: "As@121212121212"
})
},
responses: {
"200": {
contentType: 'application/json',
schema: {
Response: SignUpResponse,
},
},
},
};
async handle(
request,
env,
context,
data
) {
// Retrieve the validated slug
const { firstname, lastname, email, password } = data.body
// console.log(isValidEmail(email))
return {
message: "User Added!"
};
}
}
I know I'm missing something but how to correctly pass this contentType
and where?
Hey there, currently request bodies other than application/json
are not supported in itty-router-openapi
can you explain what are you trying to do here, so i can suggest a different approach?
When using conntent type application/json
you don't need to set that parameter, just define your schema
@G4brym
Thanks for the information but I just wanted to understand whether there is a way or not for example I wanted to change the contentType to any of these:
text/plain; charset=utf-8
application/json
application/vnd.github+json
application/vnd.github.v3+json
application/vnd.github.v3.raw+json
application/vnd.github.v3.text+json
application/vnd.github.v3.html+json
application/vnd.github.v3.full+json
application/vnd.github.v3.diff
application/vnd.github.v3.patch
isn't application/vnd.github.v3.html+json
or any other that you've listed there just json under the hood?
if yes you can still use itty-router-openapi
without a clear example of what you are trying to do, i cannot help you
@ashishjullia do you know where on the roadmap support for other request bodies is?
Would a PR be helpful?
I think as an example the image
or binary
content type could be good for uploading images (to an R2 bucket for example)
Or even the formData
type