chanfana icon indicating copy to clipboard operation
chanfana copied to clipboard

When using `contentType` for `requestBody` the it is shown Example values (default)

Open ashishjullia opened this issue 2 years ago • 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: "[email protected]"
            }),
            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!"
        };
    }
}

It shows: image

image

I know I'm missing something but how to correctly pass this contentType and where?

ashishjullia avatar Aug 08 '23 21:08 ashishjullia

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 avatar Aug 09 '23 09:08 G4brym

@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

ashishjullia avatar Aug 09 '23 18:08 ashishjullia

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

G4brym avatar Aug 09 '23 19:08 G4brym

@ashishjullia do you know where on the roadmap support for other request bodies is?

Would a PR be helpful?

ExSidius avatar Aug 18 '23 00:08 ExSidius

@ExSidius what request bodies types are you looking for?

G4brym avatar Aug 18 '23 08:08 G4brym

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

henrytoone avatar Sep 15 '23 14:09 henrytoone