Forum Discussion

ehudson's avatar
ehudson
Occasional Visitor
4 years ago

Using objects in formData in OpenAPI 2.0 (how to $ref?)

Hi,   Using OpenAPI 2.0, I have a number of parameters for a post operation. I can't figure out how to handle object types, and in particular using $ref to their properties. For a string parameter,...
  • HKosova's avatar
    4 years ago

    Hi ehudson,

     

    OpenAPI 2.0 does not support objects and $ref in form data. You need OpenAPI 3.0 for that. Here's an example that you can test in the Swagger Editor:

     

    openapi: 3.0.0
    info:
      title: Object in form data
      version: 1.0.0
    servers:
      - url: https://httpbin.org/anything
    
    paths:
      /something:
        post:
          requestBody:
            content:
              application/x-www-form-urlencoding:
                schema:
                  type: object
                  properties:
                    parameterName:
                      $ref: '#/components/schemas/MyParameterDescription'
          responses:
            '200':
              description: ok
    
    components:
      schemas:
        MyParameterDescription:
          type: object
          description: An object sent inside a form field
          properties:
            first_property:
              description: ...

     

    For more OpenAPI 3.0 examples, see the "Form Data" section in Describing Request Body.