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

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

Open
ashishjullia opened this issue Aug 8, 2023 · 6 comments

Comments

@ashishjullia
Copy link

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!"
        };
    }
}

It shows:
image

image

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

@G4brym
Copy link
Member

G4brym commented Aug 9, 2023

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

@ashishjullia
Copy link
Author

@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

@G4brym
Copy link
Member

G4brym commented Aug 9, 2023

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

@ExSidius
Copy link

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

Would a PR be helpful?

@G4brym
Copy link
Member

G4brym commented Aug 18, 2023

@ExSidius what request bodies types are you looking for?

@henrytoone
Copy link
Contributor

henrytoone commented Sep 15, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants