Forum Discussion

res13's avatar
res13
New Contributor
4 years ago

Standardization: Custom rule which ensures that at least one server url matches a pattern

I am trying to create a custom rule which ensures that there is at least one server url which matches a certain pattern (https://{host}/mypath).

My test API looks like this:

 

 

...
servers:
  - description: SwaggerHub API Auto Mocking
    url: https://myswaggerhub/virts/myorg/myapi/1.0.0
  - url: 'https://{host}/mypath'
    variables:
      host:
        enum:
          - 'myfirsthost:443'
          - 'mysecondhost:443'
        default: 'myfirsthost:443'
...

 

 

I tried the following:

1) Create a JSONPath matching my mandatory URL which must exists. Unfortunately, 'path exists' does not support expressions (see attached image named custom_rule_1.png)

2) Create a JSONPath matching all urls and add a regex to match my mandatory URL. Unfortunately, this also excludes all other URLs (see attached image named custom_rule_2.png)

3) Create a JSONPath matching all urls and add a regex to match my mandatory URL or any other URL. Unfortunately, this does not enforce that my mandatory URL must be present (see attached image named custom_rule_3.png