Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Multipart/FormData type for individual properties #5392

Closed
GlenBrauer opened this issue Jun 6, 2019 · 3 comments
Closed

Multipart/FormData type for individual properties #5392

GlenBrauer opened this issue Jun 6, 2019 · 3 comments

Comments

@GlenBrauer
Copy link

GlenBrauer commented Jun 6, 2019

  • OS: Windows 10
  • Browser: Chrome
  • Version: 74.0.3729.169
  • Swagger-UI version: Whatever is the latest online (swagger hub)
  • Swagger/OpenAPI version: OpenAPI 3.0.1

Example Swagger/OpenAPI definition:

openapi: 3.0.1
/document/addDocument:
    post:
      summary: Adds a file to the system as a document object with the provided metadata
      operationId: addDocument
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  description: input stream of the file
                  format: binary
                document:
                  $ref: '#/components/schemas/DocumentUploadData'            
      responses:
        default:
          description: default response
          content:
            '*/*': {}
      security:
      - qsessionauth: []
components:
  schemas:
    DocumentUploadData:
      type: object
      properties:
        classificationId:
          type: string
          description: The id of the classification the document should be filed in
        documentTypeId:
          type: string
          description: The id representing the type of the document
        indexValues:
          type: array
          description: A list of custom data fields to put on the document
          items:
            $ref: '#/components/schemas/IndexValue'
      description: Contains the classificationId, documentTypeId, and indexFields
        for a document that is being uploaded.

I am trying to test out my OAS using the "try it" on swagger hub. I know my OAS works correctly as I have successfully executed it from a java client, however I would like to allow api consumers to try it directly from the swagger hub. My api request uploads a file and metadata for the file which is a json object "DocumentUploadData" in teh schema.

When I submit the call I get a response from my server stating that the DocumentUploadData object received by the server is null. I can see in the curl command that the type attribute for the document property is missing. If i add the attribute "type=application/json" to the curl command and run it then it is successful. I believe that the type property is not being read from the OAS spec. Or possibly I have my yaml written incorrectly.

I have tried it both with and without the "encoding" section.

encoding:
              document:
                contentType: application/json

and also tried manually defining my object instead of using a ref.

Curl command generated from swagger hub request:

curl -X POST "linkRemovedForSecurityPurposes" -H "accept: */*" -H "Authorization: Bearer 49d57780-09ed-4560-9f87-35aae4110ec0" -H "Content-Type: multipart/form-data" -F "document={ \"classificationId\": \"0d382883-bf94-49c2-a588-dd66018972be\", \"documentTypeId\": \"33a92405-3906-4431-b500-28873cf8f939\", \"indexValues\": [] }" -F "file=@sample.txt;type=text/plain" -F "content="

Curl command that runs correctly when executed:

curl -X POST "linkRemovedForSecurityPurposes" -H "accept: */*" -H "Authorization: Bearer 49d57780-09ed-4560-9f87-35aae4110ec0" -H "Content-Type: multipart/form-data" -F "document={ \"classificationId\": \"0d382883-bf94-49c2-a588-dd66018972be\", \"documentTypeId\": \"33a92405-3906-4431-b500-28873cf8f939\", \"indexValues\": [] }";type=application/json -F "file=@sample.txt;type=text/plain" -F "content="
@hkosova
Copy link
Contributor

hkosova commented Aug 29, 2019

Duplicate of #4826.

@hkosova hkosova closed this as completed Aug 29, 2019
@chandnitin333
Copy link

  • 	@OA\RequestBody(
    
  •      required=true,
    
  •      @OA\MediaType(
    
  •          mediaType="multipart/form-data",
    
  •          @OA\Schema(                
    
  •              @OA\Property(
    
  •                  property="kaizen_video",
    
  •                  description="kaizen_video",
    
  •                  type="file",     
    
  •                  @OA\Items(type="string", format="binary")
    
  •               ),
    
  •           ),
    
  •       ),
    
  •   ),
    

I have try to send only file['tmp_name'] but it doesnt work and also try to convert file encode_base64 but it is the same result.

@chandnitin333
Copy link

also file type and temp name getting blank.....

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants