Error when running Swagger-tester for Heroku-pets example
ujjwal08 opened this issue · 3 comments
I was trying to test heroku-pets example file(http://editor.swagger.io/#/) using swagger tester. I am getting an error-
**ERROR:connexion.api:Failed to add operation for PUT /pet/
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for POST /pet/
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for GET /pet/
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for GET /pet/{petId}
ResolverError: <ResolverError: Cannot resolve operationId "None"!>**
Starting testrun against hero.json or None using examples: True
Below is the code for my test.py file to run my configuration file for heroku-pets, which is i have saved locally in json format(config. file name- hero.json)
from swagger_tester import swagger_test
authorize_error = {
'get': {
'/pet/': [200,400, 404],
'/pet/{petId}': [200,400,404],
},
'post': {
'/pet/': [200,400, 404]
},
'put': {
'/pet/': [200,400, 404]
}
}
swagger_test('hero.json', authorize_error=authorize_error)
Below is my console output when i run my test.py file:
ujjwal@ujjwal:~/Desktop/dataweave$ python test.py
ERROR:connexion.api:Failed to add operation for PUT /pet/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 237, in add_paths
self.add_operation(method, path, endpoint, path_parameters)
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 189, in add_operation
resolver=self.resolver)
File "/usr/local/lib/python2.7/dist-packages/connexion/operation.py", line 210, in init
resolution = resolver.resolve(self)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 39, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 67, in resolve_function_from_operation_id
raise ResolverError(msg)
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for POST /pet/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 237, in add_paths
self.add_operation(method, path, endpoint, path_parameters)
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 189, in add_operation
resolver=self.resolver)
File "/usr/local/lib/python2.7/dist-packages/connexion/operation.py", line 210, in init
resolution = resolver.resolve(self)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 39, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 67, in resolve_function_from_operation_id
raise ResolverError(msg)
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for GET /pet/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 237, in add_paths
self.add_operation(method, path, endpoint, path_parameters)
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 189, in add_operation
resolver=self.resolver)
File "/usr/local/lib/python2.7/dist-packages/connexion/operation.py", line 210, in init
resolution = resolver.resolve(self)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 39, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 67, in resolve_function_from_operation_id
raise ResolverError(msg)
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for GET /pet/{petId}
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 237, in add_paths
self.add_operation(method, path, endpoint, path_parameters)
File "/usr/local/lib/python2.7/dist-packages/connexion/api.py", line 189, in add_operation
resolver=self.resolver)
File "/usr/local/lib/python2.7/dist-packages/connexion/operation.py", line 210, in init
resolution = resolver.resolve(self)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 39, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/usr/local/lib/python2.7/dist-packages/connexion/resolver.py", line 67, in resolve_function_from_operation_id
raise ResolverError(msg)
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
Starting testrun against hero.json or None using examples: True
INFO:swagger_tester.swagger_tester:TESTING PUT /pet/?
INFO:swagger_tester.swagger_tester:Using FlaskClient, got status code 404 for ********** PUT /pet/?
INFO:swagger_tester.swagger_tester:Got expected authorized error on /pet/? with status 404
INFO:swagger_tester.swagger_tester:TESTING POST /pet/?
INFO:swagger_tester.swagger_tester:Using FlaskClient, got status code 404 for ********** POST /pet/?
INFO:swagger_tester.swagger_tester:Got expected authorized error on /pet/? with status 404
INFO:swagger_tester.swagger_tester:TESTING GET /pet/?limit=11
INFO:swagger_tester.swagger_tester:Using FlaskClient, got status code 404 for ********** GET /pet/?limit=11
INFO:swagger_tester.swagger_tester:Got expected authorized error on /pet/?limit=11 with status 404
INFO:swagger_tester.swagger_tester:TESTING GET /pet/string?
INFO:swagger_tester.swagger_tester:Using FlaskClient, got status code 404 for ********** GET /pet/string?
INFO:swagger_tester.swagger_tester:Got expected authorized error on /pet/string? with status 404
I have installed connexion framework also. How to resolve above errors and What is the expected output for testing ? Actually, I am new to swagger and want to learn how testing is done with help of swagger tester so that i can use this in my organisation.
Below is the code for heroku-pets config file in json format(hero.json):
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "PetStore on Heroku",
"description": "This example has a working backend hosted in Heroku\n\nYou can try all HTTP operation described in this Swagger spec.\n\nFind source code of this API here\n"
},
"host": "petstore-api.herokuapp.com",
"basePath": "/pet",
"schemes": [
"http",
"https"
],
"consumes": [
"application/json",
"text/xml"
],
"produces": [
"application/json",
"text/html"
],
"paths": {
"/": {
"get": {
"parameters": [
{
"name": "limit",
"in": "query",
"description": "number of pets to return",
"type": "integer",
"default": 11,
"minimum": 11,
"maximum": 10000
}
],
"responses": {
"200": {
"description": "List all pets",
"schema": {
"title": "Pets",
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
}
}
},
"post": {
"parameters": [
{
"name": "pet",
"in": "body",
"description": "The pet JSON you want to post",
"schema": {
"$ref": "#/definitions/Pet"
},
"required": true
}
],
"responses": {
"200": {
"description": "Make a new pet"
}
}
},
"put": {
"parameters": [
{
"name": "pet",
"in": "body",
"description": "The pet JSON you want to post",
"schema": {
"$ref": "#/definitions/Pet"
},
"required": true
}
],
"responses": {
"200": {
"description": "Updates the pet"
}
}
}
},
"/{petId}": {
"get": {
"parameters": [
{
"name": "petId",
"in": "path",
"type": "string",
"description": "ID of the pet",
"required": true
}
],
"responses": {
"200": {
"description": "Sends the pet with pet Id"
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"birthday": {
"type": "integer",
"format": "int32"
}
}
}
}
}
I have experienced similar errors. Please help.
ERROR:connexion.api:Failed to add operation for GET /auth/list
Traceback (most recent call last):
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/api.py", line 237, in add_paths
self.add_operation(method, path, endpoint, path_parameters)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/api.py", line 189, in add_operation
resolver=self.resolver)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/operation.py", line 210, in __init__
resolution = resolver.resolve(self)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/resolver.py", line 39, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/resolver.py", line 67, in resolve_function_from_operation_id
raise ResolverError(msg)
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
ERROR:connexion.api:Failed to add operation for GET /auth/status
Traceback (most recent call last):
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/api.py", line 237, in add_paths
self.add_operation(method, path, endpoint, path_parameters)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/api.py", line 189, in add_operation
resolver=self.resolver)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/operation.py", line 210, in __init__
resolution = resolver.resolve(self)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/resolver.py", line 39, in resolve
return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
File "/Users/.pyenv/versions/sentience/lib/python2.7/site-packages/connexion/resolver.py", line 67, in resolve_function_from_operation_id
raise ResolverError(msg)
ResolverError: <ResolverError: Cannot resolve operationId "None"!>
Hi all,
I'm trying the Connexion library with Swagger, too.
I had the same issue at first but I think it's not a bug, it's just a missing property in our swagger.yaml file.
Please take a look at this file, from the Connexion's petstore example:
https://github.com/hjacobs/connexion-example/blob/master/swagger.yaml
first you need to add the 'operationId' property to your swagger.yaml file:
paths:
/pets:
get:
tags: [Pets]
operationId: app.get_pets
summary: Get all pets
then you need to implement the proper function (with the same signature as you defined in swagger.yaml) inside your app:
#!/usr/bin/env python3
import connexion
def get_pets():
return [] # your code here
if __name__ == '__main__':
app = connexion.App(__name__, 8080,
specification_dir='./swagger/')
app.add_api('swagger.yaml', arguments={'title': 'your API title'})
app.run()
I hope it helps.
@Swalloow @ujjwal08 Does @leonardofoderaro's solution help? Could you turn this discussion into a short stackoverflow post?