apideck-libraries / portman

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

Filter causes YAMLException #631

Closed eurog33k closed 1 month ago

eurog33k commented 1 month ago

I'm issuing the following command: portman -l ./time.json -o ./outcoll.json --filterFile ./filter.json

My portman version is 1.29.1 on MacOS 13.6.7

I'm getting the following:

====================================================================================================================================================================================================================================== Local Path: ./time.json Output Path: ./outcoll.json Portman Config: portman-config.default.json Postman Config: postman-config.default.json Filter Config: ./filter.json Environment: .env Inject Tests: true Run Newman: false Newman Iteration Data: false Upload to Postman: false

err YAMLException { name: 'YAMLException', reason: 'unacceptable kind of an object to dump [object Undefined]', mark: null, message: 'JS-YAML: unacceptable kind of an object to dump [object Undefined]', isWarning: false } OAS File Error - Unable to process the OpenAPI file. Error: Filter file error - ./filter.json doesn't exist.

I'm attaching my openapi 3 file and my filter file time.json filter.json

I haven't been able to figure out why the filter doesn't work.

If I issue the command without the filter (portman -l ./time.json -o ./outcoll.json), the outcoll.json Postman collection gets generated correctly.

I'm unable to get the filter to work.

thim81 commented 1 month ago

Hi @eurog33k

We look into the cause of this, which we can try to reproduce thanks to your clear explanation and files. It could be that the filter action results in a incorrect YAML structure. We will keep you posted of our findings.

thim81 commented 1 month ago

hi @eurog33k

The issue lies with the empty oneOf:

image

The filtering mechanisme cleans up "empty" objects. In case of anyOf or oneOf; the empty objects are valid so they should be kept.

This will be fixed in the next release of Portman.

As a work-around, you can already keep the "empty" objects by adding "preserveEmptyObjects": true in your filters.

filter.json >>

{
  "methods": ["POST","DELETE"],
  "tags": [],
  "operationIds": [],
  "operations": [],
  "flags": [],
  "flagValues": [],
  "preserveEmptyObjects": true
}

You can see the filtered result in the online playground

thim81 commented 1 month ago

FYI: Thanks to your example we also spotted a unwanted removal of the "delete" property, which will also be fixed in the next Portman version.

thim81 commented 1 month ago

hi @eurog33k

We just released Portman 1.29.2, which contains the fixes for the reported YAML error.

Thanks for reporting the issue and helping us to improve Portman.

eurog33k commented 1 month ago

I can confirm that the update fixes the problem. I'm glad my report helped the project.