Skip to content

Commit

Permalink
fix up rebase errors, raw examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Grossmann-Kavanagh committed Jul 18, 2018
1 parent 9336eac commit 64d674d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
9 changes: 1 addition & 8 deletions connexion/apis/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ def __init__(self, specification, base_path=None, arguments=None,

self.spec_version = self._get_spec_version(self.specification)

self.options = ConnexionOptions(old_style_options, oas_version=self.spec_version)
# options is added last to preserve the highest priority
self.options = self.options.extend(options)

# TODO: Remove this in later versions (Current version is 1.1.9)
if base_path is None and 'base_url' in old_style_options:
base_path = old_style_options['base_url']
logger.warning("Parameter base_url should be no longer used. Use base_path instead.")
self.options = ConnexionOptions(options, oas_version=self.spec_version)

logger.debug('Options Loaded',
extra={'swagger_ui': self.options.openapi_console_ui_available,
Expand Down
22 changes: 16 additions & 6 deletions connexion/operations/openapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
import codecs
import json
import logging
from copy import deepcopy

import six
from jsonschema import ValidationError

from connexion.operations.abstract import AbstractOperation
Expand Down Expand Up @@ -101,8 +103,7 @@ def component_get(oas3_name):
'parameters': component_get('parameters'),
'securitySchemes': component_get('securitySchemes'),
'responses': component_get('responses'),
'headers': component_get('headers'),
'examples': component_get('examples')
'headers': component_get('headers')
}
}

Expand Down Expand Up @@ -186,7 +187,7 @@ def _spec_definitions(self):

def _validate_defaults(self):
# TODO also validate requestBody defaults
# TODO this should be upstreamed into openapi-spec-validator
# TODO@dtkav remove with openapi-spec-validator 0.2.3
for param_defn in self.parameters:
try:
param_schema = param_defn["schema"]
Expand Down Expand Up @@ -273,8 +274,17 @@ def example_response(self, code=None, content_type=None):
code = 200
try:
# TODO also use example header?
example_raw = self._resolve_reference(list(deep_get(self._responses, examples_path).values())[0])['value']
return self.api.json_loads(codecs.decode(example_raw, 'unicode-escape')), code
example = self._resolve_reference(
list(deep_get(self._responses, examples_path).values())[0]
)['value']
if isinstance(example, six.string_types):
try:
# attempt to decode in case example is raw
example = self.api.json_loads(codecs.decode(example, 'unicode-escape')), code
return example
except json.decoder.JSONDecodeError:
pass
return example, code
except (KeyError, IndexError):
pass
try:
Expand Down
1 change: 1 addition & 0 deletions connexion/operations/swagger2.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def produces(self):
return self._produces

def _validate_defaults(self):
# TODO@dtkav remove with openapi-spec-validator 0.2.3
for param_defn in self.parameters:
try:
if param_defn['in'] == 'query' and 'default' in param_defn:
Expand Down
1 change: 1 addition & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jinja2
import yaml
from openapi_spec_validator.exceptions import ValidationError

import pytest
from conftest import TEST_FOLDER, build_app_from_fixture
Expand Down
6 changes: 1 addition & 5 deletions tests/decorators/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ class Op(object):
def get_arguments(self, *args, **kwargs):
return {"p1": "123"}

parameter_to_arg(Op(), handler)(request)

func.assert_called_with(p1='123')

parameter_to_arg({}, [], handler, pass_context_arg_name='framework_request_ctx')(request)
parameter_to_arg(Op(), handler, pass_context_arg_name='framework_request_ctx')(request)
func.assert_called_with(p1='123', framework_request_ctx=request.context)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_invalid_operation_does_not_stop_application_in_debug_mode():
def test_other_errors_stop_application_to_setup():
# Errors should still result exceptions!
with pytest.raises(InvalidSpecification):
FlaskApi(TEST_FOLDER / "fixtures/bad_specs/swagger.yaml",
FlaskApi(TEST_FOLDER / "fixtures/bad_specs/openapi.yaml",
base_path="/api/v1.0", arguments={'title': 'OK'})


Expand Down
20 changes: 10 additions & 10 deletions tests/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ def test_mock_resolver():
'application/json': {
'examples': {
"super_cool_example": {
'foo': 'bar'
'value': {'foo': 'bar'}
}
}
}
}
}
}

operation = OpenAPIOperation(api=None,
method='GET',
path='endpoint',
path_parameters=[],
operation={
'responses': responses
},
app_security=[],
resolver=resolver)
operation = OpenAPIOperation(
api=None,
method='GET',
path='endpoint',
path_parameters=[],
operation={'responses': responses},
app_security=[],
resolver=resolver
)
assert operation.operation_id == 'mock-1'

response, status_code = resolver.mock_operation(operation)
Expand Down

0 comments on commit 64d674d

Please sign in to comment.