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

Set example values of bodyRequest, or any field, without setting default? #149

Open
carafelix opened this issue May 7, 2024 · 1 comment

Comments

@carafelix
Copy link

carafelix commented May 7, 2024

For Swagger UI it's really neat to have example to run trough your API, as of right now this allows to make use of them via the .default() method, is there already any way of setting the example field specifically, the new BodyRequest does not support it. Could it be implement?

@carafelix carafelix changed the title set example values without setting default? Set example values of bodyRequest without setting default? May 8, 2024
@carafelix carafelix changed the title Set example values of bodyRequest without setting default? Set example values of bodyRequest, or any field, without setting default? May 8, 2024
@G4brym
Copy link
Member

G4brym commented May 23, 2024

Hello, you should be able to set examples like this:

export class ToDoCreate extends OpenAPIRoute {
  static schema = {
    tags: ['ToDo'],
    summary: 'Create a ToDo',
    requestBody: {
      description: new Str({required: false, example: 'new description'}),
      name: z.string().openapi({example: 'new name'}),
    }
  }

  async handle(
    request: Request,
    env: any,
    context: any,
    data: any
  ) {
    const newToDo = data.body
    // ...
  }
}

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

2 participants