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

Postman CollectionTypeError on empty examples object #652

Open
miriamgreis opened this issue Sep 9, 2024 · 11 comments
Open

Postman CollectionTypeError on empty examples object #652

miriamgreis opened this issue Sep 9, 2024 · 11 comments
Assignees
Labels
investigate Needs more investigation, before next steps can be defined.

Comments

@miriamgreis
Copy link
Contributor

If I use the following stripped-down OpenAPI file, I get an error during the conversion saying: Converting OpenAPI to Postman Collection Type Error: Cannot read properties of undefined (reading '$ref').

The problem is the empty examples: {} which is sometimes autogenerated by Stoplight Studio. This wasn't a problem with earlier versions of Portman, so I assume that it is related to some recent openapi-format updates. I'm not sure whether this can be fixed here, but for me it's most important that Portman fails on such errors when I use it in the CI. Otherwise, nobody will realise that the tests are not generated at all.

openapi: 3.0.1
info:
  title: Test
  version: 1.0.0
  description: Test
servers:
  - url: https://example.de/test
security:
  - bearerToken: []
tags:
  - name: Test API
paths:
  /test:
    get:
      summary: Get test
      tags:
        - Test API
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  test-value:
                    type: string
              examples: {}
      operationId: get-test
      description: Test
  securitySchemes:
    bearerToken:
      type: http
      scheme: bearer
@thim81 thim81 self-assigned this Sep 9, 2024
@thim81 thim81 added the investigate Needs more investigation, before next steps can be defined. label Sep 9, 2024
@thim81
Copy link
Collaborator

thim81 commented Sep 9, 2024

hi @miriamgreis

Looking into the matter.
Do you apply a filter on the OpenAPI file?

@miriamgreis
Copy link
Contributor Author

No, just running Portman with the local OpenAPI file. Nothing special.

@thim81
Copy link
Collaborator

thim81 commented Sep 9, 2024

Openapi-format is only triggered when there is a filterFile passed along, so I'll look further in the matter.

Do you happen to know, in which version it still worked?

@miriamgreis
Copy link
Contributor Author

miriamgreis commented Sep 9, 2024

I just tried to figure it out as I had a very old version installed locally. The first version that I see the error message with is v1.29.0, but you might want to doublecheck.

Could be a problem with convertV2?

@thim81
Copy link
Collaborator

thim81 commented Sep 9, 2024

@miriamgreis Found the issue: the openapi-to-postman "convertV2" fails. We introduced the V2 method, which has become the default by Postman, in v1.29.

I'm created an the issue in the openapi-to-postman github.

@miriamgreis
Copy link
Contributor Author

Great, thanks for creating the issue. How is Portman supposed to behave if convertV2 fails? Because right now it doesn't fail on these errors.

@thim81
Copy link
Collaborator

thim81 commented Sep 9, 2024

It should fail:

postmanObj = await oaToPostman.convert(oaToPostmanConfig).catch(err => {
        console.error('Postman Collection generation failed: ', err.toString())
        process.exit(1)
      })

Let me double check if the error trigger is not properly catched in the nesting.

@thim81
Copy link
Collaborator

thim81 commented Sep 9, 2024

hi @miriamgreis, an update: We just submitted a PR that should overcome the error in the openapi-to-postman library.

@thim81
Copy link
Collaborator

thim81 commented Sep 9, 2024

as possible work-arounds for now:

  • manually remove the empty example
  • If you would use any filter or only a filter with preserveEmptyObjects: false, it will sanitize the OpenAPI spec of empty objects.

Since openapi-to-postman does not throw an error and returns a postman obj, we cannot catch the error with proper exit 1 code. In the PR on openapi-to-postman, we added the throwing of an error.

@miriamgreis
Copy link
Contributor Author

Perfect, thanks. For now I anyway manually removed the empty example anyway. I saw your PR for openapi-to-postman, so seems that everything needs to be resolved on their side.

@thim81
Copy link
Collaborator

thim81 commented Sep 11, 2024

update: The PR for openapi-to-postman is merged in.
We will have to wait for the next release of openapi-to-postman to have it in Portman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Needs more investigation, before next steps can be defined.
Projects
None yet
Development

No branches or pull requests

2 participants