OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.57k stars 6.28k forks source link

[CSharp] JSON encoding on a form value not supported #5215

Open milesressler opened 4 years ago

milesressler commented 4 years ago
Description

C-Sharp generator doesn't support complex serialization in form data. For example, the Slack example here under Complex Serialization in Form Data (after removing application/json block under content) will send form data like "payload=class Message...etc" instead of "payload={"text":"Swagger is awesome"}", since it uses the ToString on the object instead of ToJson.

openapi-generator version

Tested on 4.3 and 5.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Slack Incoming Webhook
externalDocs:
  url: https://api.slack.com/incoming-webhooks
paths:
  /services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX:
    post:
      summary: Post a message to Slack
      requestBody:
        content:
          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
Command line used for generation

./mvn clean install

Steps to reproduce
  1. Generator the CSharp client
  2. Use the API
  3. Notice that the form value for "payload" will not be valid json
Related issues/PRs

Similar issue in Java - https://github.com/OpenAPITools/openapi-generator/issues/724

Suggest a fix/enhancement
milesressler commented 4 years ago

See PR #5217