Skip to content

enhancement: add ability to define encoding option on operations with complex serialization #34

@GamerGirlandCo

Description

@GamerGirlandCo

From the openapi specification website:

Complex Serialization in Form Data

[...] For more complex scenarios, such as nested arrays or JSON in form data, you need to use the contentType keyword to specify the media type for encoding the value of a complex field. Consider Slack incoming webhooks for an example. A message can be sent directly as JSON, or the JSON data can be sent inside a form field named payload like so (before URL-encoding is applied):

payload={"text":"Swagger is awesome"}

This can be described as:

openapi: 3.0.0
info:
  version: 1.0.0
  title: Slack Incoming Webhook
externalDocs:
  url: https://api.slack.com/incoming-webhooks

servers:
  - url: https://hooks.slack.com

paths:
  /services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX:
    post:
      summary: Post a message to Slack
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Message"

          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                payload: # <--- form field that contains the JSON message
                  $ref: "#/components/schemas/Message"
            encoding:
              payload:
                contentType: application/json

      responses:
        "200":
          description: OK

components:
  schemas:
    Message:
      title: A Slack message
      type: object
      properties:
        text:
          type: string
          description: Message text
      required:
        - text

Perhaps the ContentUnit struct could be extended to include a map field that maps property names to mime-type strings, and an Encoding function could be added to populate said map?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions