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

JSON example no longer generated for object form-data properties #7268

Closed
bfreuden opened this issue May 14, 2021 · 4 comments · Fixed by #7355
Closed

JSON example no longer generated for object form-data properties #7268

bfreuden opened this issue May 14, 2021 · 4 comments · Fixed by #7355

Comments

@bfreuden
Copy link

Q&A

  • OS: Ubuntu 18.04
  • Browser: Firefox
  • Version: 88.0
  • Method of installation: snap
  • Swagger-UI version: 3.48.0
  • Swagger/OpenAPI version:OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

---
openapi: 3.0.2
info:
  title: Conversion API doc
  description: Conversion API documentation
  version: '1.0'
tags:
- name: converters
  description: Converters
paths:
  "/convert/tutu":
    post:
      summary: ''
      tags:
      - converters
      operationId: tutuconvert
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                parameters:
                  "$ref": "#/components/schemas/TutuConverterTutuParameters"
      responses:
        '200':
          description: List of converted documents
          application/json:
            schema:
              type: array
              items:
                "$ref": "#/components/schemas/Document"
        '500':
          description: Error
      description: ''
components:
  schemas:
    Document:
      required:
      - text
      type: object
      properties:
        text:
          type: string
    TutuConverterTutuParameters:
      type: object
      properties:
        stuff:
          type: string

Swagger-UI configuration options:

Nothing special here, I'm using the "dist package" as is.

Describe the bug you're encountering

The JSON example of object form-data properties is no longer generated.

To reproduce...

Steps to reproduce the behavior:

  1. Click on the /convert/tutu endpoint
  2. Click on the "try it out" button
  3. The parameters field has no generated JSON example

Screenshot:
swagger-ui-ko

Expected behavior

In swagger-ui 3.41.0 we used to have a json example for object properties of form-data bodies:
swagger-ui-ok

Additional context or thoughts

It might be something incorrect in my spec though: maybe swagger-ui 3.42.0 is expecting something 3.41.0 was not expecting.
If it is the case I apologize for the bug report and I would be grateful for any hint that might help me correcting my spec.

If not I have narrowed the regression down to the following commit:

commit 8ed6c34958ddb333473f953969e69a23d0a419b3
Author: <hidden>
Date:   Wed Feb 3 21:04:12 2021 +0100

    feat: sample-gen mulit and form media-type (#6874)
    
    * application/x-www-form-urlencoded || **multipart/** initial value should rely on sample gen

So it seems to be related to this pull request:
#6874

Here is what I did to support my claim:

# checkout source code before the commit (somewhere between  3.41.0 and  3.42.0)
git checkout 23323bbbff2235c8b3ccd7d60a345dcb8c31706b
# build
npm install
npm run build
# use the swagger-ui/dist to perform the OK screenshot above
# clean 
git checkout -f ; git clean -fd
git checkout master
# checkout source code at the immediate following commit 
git checkout 8ed6c34958ddb333473f953969e69a23d0a419b3
# build
npm run build
# use the swagger-ui/dist to perform the KO screenshot above
@tim-lai
Copy link
Contributor

tim-lai commented Jun 10, 2021

@bfreuden Here is a fixed definition excerpt that works for me in https://editor.swagger.io.

      responses:
        '200':
          description: List of converted documents
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Document"

@tim-lai
Copy link
Contributor

tim-lai commented Jun 10, 2021

@bfreuden Please ignore my previous comment, as it doesn't address the issue. Well, the definition fix is valid, just not the sample gen.

      responses:
        '200':
          description: List of converted documents
          content: 
            application/json:
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/Document"

@bfreuden
Copy link
Author

@tim-lai No problem! Thank you for having taken a look at the issue ^^

@bfreuden
Copy link
Author

bfreuden commented Jun 21, 2021

@tim-lai Thank you for fixing the issue! I've just tested the latest master branch and it is working very well :)

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

Successfully merging a pull request may close this issue.

3 participants