Commit Graph

114 Commits

Author SHA1 Message Date
Daniel Grossmann-Kavanagh
ab430afaf5 Fixes #1020, OAS3 false positive for extra form param (#1124)
When using an OAS3 spec with formdata, the validation logic looks
for the key 'formData' in the spec parameters list. This keys is
specific to OAS2, and will never be present, causing any form data to
throw an ExtraParameterProblem.
2020-01-21 09:49:46 +01:00
Daniel Grossmann-Kavanagh
1abab0653f scope deepObject defaults code to query params only (#1110)
* scope deepObject defaults code to query params only (fixes spread of defaults into other parameters)

* make default param test strict
2020-01-20 10:21:08 +01:00
Henning Jacobs
f55cb1c923 Merge pull request #1075 from mblaettler/feat/enable-empty-security
enable empty security definition
2020-01-06 13:39:20 +01:00
Michael Blättler
b14e235108 enable empty security definition
This allows to use optional authentication and provide different
responses to authenticated users via the same API-Endpoint.

Co-Authored-By: Jacob Floyd <cognifloyd@gmail.com>
2019-12-18 08:15:09 +01:00
Daniel Grossmann-Kavanagh
e85960947f Merge branch 'master' into dynamic_ui_path 2019-12-17 11:42:35 +11:00
Daniel Grossmann-Kavanagh
d287fcc4bd Revert "Fixes #510 in upstream: multiple file uploads via POST now work correctly. (#1000)" (#1101)
This reverts commit 4a1c69e372.
2019-12-13 08:30:49 +01:00
Daniel Grossmann-Kavanagh
154d367a9e use yaml.BaseLoader in test to remove warning 2019-12-11 18:16:15 -08:00
Daniel Grossmann-Kavanagh
c672c85c00 add tests for reverse proxies 2019-12-11 17:58:15 -08:00
Jyhess
d18c387d94 Return tuple for aiohttp (#849)
* Support aiohttp handlers to return tuples

* Minor update from #828 review

* Factorize more code between Flask and AioHttp response

* Fix CI

* Drop six string types

* Standardize response logging

* Handle one-tuples that only contain data

* clean up a couple of type hint comments

* Add a few more get_response tests

* Adjust _prepare_body interface to simplify improving _serialize_data

Rename _jsonify_data to _serialize_data to make its purpose easier to
understand (this was also known as _cast_body in aiohttp_api).

In exploring how to harmonize json serialization between aiothttp and
flask, we needed to be able to adjust the mimetype from within
_serialize_data. Harmonizing the actual serialization has to wait until
backwards incompatible changes can be made, but we can keep the new
interface, as these functions were introduced in this PR (#849).

* Add deprecation warnings about implicit serialization
2019-12-11 12:54:44 +01:00
Peter Bašista
738f47ed50 Do not sanitize body keys in OpenAPI 3 (#1008)
* Remove the unused "query_sanitazion" fixture

* Test whether no sanitization is performed in the request body

* Do not perform sanitization on request body keys in OpenAPI v3

The deserialized JSON form of the request body
needs to be passed to the client applications
* without further modification *
so that they can work directly with objects
that have been received over the network.
The only names for which sanitization makes sense
are the ones which are used as Python identifiers.

Keys of the top-level JSON object within the request payload
are never used by Connexion as Python identifiers.

Also, no such sanitization of keys within request body
is performed in OpenAPI v2.

Closes issue #835.
2019-12-03 05:01:49 +01:00
Christian Siegel
67f48ae24d Add swagger_ui_config option to pass config to the Swagger UI (#948)
* Add swagger_ui_config option to configure the Swagger UI

There was no possibility to configure the Swagger UI. Through
this new option a config object can be passed to the UI via
a `swagger-ui-config.json` file.

* Add tests for swagger_ui_config option
2019-11-05 10:12:59 +01:00
simondrabble
4a1c69e372 Fixes #510 in upstream: multiple file uploads via POST now work correctly. (#1000) 2019-11-05 10:08:17 +01:00
Svendegroote91
e06ec6da82 #594 & #816 - Add error path to schema validation error in RequestBodyValidator (#1063)
* Add error path to schema validation error in RequestBodyValidator

* Add unit test for error path in schema validation
2019-10-27 12:07:12 +01:00
Fabian Wollert
54e50f2278 handle deepObject and explode: true (#971)
* first implementation draft

* gitignore virtualenv

* use isinstance instead of type function

* fix tests

* remove unused function

* move object parsing to uri_parsing.py

* remove not needed import

* only test for OpenAPI

* remove not needed import

* make it work for other cases again

* flake8 fixes

* python2.7 fixes

* isort fix

* address code review comments

* remove for loop and address other comments

* remove not needed abstract function

* move array unnesting into uri_parsing

* make nested arrays possible

* style fixes

* style fixes

* test other data types

* comment and simplify function

* WIP: start additionalProperties test

* test additionalProperties

* remove uneccessary exception

* set default values

* set default values also in response

* flake8 fixes

* fix test

* use suggestions from dtkav's branch

* fix tests partially

* fix tests partially

* fix tests

* fix tests

* add comments for clarity
2019-10-15 17:36:58 +02:00
João Santos
1bda0659d5 Fix broken tests (#933)
* Remove extra space in error.

* Fix tests due to new behaviour of external dependencies
2019-05-05 19:38:42 +02:00
Daniel Grossmann-Kavanagh
08e4536e5e bump and pin isort, apply all automatic fixes (#903)
Fixes the build.

Changes proposed in this pull request:
 - apply all of the isort changes that resulted from the latest version
 - pin to the latest version (4.3.15) so this doesn't happen again, unless we bump the version on purpose
2019-03-15 13:04:33 +01:00
Roberto Polli
b18d8b9528 Serve yaml spec. (#842)
* Fix: #772. Serving yaml spec.

Serve yaml spec with a yaml prettifier. Uses a separate method for
doing the job and does not modify the openapi_json one.
2019-01-24 08:31:02 +01:00
panpann
089840b0a2 add path to API only for HTTP operations (#817)
* add path to API only for HTTP operations
2018-12-18 09:58:54 +01:00
Christoph Ziebuhr
cca92c0777 Fix passing empty object body (#815)
Having a json request with an empty object body `{}` resulted in having `None` passed as body argument.
2018-12-18 08:27:10 +01:00
krise3k
b6530d32aa Fix handling additionalProperties in body (#789)
Currently when object is send as body parameter only properties defined in `properties` in body schema are passed to handler function. Additional keys are filtered out, which is opposite to [spec](https://github.com/OAI/OpenAPI-Specification/blame/3.0.2/versions/3.0.2.md#L2305). For me specification is counter intuitive :(

Changes proposed in this pull request:
 - If `additionalProperties` is not set or is `True`, all properties not defined in `properties` are passed without type casting.
 - If `additionalProperties` declares value type,  unknown properties are cast according to https://github.com/zalando/connexion#type-casting.

The best explanation for `additionalProperties` I found in https://github.com/OAI/OpenAPI-Specification/issues/668#issuecomment-218829120
2018-11-28 13:32:34 +01:00
krise3k
6ec11825b8 Add support for JWT authentication (#732)
* Add support for JWT

* Add example for JWT

* Add minimal JWT documentation
2018-11-12 08:53:50 +01:00
Daniel Grossmann-Kavanagh
53dffc0b78 Only pass body on PATCH/POST/PUT request (#761)
Fixes #757
2018-11-09 08:27:08 +01:00
João Santos
44ea9336fe Connexion 2.0 (#619)
- App and Api options must be provided through the "options" argument (``old_style_options`` have been removed).
- You must specify a form content-type in 'consumes' in order to consume form data.
- The `Operation` interface has been formalized in the `AbstractOperation` class.
- The `Operation` class has been renamed to `Swagger2Operation`.
- Array parameter deserialization now follows the Swagger 2.0 spec more closely.
  In situations when a query parameter is passed multiple times, and the collectionFormat is either csv or pipes, the right-most value will be used.
  For example, `?q=1,2,3&q=4,5,6` will result in `q = [4, 5, 6]`.
  The old behavior is available by setting the collectionFormat to `multi`, or by importing `decorators.uri_parsing.AlwaysMultiURIParser` and passing `parser_class=AlwaysMultiURIParser` to your Api.
- The spec validator library has changed from `swagger-spec-validator` to `openapi-spec-validator`.
- Errors that previously raised `SwaggerValidationError` now raise the `InvalidSpecification` exception.
  All spec validation errors should be wrapped with `InvalidSpecification`.
- Support for nullable/x-nullable, readOnly and writeOnly/x-writeOnly has been added to the standard json schema validator.
- Custom validators can now be specified on api level (instead of app level).
- Added support for basic authentication and apikey authentication
- If unsupported security requirements are defined or ``x-tokenInfoFunc``/``x-tokenInfoUrl`` is missing, connexion now denies requests instead of allowing access without security-check.
- Accessing ``connexion.request.user`` / ``flask.request.user`` is no longer supported, use ``connexion.context['user']`` instead
2018-11-05 14:50:42 +01:00
Pavel Melnikov
6675ccc800 Fix body validator different error codes for bad Content-Types. (#629)
Fixes #628 .

 - Added a test for this bug.
 - Fixed it by checking for non-empty HTTP POST payload by considering request.body, request.form and request.files (only request.body was checked)
2018-08-14 13:22:03 +02:00
Daniel Grossmann-Kavanagh
212820bf35 add more test cases for form params 2018-07-25 08:50:30 +02:00
Diogo Dutra
e326711aa4 Increase the code coverage (#631)
removed the validate_defaults method from Operation because the new swagger_spec_validation version do this validation
    added tests for AbstractApi._handle_add_operation_error
2018-07-21 13:15:55 +02:00
Pavel Melnikov
0c352cd4da Correct validator response on bad JSON (#610)
* report 400 Bad Request if validation fails to parse JSON while Content-Type is json.
2018-07-10 09:43:44 +02:00
Daniel Grossmann-Kavanagh
2f074998e3 URI parsing decorator (#613)
- array logic refactored into one place.
- validation.py and parameter.py no longer try to join the array, and the split it again.
- validation of defaults now works, because the validator is given the correct type.
- some additional classes that change the behavior of deduplicating query parameters that are defined multiple times
  - **AlwaysMultiURIParser** that is backwards compatible, warts and all (used by default)
  - **Swagger2URIParser** that adheres to the spec's definition of `collectionFormat: multi` and uses the last-defined query parameter value (ex. `query?a=1&a=2` => `a = 2`)
  - **FirstValueURIParser** that behaves like Swagger2URIParser, except that the first-defined value is used (ex. `query?a=1&a=2` => `a=1`)
2018-07-09 11:06:24 +02:00
Daniel Grossmann-Kavanagh
0b19ed489a Update to swagger-spec-validator 2.3.1 (fixes #612) (#611) 2018-07-03 08:21:43 +02:00
Shaun Kaasten
a4cabb23ae Allow token_info response to use 'scopes' key (#565) 2018-02-08 16:30:00 +01:00
John Krukoff
94f64b80e1 Allow http.HTTPStatus enums as response status codes. (#504)
* Allow http.HTTPStatus enums as response status codes.

Python 3.5 introduced a new enumeration "http.HTTPStatus" for
representing HTTP response status codes. The default response validation
introduced in connexion 1.1.12 highlighted the fact that connexion does
not natively support this type and was previously silently ignoring
non-integer status code representations.

This modifies the response validation code to extract the value when
given an enum instead of an int. Somewhat hacky test code is added to
check for enum support on python versions that include
"http.HTTPStatus".

* [master]: Restructure tests from PR comments.

* [master]: Revert to exception based version checking.

This reverts to exception based python version checking for both tests,
due to the suggested unittest skipping alternative not being supported
in all python versions.

"unittest.case.SkipTest: Not supported in this version" is the error
reported.

* [master]: Move enum handling deeper into the stack.

* [master]: Respond to yet more PR comments.
2017-10-05 09:08:59 +02:00
Lance Hannestad
f36c24685b Preserving the multiplicity of array type query parameters (#500)
* Preserving the multiplicity of array type query parameters

* Resolved failing tests, and refactored code block into a method

* Added tests for multi array

* Refactored parameter.py and updated tests in test_parameters.py
2017-09-08 15:18:47 +02:00
Ronaldo Ferreira
f2923148f8 Fix UnicodeEncodeError for query-strings on Python 2 (#507)
* Fix UnicodeEncodeError for query-strings on Python 2

* Fix test for Python 3.4 and 3.5
2017-08-28 18:52:10 +02:00
Fiete Gruenter
07ce38b484 Move import to top level. 2017-08-15 09:09:12 +02:00
Fiete Gruenter
ee72325345 Implement hacky workaround for passing environ to test_client.open() for no-content-type-test since old flask<=0.12.2 does not support it. 2017-08-04 09:30:25 +02:00
Fiete Gruenter
bf66cc726d Add a test that posts a requests without sending Content-Type in the header. 2017-08-03 12:43:48 +02:00
Tony Tung
6668835420 Validate responses against the default response field if the code is not found. (#487) 2017-07-20 22:58:22 +02:00
Rodrigo di Lorenzo Lopes
9a8bddf509 solving fixed argument (server) for FlaskApp (backward incompatible and undesired change) 2017-06-06 14:44:17 +02:00
Kyle Cacciatore
1f34e3565b 449 path format (#450)
* added test for path formatted parameters

* re-added removed test, as it would generate valid flask route
2017-05-10 22:04:48 +02:00
Rafael Carício
93c06711ed New style of passing options to Connexion (#436)
* Order classes by relevance in module

* Order definitions by relevance within module

* Swagger UI options extracted

* New style options

* Use new-style options

* Reuse code

* Sort imports

* Ignore typing imports

* Warn users about parameter name change

* Add back isort check

* Fix isort check
2017-04-11 16:47:21 +02:00
Rafael Carício
63abcad512 Connexion request user (#435)
* Add back connexion.request

* Refactor code to lifecycle module

* Test user from connexion.request instance
2017-04-07 16:15:09 +02:00
Rafael Carício
067ad1b55a Flask request user support (#432)
* ConnexionRequest.context proxied to flask.request instance

* Add type annotations for FlaskRequestContextProxy

* Sort imports

* Sort imports

* Remove unnecessary code
2017-04-05 19:04:48 +02:00
Henning Jacobs
d9edc36647 Ignore context args (#429)
* #428 add unit test

* #428 ignore context param if not in function args

* #428 update OAuth2 example app

* #428 update security docs
2017-04-05 14:32:40 +02:00
Rafael Carício
1858c9d4a0 Flask required only if necessary (#424)
* Example with Flask support

* Only show import error when trying to use Flask

* Re-organize imports

* Move flask_utils next to related module

* Code style

* Change back to incentivizes

* Includes Flask by default

* Project clean up

* Update Rafael Caricio's e-mail address

* Fix conflicts
2017-04-04 20:48:08 +02:00
Landon
6f567ee4de Fix returning flask Response objects in a tuple (#425)
* Fix returning Response objects in tuple with status code and/or headers

* Use flasks code for dealing with tuples instead of my own

* Unit tests for returning flask reponse in tuple

* fix test, should be a dict, not a set

* Properly sort imports
2017-04-04 20:11:03 +02:00
Diogo Dutra
2ddebfdbe2 did changes requested by isort-check 2017-04-04 08:20:25 -03:00
Diogo Dutra
3952ea2771 did changes requested by isort and flake8 2017-04-04 08:20:25 -03:00
Diogo
5857dd237f Uncouple all flask functions from base code.
removed test_decorators and test_parameter (this test is useless now);
removed the request/response containers and add new request response classes;
created a abstract api class and a api flask class;
derived classes will implements the get_response/get_request methods that will convert framework req/resp types to connexion req/resp types;
moved the jsonifier from produces to flask api;
created a abstract app class and a app flask class;
changed all validators to use the ConnexionRequest instead flask request;
changed the problem function to generate a ConnexionRequest;
created a new user variables container called context (this is a property of ConnexionRequest). this will be passed as kwargs to all operations functions;
this context is used on authentication;
fixed all tests to new API;
some changes that I did may not be documented in this commit.
2017-04-04 08:20:24 -03:00
Diogo Dutra
a7af62fbf0 Uncouple flask from App and Api. Created Abstract classes for theses modules. Fixed the tests 2017-04-04 08:20:23 -03:00
Rafael Carício
711bbf08e7 Merge pull request #404 from Griffon26/master
Remove unnecessary dependency on strict-rfc3339
2017-03-21 10:56:20 +01:00