Skip to content

When using oneOf for a property of a multipart/form-data, the json example is replaced by an empty string #9745

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

Closed
AlexisAmd opened this issue Mar 25, 2024 · 1 comment

Comments

@AlexisAmd
Copy link

AlexisAmd commented Mar 25, 2024

Q&A

  • OS: W10
  • Browser: Firefox
  • Version: 115.5.0esr (32 bits)
  • Method of installation: Web ( https://editor.swagger.io/)
  • Swagger-UI version: 4.12.1 5.11.0
  • OpenAPI version: 3.0.3

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Example app
  description: This is my test applicaiton
  version: 1.0.0
  contact:
    name: John Doe
    email: [email protected]
servers:
  - url: https://dev.app.com/appApplicationName
    description: DEV
paths:
  /documentsWithCombineOneOf:
    post:
      description: ''
      summary: Add a document - KO
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ModelPostDocumentOneOfCombineModelFile'
      operationId: testKo
      security:
        - Basic: []
      tags: []
      responses:
        '200':
          $ref: '#/components/responses/Default'
  /documentsWithCombineWithoutOneOf:
    post:
      description: ''
      summary: Add a document - OK
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ModelPostDocumentInvoiceCombineModelFile'
      operationId: test2
      security:
        - Basic: []
      tags: []
      responses:
        '200':
          $ref: '#/components/responses/Default'
  /documentsWithCombineOneOfInBody:
    post:
      description: ''
      summary: Add a document - OK
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ModelPostDocumentOneOfCombineModelFile'
      operationId: test3
      security:
        - Basic: []
      tags: []
      responses:
        '200':
          $ref: '#/components/responses/Default'
components:
  schemas:
    AbstractModelPostDocument:
      type: object
      properties:
        title:
          type: string
          default: ''
          maxLength: 64
          example: MyDocument.pdf'
        category:
          type: string
          pattern: ''
        type:
          type: string
          description: Type depends on category
        issuingApplicationId:
          type: string
          enum:
            - App1
            - App2
            - App3
            - App4
        documentDate:
          type: string
          description: >-
            Creation date of the document. Example : For ID card, it is the
            issuing date of the card.
          format: date
        sharedWith:
          type: array
          items:
            type: string
            enum:
              - CustomerPortal
              - PartnerPortal
          uniqueItems: true
          minItems: 0
          maxItems: 2
      required:
        - title
        - category
        - type
        - documentDate
        - file
    ModelPostDocumentPolicy:
      allOf:
        - $ref: '#/components/schemas/AbstractModelPostDocument'
        - type: object
          properties:
            policyNumber:
              type: string
              description: Policy Number
              example: '132456'
              minLength: 1
              maxLength: 36
              pattern: ''
          description: Metadata for policy documents
          required:
            - policyNumber
    ModelPostDocumentCustomer:
      allOf:
        - $ref: '#/components/schemas/AbstractModelPostDocument'
        - type: object
          properties:
            customerNumber:
              type: number
              description: Customer Number
              exclusiveMinimum: true
              minimum: 0
              exclusiveMaximum: true
              maximum: 99999999999999
            organisationName:
              type: string
              enum:
                - Organisation1
                - Organisation2
                - Organisation3
              description: Organisation Name
          required:
            - organisationName
            - customerNumber
          description: Metadata for Customer Documents
    ModelPostDocumentInvoice:
      allOf:
        - $ref: '#/components/schemas/AbstractModelPostDocument'
        - type: object
          properties:
            invoiceNumber:
              type: string
              description: Invoice Number
              example: '132456'
              minLength: 1
              maxLength: 36
              pattern: ''
            amount:
              type: number
              example: 1234.56
              description: Invoice Amount
          description: Metadata for invoice documents
          required:
            - amount
            - invoiceNumber
    ModelPostDocumentOneOf:
      oneOf:
        - $ref: '#/components/schemas/ModelPostDocumentPolicy'
        - $ref: '#/components/schemas/ModelPostDocumentCustomer'
        - $ref: '#/components/schemas/ModelPostDocumentInvoice'
    ModelFile:
      type: object
      properties:
        content:
          type: string
          format: binary
      required:
        - content
    ModelPostDocumentOneOfCombineModelFile:
      allOf:
        - $ref: '#/components/schemas/ModelFile'
        - type: object
          properties:
            metadata:
              $ref: '#/components/schemas/ModelPostDocumentOneOf'
          required:
            - metadata
    ModelPostDocumentInvoiceCombineModelFile:
      allOf:
        - $ref: '#/components/schemas/ModelFile'
        - type: object
          properties:
            metadata:
              $ref: '#/components/schemas/ModelPostDocumentInvoice'
          description: metadata
          required:
            - metadata
  securitySchemes:
    Basic:
      type: http
      scheme: basic
  responses:
    Default:
      description: Not needed
      headers: {}
      content:
        application/json:
          schema:
            type: string
            description: not needed
tags: []

Describe the bug you're encountering

When using oneOf for a property of a multipart/form-data, the json example is replaced by an empty string instead of an example while, according to the 2 other tests below, I expected it to be the example for the first element of the 'OneOf' relation.

Screenshot of the empty field :
image

Other tests in the attached YAML:

  • When not using oneOf for the multipart/form-data, the example is displayed.
    Example: in '/documentsWithCombineWithoutOneOf' the example for 'ModelPostDocumentInvoice' is displayed
    image

  • When using oneOf for a POST with request body instead of mutipart/format-data, addtionaly to the schema, the first example of the 'OneOf' relation is displayed.
    Example: "/documentsWithCombineOneOfInBody, the ModelPostDocumentPolicy which is the first item of the oneOf relation of ModelPostDocumentOneOfCombineModelFile is displayed :
    image

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Past definition above
  3. Scroll down to '/documentsWithCombineOneOf'
  4. Click on 'Try on'
  5. See that the example is replaced by an empty field

Expected behavior

Display the example for the first element of the 'OneOf' relation, like in the screenshot of '/documentsWithCombineWithoutOneOf'

Related issues

Other related issues but not duplicates:
#5169: Display static documentation information for multipart properties in OpenAPI 3.0 files
#7462 : When using oneOf with multipart/form-data the ability to upload a file is incorrectly replaced with a string

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