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

Display schema for mutipart/form-data object properties #9756

Open
AlexisAmd opened this issue Mar 27, 2024 · 4 comments · May be fixed by #10166
Open

Display schema for mutipart/form-data object properties #9756

AlexisAmd opened this issue Mar 27, 2024 · 4 comments · May be fixed by #10166

Comments

@AlexisAmd
Copy link

AlexisAmd commented Mar 27, 2024

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.3
info:
 title: Example app
 description: This is an example
 version: 1.0.0
servers:
 - url: https://dev.app.com/appApplicationName
   description: DEV
paths:
 /documents:
   post:
     description: >
       The structure of the *metadata* property should conform to the schema
       defined in the
       [ModelPostDocumentInvoice](#/components/schemas/ModelPostDocumentInvoice)
       schema outlined at the bottom of this page. summary: Multipart/form-data
       with json object property + file
     requestBody:
       content:
         multipart/form-data:
           schema:
             $ref: '#/components/schemas/ModelPostDocumentInvoiceCombineModelFile'
     operationId: test2
     responses:
       '200':
         description: ok
         content:
           application/json:
             schema:
               type: string
               description: ok
components:
 schemas:
   ModelFile:
     type: object
     properties:
       file:
         type: string
         format: binary
     required:
       - file
   AbstractModelPostDocument:
     type: object
     properties:
       title:
         type: string
         default: ''
         maxLength: 64
         example: MyDocument.pdf'
         description: Displayed title. Can be different than filename
       category:
         type: string
         enum:
           - Invoice
           - Receipt
           - Credit note
           - Purchase Order
       documentDate:
         type: string
         description: >-
           Creation date of the document. Example : For ID card, it is the
           issuing date of the card.
         format: date
     required:
       - title
       - category
       - documentDate
   ModelPostDocumentInvoice:
     allOf:
       - $ref: '#/components/schemas/AbstractModelPostDocument'
       - type: object
         properties:
           amount:
             type: number
             example: 1234.56
             description: Invoice Amount
         description: Metadata for invoice documents
         required:
           - amount
   ModelPostDocumentOneOf:
     oneOf:
       - $ref: '#/components/schemas/ModelPostDocumentInvoice'
   ModelPostDocumentInvoiceCombineModelFile:
     allOf:
       - $ref: '#/components/schemas/ModelFile'
       - type: object
         properties:
           metadata:
             $ref: '#/components/schemas/ModelPostDocumentInvoice'
         description: metadata
         required:
           - metadata
   ModelPostDocumentOneOfCombineModelFile:
     allOf:
       - $ref: '#/components/schemas/ModelFile'
       - type: object
         properties:
           metadata:
             $ref: '#/components/schemas/ModelPostDocumentOneOf'
         required:
           - metadata

Is your feature request related to a problem?

In the example provided the 'metadata' which is an object property property is defined using a schema.
After clicking on 'Try it out' an example based on this schema is displayed, however the schema is not displayed in Swagger UI.

Consequently :

  • As API provider I have to provide a link in description to inform consummer that the json for the property should follow the schema
    image

  • As API consumer I have to scroll down to the bottom of the OAS definition to display the schema.
    image

Describe the solution you'd like

With the impovement, for each obect property, the user is allowed to choose between 'Example value' and 'Schema'
image

Describe alternatives you've considered

Current solution : Add link to the schema in endpoint's description

Additional context

The purpose of this endpoint is to offer a versatile method for uploading files and associated metadata of various types. The set of metadata required depends on the nature of the file, such as Invoicing or Identification documents (see Schemas for examples).

Related issues :

@kenchen-cs
Copy link

As it's not officially supported, I have to do it myself. My solution is simple and just show the example value like clicking "Try it out". Even though it's not as fancy as your example, it's better than nothing.

kenspirit@d325fd8

image

@jearton
Copy link

jearton commented Jun 27, 2024

Need it + 1

@kenspirit
Copy link

As it's not officially supported, I have to do it myself. My solution is simple and just show the example value like clicking "Try it out". Even though it's not as fancy as your example, it's better than nothing.

kenspirit@d325fd8

image

The change can be checked for a better handling now in: https://github.com/kenspirit/swagger-ui/tree/multipart-body-show-schema

@iliaszh
Copy link

iliaszh commented Jul 30, 2024

same problem here

@BreakBB BreakBB linked a pull request Oct 11, 2024 that will close this issue
17 tasks
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

Successfully merging a pull request may close this issue.

5 participants