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 59 forks source link

Merge several definitions #619

Closed vampyar closed 3 weeks ago

vampyar commented 1 month ago

How I can using separate file and merge in the one file for overwrites field ?

overwrites:
    - $ref: './tests/portman/definitions/overwrites-vehicle.yml#/overwrites'
    - $ref: './tests/portman/definitions/overwrites-vehicle-v2.yml#/overwrites'

in the case I got error

 Invalid Portman Config:                ./tests/portman/portman-config.crm.yml
[
  {
    message: "'0' property type must be object",
    path: '{base}.overwrites.0',
    context: { errorType: 'type' }
  },
  {
    message: "'1' property type must be object",
    path: '{base}.overwrites.1',
    context: { errorType: 'type' }
  }
]

I need split this entity on the two file or more, and after combine to one in the overwrite or

tests:
  contentTests:
     - $ref : ...
     - $ref : ... 
thim81 commented 1 month ago

hi @vampyar

We created a small example using $references: https://github.com/apideck-libraries/portman/tree/main/examples/config-references, which could be helpful.

vampyar commented 1 month ago

hi @thim81 Yep I got it but your example you include one ref how I can did it like multiple time

version: 1
tests:
  contractTests:
    $ref: './examples/config-references/definitions/test-contracts.yaml#/contractTests'
  contentTests:
    $ref: './examples/config-references/definitions/test-content.yaml#/contentTests'
globals:
    $ref: 'https://raw.githubusercontent.com/apideck-libraries/portman/main/examples/config-references/definitions/globals.yaml#/globals'

like example:

version: 1
tests:
  contractTests:
    $ref: './examples/config-references/definitions/test-contracts.yaml#/contractTests'
    $ref: './examples/config-references/definitions/test-contracts1.yaml#/contractTests'
  contentTests:
    $ref: './examples/config-references/definitions/test-content.yaml#/contentTests'
globals:
    $ref: 'https://raw.githubusercontent.com/apideck-libraries/portman/main/examples/config-references/definitions/globals.yaml#/globals'
miriamgreis commented 4 weeks ago

hi @vampyar, it depends on how your file with the refs is structured.

It should work in your very first example if #/overwrites is an object and not an array. So you cannot include multiple $refs containing arrays, but with objects on a lower level it will work.

With a json config, it works for me like this by just including the $ref on the object level.

{
  "variationTests": [
    {
       ...
    },
    {
       "$ref": "portman-variation-tests.json#/variationTestsUnauthorized"
    }
  ]
}

With the portman-variation-tests.json containing objects:

{
  "variationTestsUnauthorized": {
       "openApiOperation": "*::/*",
       "openApiResponse": "401",
       "variations": [...]
    }
}