Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion - Added option to set preferred request body content-type #803

Merged

Conversation

thim81
Copy link
Contributor

@thim81 thim81 commented Jul 11, 2024

Linked to #801 and #802

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 adds the option to set a preferred content-type as request body, when there are multiple content-types defined in the request body of OpenAPI

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

Default Result, with no preferredRequestBodyType option defined:
image

Result, with preferredRequestBodyType option defined as raw:
image

Copy link
Member

@VShingala VShingala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add few unit tests as well to make sure functionality works as intended.

lib/options.js Outdated Show resolved Hide resolved
lib/options.js Outdated Show resolved Hide resolved
@thim81
Copy link
Contributor Author

thim81 commented Jul 12, 2024

hi @VShingala

I added the 4th option and tests to make the sure the scenario's are covered.
I think it is ready for your review and feedback.

@thim81 thim81 requested a review from VShingala July 12, 2024 07:05
lib/options.js Outdated Show resolved Hide resolved
lib/options.js Outdated Show resolved Hide resolved
libV2/schemaUtils.js Outdated Show resolved Hide resolved
libV2/schemaUtils.js Outdated Show resolved Hide resolved
@thim81 thim81 requested a review from VShingala July 15, 2024 14:58
@thim81
Copy link
Contributor Author

thim81 commented Jul 15, 2024

@VShingala All changes are made and tests are ✅, expect for the "external:false", see #803 (comment)

@thim81
Copy link
Contributor Author

thim81 commented Jul 15, 2024

Perhaps I can extend the tests with one without external and another with all options.

Copy link
Member

@VShingala VShingala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good!

@VShingala VShingala merged commit fec6268 into postmanlabs:develop Jul 16, 2024
6 checks passed
@thim81 thim81 deleted the develop-801-request-contenttype-body branch July 16, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants