Skip to content

Incorrect code example for requests supporting several content types #1283

@shadone

Description

@shadone

Describe the bug

Code example display wrong code for requests that have multiple supported content-types

For example I have a POST endpoint that accepts either application/json or application/xml - the requests are different - json request has field example_request_json_param and xml request has field example_request_xml_param but the example widget always shows params for the json request. See attached screenshot

Note this is not limited to "curl" example only, examples in other tools/languages have the same issue - Go, Rust, Nodejs etc.

Expected behavior

I expected to see the following curl example requests:

For application/json request:

curl -L 'https://example.com/signature/foobar' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{
  "example_request_json_param": "string"
}'

For application/xml request:

curl -L 'https://example.com/signature/foobar' \
-H 'Content-Type: application/xml' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{
  "example_request_xml_param": "string"
}'

Current behavior

Instead it shows the following:

For application/json request:

curl -L 'https://example.com/signature/foobar' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{
  "example_request_json_param": "string"
}'

For application/xml request:

curl -L 'https://example.com/signature/foobar' \
-H 'Content-Type: application/xml' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{
  "example_request_json_param": "string"      <<<<<--- notice this shows "json_param" instead of "xml_param"
}'```
 
## Possible solution


## Steps to reproduce

Here is what my openapi.yaml looks like

```yaml
...
paths:
  /signature/foobar:
    post:
      tags:
        - Embed
      summary: Example endpoint
      description: Example endpoint
      operationId: ExampleEndpoint
      security:
        - BearerAuth: []
      requestBody:
        description: Example endpoint request
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ExampleRequestJSON"
          application/xml:
            schema:
              $ref: "#/components/schemas/ExampleRequestXML"
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ExampleResponse"

components:
  schemas:
    ExampleRequestJSON:
      type: object
      required:
        - example_request_json_param
      properties:
        example_request_json_param:
          type: string

    ExampleRequestXML:
      type: object
      required:
        - example_request_xml_param
      properties:
        example_request_xml_param:
          type: string

    ExampleResponse:
      type: object
      required:
        - example_response_param
      properties:
        example_response_param:
          type: string
          description: The example response parameter

Screenshots

Image Image

Context

Your Environment

  • Version used: Docusaurus 3.9.2, docusaurus-plugin-openapi-docs 4.5.1
  • Environment name and version (e.g. Chrome 59, node.js 5.4, python 3.7.3):
  • Operating System and version (desktop or mobile):
  • Link to your project:

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions