apideck-libraries / portman

Port OpenAPI Specs to Postman Collections, inject test suite and run via Newman 👨🏽‍🚀
http://getportman.com/
Apache License 2.0
622 stars 58 forks source link

Error when using undocumented option uploadOnly #331

Open Kallys opened 2 years ago

Kallys commented 2 years ago

Hi!

When I'm using undocumented option "uploadOnly", portman fails. I tried debugging and catched the "Error: Postman collection name is required.[...]" exception at this line throwed from this line. It seems that collectionName is empty when trying to read collection name (portmanCollection?.info?.name). Also, it appears that portmanCollection?.name is working in "uploadOnly" context.

Thanks!

thim81 commented 2 years ago

Hi @Kallys

uploadOnly served a use-case that was not that common, the syncPostman option is greatly enhanced to do kind of the same.

Could you explain your use-case for uploadOnly?

On the collection name, not sure what is wrong here. Could you perhaps share your OpenApi collection?

Kallys commented 2 years ago

Hi @thim81! Thanks for your quick reaction!

My use-case is the following: I have manually writen tests (that portman can't generate) in a postman collection, I want them to be bundled with portman generated tests in a single postman collection and upload the combined collection to a postman workspace. I'm using a script that combines my both collections, but I'm unable to uploadOnly them.

syncPostman requires me to provide an OpenAPI definition:

$ portman --syncPostman true --env .env --localPostman combined.collection.json
===================================================================
 Portman Config:        portman-config.default.json
 Postman Config:        postman-config.default.json
 Environment:           .env
 Inject Tests:          true
 Run Newman:            false
 Newman Iteration Data: false
 Upload to Postman:     true
===================================================================
Error: Error initializing OpenApi Spec.
===================================================================

Ok so apparently, I just found that if I provide any valid OpenAPI definition, sync is working!

$ portman --syncPostman true --env .env --localPostman root.collection.json --url https://raw.githubusercontent.com/apideck-libraries/portman/main/examples/config-references/crm.openapi.yml
===================================================================
 Remote Url:            https://raw.githubusercontent.com/apideck-libraries/portman/main/examples/config-references/crm.openapi.yml
 Portman Config:        portman-config.default.json
 Postman Config:        postman-config.default.json
 Environment:           .env
 Inject Tests:          true
 Run Newman:            false
 Newman Iteration Data: false
 Upload to Postman:     true
===================================================================
  ✔ Upload to Postman Succeeded
[...]

For now, I will use this option as a workaround, but maybe you may wan't to adapt portman behavior to this use-case? Perhaps localPostman should totally avoid the requirement of an OpenAPI definition?

Thanks!

thim81 commented 2 years ago

@Kallys Portman does support the usage of injecting custom tests/postman scripts. You can even manage them in a seperate JS file and just reference the file.

By using https://github.com/apideck-libraries/portman#portman---extendtests-properties, you can specify which OpenAPI operation you want to extend with customer tests.

Reading your use-case, you are not starting from an OpenAPI specification, but you want to simply merge 2 Postman collections and upload them? Or do you use Portman for injecting variables,overwrites, ...?

Kallys commented 2 years ago

@thim81 Extend tests allows to extend existing API routes, but what I need to do (for my manual tests) is (for exemple):

To be more precise on my use-case:

  1. Generate postman collection auto.json with portman options (injection etc) from an OpenAPI spec
  2. Manually write postman collection manual.json with tests I can't perform with portman
  3. Combine collections auto.json and manual.json into combined.json collection
  4. Upload to portman workspace and run newman onto combined.json
thim81 commented 2 years ago

Hi @Kallys, I have been using the following configuration, which is using the collectionName option.

openapi: 3.0.3
info:
  title: 332 Organizations API
{
  "local": "./tmp/333-bracket/input-openapi.yml",
  "output": "./tmp/333-bracket/output-postman.json",
  "portmanConfigFile": "./tmp/333-bracket/portman-config.json",
  "includeTests": true,
  "syncPostman": true,
  "collectionName": "333 bracket"
}

It does sync the generated collection to Postman, and overwriting the Collection name title: 332 Organizations API with 333 bracket.

2022-06-06 at 19 32 49@2x

In your initial case, when the error occured, did the OpenAPI file contained an info.title or was it blank?