Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
- #42
- cause: empty operationId with tags would cause scope_compose returns
duplicated scopes.
- fix: it’s meaningless to add and Operation with empty operationId
into ScopeDict
  • Loading branch information
ml authored and ml committed Oct 8, 2015
1 parent bad0be2 commit 45d1124
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pyswagger/scanner/type_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def _op(self, path, obj, _):
scope = obj.tags[0] if obj.tags and len(obj.tags) > 0 else None
name = obj.operationId if obj.operationId else None

# in swagger 2.0, both 'operationId' and 'tags' are optional.
# When 'operationId' is empty, it causes 'scope_compose' return something
# duplicated with other Operations with the same tag.
if not name:
return

new_scope = scope_compose(scope, name, sep=self.__sep)
if new_scope:
if new_scope in self.op.keys():
Expand Down
27 changes: 27 additions & 0 deletions pyswagger/tests/data/v2_0/schema/emptyOp/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"swagger":"2.0",
"host":"http://test.com",
"basePath":"/v1",
"paths":{
"/t":{
"get":{
"tags":[
"v1",
"v2"
]
},
"put":{
"tags":[
"v3"
]
},
"post":{
"tags":[
"v1",
"v2",
"v3"
]
}
}
}
}
10 changes: 9 additions & 1 deletion pyswagger/tests/v2_0/test_op_access.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyswagger import SwaggerApp, utils
from pyswagger import SwaggerApp, utils, errs
from ..utils import get_test_data_folder
import unittest
import os

def _check(u, op):
u.assertEqual(op.operationId, 'addPet')
Expand Down Expand Up @@ -45,3 +46,10 @@ def test_special_char(self):
self.app.resolve(utils.jp_compose(['#', 'paths', '/user/{username}'])).get.operationId,
'getUserByName'
)

def test_empty_operation_id(self):
""" when operationId is empty, should not raise SchemaError """
try:
app = SwaggerApp.create(get_test_data_folder(version="2.0", which=os.path.join("schema", "emptyOp")))
except errs.SchemaError:
self.fail("SchemaError is raised when 'operationId' is empty and 'tags' is not")

0 comments on commit 45d1124

Please sign in to comment.