How to make swagger compliance assertion url dynamic
Hi,
I have been struggling to get some grip on the swagger compliance assertion. I want to provide a dynamic url but ReadyAPI doesn't seem to cope with it in the way I would expect.
Use case: The swagger url might change over time and I don't want to adapt it in all individual swagger compliance assertions.
Current attempt:
In my project setup script I define following properties:
1)
def swaggerENGvalidationPath = testDataPath + File.separator + "swagger" + File.separator + "ENG" + File.separator + swaggerENGversionForValidation + ".yaml"
project.setPropertyValue("swaggerENGvalidationPath", swaggerENGvalidationPath)
2)
def swaggerAPPvalidationPath = "https://onlineUrlToMyApiSwagger.yaml"
project.setPropertyValue("swaggerAPPvalidationPath", swaggerAPPvalidationPath)
So path 1 is pointing to a yaml file present in my project repo. In the swagger validation assertion I set the url to \${#Project#swaggerENGvalidationPath} and this works fine.
Path 2 should point to a specific url. When I set this url directly in the swagger validation assertion it works. But when I set the swaggerAPPvalidationPath as a dynamic property in the assertion like this: ${#Project#swaggerAPPvalidationPath} it doesn't work.
I see in the log "Fri Jun 25 09:19:17 UTC 2021: ERROR: attribute is not of type `object`" and I can see the HTTP Log reading the swagger file, but the assertion always fails "Failed to load the swagger definition from [${#Project#swaggerAPPvalidationPath}]
With \${#Project#swaggerAPPvalidationPath} it complains like this: Illegal char <:> at index 7. I notice indeed that then it starts with C:/http... which obviously won't work.
I tried to also to put some escaping variants in my project property, but to no avail. Tried "https://onlineUrlToMyApiSwagger.yaml", "https:////onlineUrlToMyApiSwagger.yaml", "'https://onlineUrlToMyApiSwagger.yaml'", "\"https://onlineUrlToMyApiSwagger.yaml\"",...
Here is an approach which you can try.
NOTE:
1. In the Swagger Compliance Assertion set a file path or url (absolute value). The value will be replaced with value passed at run time as project property, SWAGGER_URL
2. Here, property expansion is not used. Instead value is overridden run time.
3. Please follow the comments provided in the script.
4. This is project setup script only.
Here is the log message when the script is run