joolfe / postman-to-openapi

🛸 Convert postman collection to OpenAPI
MIT License
577 stars 99 forks source link

no response body property - TypeError: Cannot read properties of null (reading 'trim') #233

Closed YOU54F closed 1 year ago

YOU54F commented 1 year ago

Same error as https://github.com/joolfe/postman-to-openapi/issues/198 , if body field is missing in a response.

See reproduction.

npx -y pmpact https://gist.githubusercontent.com/YOU54F/994b85ff830ed2f6f21057779c0a40f0/raw/41d3286503714bca5914df7da54a665c83a84c60/pact.json > postman-collection.json && npx -y p2o postman-collection.json

❯ npx -y pmpact https://gist.githubusercontent.com/YOU54F/994b85ff830ed2f6f21057779c0a40f0/raw/41d3286503714bca5914df7da54a665c83a84c60/pact.json  > postman-collection.json && npx -y p2o postman-collection.json
TypeError: Cannot read properties of undefined (reading 'trim')

modifying the input file to have "body": {} in the response body https://gist.github.com/YOU54F/994b85ff830ed2f6f21057779c0a40f0/revisions#diff-5f14bf76a8d5411742e1d427c982aca6fd3cc539aec6c998ddca5bb7f19c5565R63

returns in the OAS being returned

npx -y pmpact https://gist.githubusercontent.com/YOU54F/994b85ff830ed2f6f21057779c0a40f0/raw/5665d6625bc0f692f730bac058e4456c5bfe565b/pact.json > postman-collection.json && npx -y p2o postman-collection.json

Returns

openapi: 3.0.0
info:
  title: Pact - pactflow-example-consumer - pactflow-example-provider
  version: 1.0.0
servers:
  - url: http://{{url}}
paths:
  /product/10:
    get:
      tags:
        - default
      summary: a request to get a product
      parameters:
        - name: Authorization
          in: header
          schema:
            type: string
          example: Bearer 2019-01-14T11:34:18.045Z
      responses:
        '200':
          description: OK
          headers:
            Content-Type:
              schema:
                type: string
                example: application/json; charset=utf-8
          content:
            application/json:
              schema:
                type: object
              example:
                id: '10'
                type: CREDIT_CARD
                name: 28 Degrees
  /product/11:
    get:
      tags:
        - default
      summary: a request to get a product
      parameters:
        - name: Authorization
          in: header
          schema:
            type: string
          example: Bearer 2019-01-14T11:34:18.045Z
      responses:
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
              example: {}
  /products:
    get:
      tags:
        - default
      summary: a request to get all products
      parameters:
        - name: Authorization
          in: header
          schema:
            type: string
          example: Bearer 2019-01-14T11:34:18.045Z
      responses:
        '200':
          description: OK
          headers:
            Content-Type:
              schema:
                type: string
                example: application/json; charset=utf-8
          content:
            application/json:
              schema:
                type: object
              example:
                - id: '10'
                  type: CREDIT_CARD
                  name: 28 Degrees

Not urgent for me, just been playing around with the tool and noted this. Great work BTW

joolfe commented 1 year ago

@YOU54F thanks for report the issue,

This is a tricky one... the error is produced because the body in the response is undefined, I'm not able to generate a postman collection file with an undefined body using postman app or online version... but as this is easy to fix I have just released a new version 2.7.2 solving this.

Best Regards.