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

Example request body for multipart/form-data POST isn't used by "Try it out" #10248

Open
LincolnPuzey opened this issue Jan 2, 2025 · 2 comments

Comments

@LincolnPuzey
Copy link

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.1.0
info:
 title: Test
 version: '0.0.1'
paths:
 /example:
   post:
     summary: Example endpoint
     operationId: example_endpoint
     parameters: []
     requestBody:
       required: true
       content:
         multipart/form-data:
           schema:
             type: object
             required:
               - required_field
             properties:
               required_field:
                 type: string
                 minLength: 1
               optional_field:
                 type: string
             example:
               required_field: foo
     responses:
       "200":
         description: OK

Swagger-UI configuration options:

SwaggerUI({
 // I am using https://editor-next.swagger.io/
})

Is your feature request related to a problem?

Clicking the "Try it out" button for my example endpoint gives the following initial form state:
image

Instead of using the example provided.

Describe the solution you'd like

I would like the initial form state to be the following
image

(required_field="foo" and optional_field omitted) to reflect the example given.

Describe alternatives you've considered

I've played around with different ways of specifying the request body and the example. Nothing seems to produce this result in the swagger UI.

@glowcloud
Copy link
Contributor

Hi @LincolnPuzey

It looks like for multipart/form-data we don't take into account the parent schema example when generating samples for the properties. There is a workaround for this by specifying an example for each of the properties separately instead of for the entire schema:

 properties:
   required_field:
     type: string
     minLength: 1
     example: foo
   optional_field:
     type: string
     example: ""

@LincolnPuzey
Copy link
Author

@glowcloud Thanks for your response! I'll try out that workaround.

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

No branches or pull requests

3 participants