postmanlabs / openapi-to-postman

Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format
Apache License 2.0
928 stars 200 forks source link

Conversion - Select request body content-type as ordered in OpenAPI #802

Closed thim81 closed 4 months ago

thim81 commented 4 months ago

Linked to #801

Currently the request body used for creating the Postman request is a fixed content-type mapping, where the following logic applies:

  1. if present, the 'x-www-form-urlencoded' is taken
  2. ELSE if the 'form-data' is taken
  3. ELSE fallback to 'raw'

This PR uses the order of the request body content-types as ordered in the OpenAPI spec, meaning which ever is found first will be taken.

Example OpenAPI:

openapi: 3.0.0
info:
  version: v1
  title: 601-RequestBody TcPCM Gateway API
  description: TcPCM Gateway API
  license:
    name: Privacy Policy
    url: https://www.plm.automation.siemens.com/global/en/legal/privacy-policy.html
paths:
  "/api/v1/administration/samAuth/users/{userName}":
    put:
      tags:
        - "Administration: Users"
      summary: Create or Update Sam Auth User
      operationId: CreateSamAuthUser_CreateOrUpdateSamAuthUser
      parameters:
        - name: userName
          in: path
          description: User name
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          description: bearer token
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateSamAuthUserRequestModel"
          text/json:
            schema:
              $ref: "#/components/schemas/CreateSamAuthUserRequestModel"
          application/xml:
            schema:
              $ref: "#/components/schemas/CreateSamAuthUserRequestModel"
          text/xml:
            schema:
              $ref: "#/components/schemas/CreateSamAuthUserRequestModel"
          application/x-www-form-urlencoded:
            schema:
              $ref: "#/components/schemas/CreateSamAuthUserRequestModel"
        description: The request represents that the user with {userName} will either be
          created or updated depending on whether the {userName} exists or not.
        required: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
            text/json:
              schema:
                type: object
            application/xml:
              schema:
                type: object
            text/xml:
              schema:
                type: object

Current result: image

PR result:

image
thim81 commented 4 months ago

Closing this in favour of #803