Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OperationID support #9

Merged
merged 4 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions transmute_core/function/transmute_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def get_swagger_operation(self, context=default_context):
"type": "object",
"properties": {
"success": {"type": "boolean"},
"message": {"type": "string"}
"result": {"type": "string"}
},
"required": ["success", "message"]
"required": ["success", "result"]
})
})
}
Expand All @@ -117,7 +117,8 @@ def get_swagger_operation(self, context=default_context):
"consumes": consumes,
"produces": produces,
"parameters": parameters,
"responses": responses
"responses": responses,
"operationId": self.raw_func.__name__
})

def process_result(self, context, result_body, exc, content_type):
Expand Down
8 changes: 5 additions & 3 deletions transmute_core/swagger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import jinja2
import os

from swagger_schema import Swagger, Info


CURDIR = os.path.dirname(__file__)


Expand Down Expand Up @@ -69,13 +71,13 @@ def paths(self):
"""
return self._swagger

def swagger_definition(self, title="example", version="1.0"):
def swagger_definition(self, title="example", version="1.0", base_path=None):
"""
return a valid swagger spec, with the values passed.
"""
return Swagger({
"info": Info({"title": title, "version": version}),
"paths": self.paths,
"swagger": "2.0",
"basePath": "/",
"basePath": "/" if base_path is None else base_path,
}).to_primitive()
8 changes: 7 additions & 1 deletion transmute_core/tests/test_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import inspect
import pytest
from transmute_core.function import TransmuteFunction

import transmute_core
from transmute_core.function import TransmuteFunction


@transmute_core.describe(paths="/")
Expand Down Expand Up @@ -47,6 +48,11 @@ def test_swagger_schema_has_object(func):
}


def test_swagger_operation_has_operation_id(func):
op = func.get_swagger_operation()
assert op.operationId == "raw_func"


def test_swagger_schema_path(func):
swagger = func.get_swagger_path()
assert swagger.get.responses["200"].schema.to_primitive() == {
Expand Down
13 changes: 11 additions & 2 deletions transmute_core/tests/test_swagger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import swagger_schema
from transmute_core import default_context
from transmute_core.swagger import (
generate_swagger_html, get_swagger_static_root,
SwaggerSpec
)
import swagger_schema
from transmute_core import default_context


def test_generate_swagger():
Expand Down Expand Up @@ -87,6 +87,15 @@ def test_swagger_add_path(transmute_func):
}


def test_basepath_override():
assert SwaggerSpec().swagger_definition(base_path="dummy_path") == {
'basePath': 'dummy_path',
'info': {'title': 'example', 'version': '1.0'},
'paths': {},
'swagger': '2.0'
}


def test_swagger_get_post(transmute_func, transmute_func_post):
"""
adding different paths of diffrent methods should have both
Expand Down