apideck-libraries / portman

Port OpenAPI Specs to Postman Collections, inject test suite and run via Newman šŸ‘ØšŸ½ā€šŸš€
http://getportman.com/
Apache License 2.0
636 stars 59 forks source link

Order by tags #621

Closed vampyar closed 2 months ago

vampyar commented 2 months ago

hi @thim81 can you help with it ?

I have this entities by by default when I'm running portman it run first entity in the the list, how I can did it without sorting in the openapi image

because I did try use config, but it not helped me, it's sorted only methods:

version: 1
globals:
  # For every request generated omit the Postman examples
  # This helps keep the generated test collection leaner
  stripResponseExamples: true
  variableCasing: camelCase

  orderOfOperations:
    - "POST::/v1/regulations"
    - "GET::/v1/regulations"
    - "GET::/v1/regulations/{id}"
    - "PUT::/v1/regulations/{id}/*"
    - "PATCH::/v1/regulations/{id}*"
    - "DELETE::/v1/regulations/{id}"
    - "POST::/v1/vehicle-types"
    - "GET::/v1/vehicle-types/{id}*"
    - "PUT::/v1/vehicle-types/{id}*"
    - "PATCH::/v1/vehicle-types/{id}*"
    - "DELETE::/v1/vehicle-types/{id}"
    - "POST::/v1/systems"
    - "GET::/v1/systems/{id}"
    - "PUT::/v1/systems/{id}*"
    - "PATCH::/v1/systems/{id}*"
    - "DELETE::/v1/systems/{id}"
thim81 commented 2 months ago

@vampyar Can you share the openapi file? So we can use that for our investigation to reproduce the behaviour?

vampyar commented 2 months ago

Open API api-json.json

My portman config

oas-format-filter.yml

---
methods:
tags:
operationIds:
####################################################################
# With this filters run only /v1/systems endpoints
# if you need only one specific endpoints uncomment all lines below
####################################################################
operations:
#  - "*::/v1/vehicle-types*"
#  - "*::/v2/regulations*"
#  - "*::/v1/regulations*"
#  - "*::/v1/systems*"
  - "*::/v2/vehicle-types*"
  - "*::/v2/systems*"
  - "*::/v1/releases*"
  - "*::/v2/releases*"
  - "*::/v1/ecus*"
  - "*::/v2/ecus*"
  - "*::/v1/status*"
  - "*::/v2/status*"
  ### END ####
  - "*::/v1/packages*"
  - "*::/v2/packages*"
  - "*::/v1/vehicles*"
  - "*::/v2/vehicles*"
  - "*::/v1/uploader/*"
  - "*::/v2/uploader/*"
  - "*::/v1/versions/list*"
  - "*::/v2/versions/list*"
  - "*::/v1/associations/manage*"
  - "*::/v2/associations/manage*"
  - "*::/v1/packageDistribution*"
  - "*::/v2/packageDistribution*"
  - "*::/v1/updateVehicleInfo*"
  - "*::/v2/updateVehicleInfo*"
flags: []
flagValues: []

portman-cli-options.yml

url: http://localhost:3000/api-json
baseUrl: http://localhost:3000
output: "./tests/portman/sums.postman.json"
collectionName: "SUMS NewMan / Portman"
portmanConfigFile: "./tests/portman/portman-config.crm.yml"
postmanConfigFile: "./tests/portman/postman-config.crm.json"
filterFile: "./tests/portman/oas-format-filter.yml"
includeTests: true
syncPostman: false # FIXME Temporary commented
runNewman: true
newmanRunOptions:
  reporters:
    - cli
    - junit
  reporter:
    junit:
      export: "junit-postman.xml"
  reporter-junit-export: "junit-postman.xml"

portman-config.crm.yml

version: 1
globals:
  # For every request generated omit the Postman examples
  # This helps keep the generated test collection leaner
  stripResponseExamples: true
  variableCasing: camelCase
  keyValueReplacements:
    # it's param tack automatic from env by prefix 'PORTMAN_' => PORTMAN_ADDITIONAL_TOKEN_USER
    additionaltokenuser: "{{additionalTokenUser}}"

  orderOfOperations:
    - "*::/v1/regulations"
    - "*::/v1/vehicle-types"
    - "*::/v1/system"

tests:
  contractTests:
    - openApiOperation: "*::*"
      # Check that the API returned a 2XX response
      statusSuccess:
        enabled: true
      # FIXME
#      responseTime:
#        enabled: true
#        maxMs: 300
      # Check if the response contains a Content-Type header with application/json
      contentType:
        enabled: true
      # Check if the response contaisn a JSON response body
      jsonBody:
        enabled: true
#  contentTests:
#    $ref: './tests/portman/definitions/overwrites-vehicle-types.yml#/contentTests'

assignVariables:
  - openApiOperation: "POST::*"
    collectionVariables:
      - responseBodyProp: data._id
        name: "<operationId>Id"
      - responseBodyProp: data.name
        name: "<operationId>Name"
  - openApiOperation: "PUT::*"
    collectionVariables:
      - responseBodyProp: data._id
        name: "<operationId>IdUpdated"
      - responseBodyProp: data.name
        name: "<operationId>NameUpdated"

#overwrites:
#  $ref: './tests/portman/definitions/overwrites.yml#/overwrites'
vampyar commented 2 months ago

@thim81 Hi, do you have any updates about it issues ?

thim81 commented 2 months ago

I did start investigating it but did not yet came to the cause of it.

Due to vacation, away from a laptop, I ll continue the investigation again past mid August.

vampyar commented 2 months ago

@thim81 Oh, sorry, have a good holiday, I hear you.

vampyar commented 2 months ago

@thim81 Do you have any updates ?

thim81 commented 2 months ago

hi @vampyar

No news about the cause, but are able to reproduce it:

Without ordering:

image

With ordering:

image

If I understand correctly, you want to order the "folders"?

from:

  1. Vehicle Types
  2. Vehicle Systems
  3. Regulations

to:

  1. Regulations
  2. Vehicle-types
  3. Systems

The ordering is build for the ordering of the operations within the folders, it will not re-arrange the folders, but that is what you are looking for?

As are 2 work-arounds, you could use

  1. Modify your OpenAPI document, by putting the Operations in the order as you want to run them.
  2. Pre-sort & filter the OpenAPI document using the following steps, before you pass it input to Portman:
npx openapi-format openapi.json -o openapi-formatted.json --sortFile oaf-sort.json --filterFile oaf-filter.json

where the oaf-sort.json looks like this:

{
  "sortPathsBy": "tags"
}

oaf-filter.json:

---
methods: []
tags: []
operationIds: []
####################################################################
# With this filters run only /v1/systems endpoints
# if you need only one specific endpoints uncomment all lines below
####################################################################
operations:
  #  - "*::/v1/vehicle-types*"
  #  - "*::/v2/regulations*"
  #  - "*::/v1/regulations*"
  #  - "*::/v1/systems*"
  - "*::/v2/vehicle-types*"
  - "*::/v2/systems*"
  - "*::/v1/releases*"
  - "*::/v2/releases*"
  - "*::/v1/ecus*"
  - "*::/v2/ecus*"
  - "*::/v1/status*"
  - "*::/v2/status*"
  ### END ####
  - "*::/v1/packages*"
  - "*::/v2/packages*"
  - "*::/v1/vehicles*"
  - "*::/v2/vehicles*"
  - "*::/v1/uploader/*"
  - "*::/v2/uploader/*"
  - "*::/v1/versions/list*"
  - "*::/v2/versions/list*"
  - "*::/v1/associations/manage*"
  - "*::/v2/associations/manage*"
  - "*::/v1/packageDistribution*"
  - "*::/v2/packageDistribution*"
  - "*::/v1/updateVehicleInfo*"
  - "*::/v2/updateVehicleInfo*"
flags: []
flagValues: []

See playground for the result

This will give you a filtered and sorted openapi-formatted.json file, which you can pass along to Portman which will result in:

image

This is off course not a permanent fix, since it will sort the folders by alphabet and not any specific custom ordering.

To provide a more permanent solution, we would have to introduce a new feature "orderOfFolders" (instead of "orderOfOperations").

thim81 commented 2 months ago

@vampyar We created a PR to introduce the option to sort Postman folders based on the "orderOfFolders" configuration. See the PR for more details.

vampyar commented 2 months ago

@thim81 Thx mate) Coooool )

thim81 commented 2 months ago

hi @vampyar

We just release Portman v1.30, which includes the "orderOfFolders" option to sort Postman folders. Be sure to update to the latest version of Portman.