Commit Graph

42 Commits

Author SHA1 Message Date
Robbe Sneyders
022bb8f34a Coerce types only in uri parser (#1627)
This PR moves all type coercing into the URI parsers and makes sure it's
only done once for each code path.
2023-01-30 08:49:49 +01:00
Robbe Sneyders
edb0381af3 Implement user facing interface for ConnexionMiddleware (#1621)
This PR adds an interface for the ConnexionMiddleware, similar to the
interface of the Connexion Apps.

The Connexion Apps are now a simple wrapper around the
ConnexionMiddleware and framework app, delegating the work to the
middleware. This enables a similar interface and behavior for users when
using either the middleware or apps.

The arguments are repeated everywhere there is a user interface, but are
parsed in a central place. Repeating the arguments is not DRY, but
needed to provide users with IDE autocomplete, typing, etc. They are
parsed in a single `_Options` class, which also provides a mechanism to
set default options on an App level, and override them on the more
granular API level.

This makes the long list of provided parameters a lot more manageable,
so I would like to use it for the `Jsonifier` as well, and re-add the
`debug` and `extra_files` arguments which I have dropped in previous
PRs. I'll submit a separate PR for this.

I renamed the `options` parameter to `swagger_ui_options` since it only
contains swagger UI options. This is a breaking change though, and we'll
need to highlight this upon release.

We still have quite a lot of `App`, `MiddlewareApp`, and abstract
classes. It would be great if we could find a way to reduce those
further, or at least find better naming to make it more clear what each
one does 🙂 .

Finally, I added examples on how the middleware can be used with third
party frameworks under `examples/frameworks`. Currently there's an
example for Starlette and Quart, but this should be easy to extend. They
also show how the `ASGIDecorator` and `StarletteDecorator` from my
previous PR can be used.
2023-01-26 14:40:29 +01:00
Robbe Sneyders
7acbad0691 Move parameter decorator related methods out of operation classes 2022-12-23 11:15:10 +01:00
Robbe Sneyders
2581a7e4c4 Move parameter validation to middleware 2022-11-14 23:15:31 +01:00
Robbe Sneyders
600ed4ed94 Format files with black 2022-06-25 23:50:52 +02:00
Nicolas Noirbent
a1dddf62d4 lifecycle: add cookies attribute to ConnexionRequest (#1168) (#1209)
Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2022-02-23 22:45:34 +01:00
Davy Durham
eb97cf9f74 Fix for aiohttp and multipart/form-data uploads (#1222)
* Added unit tests to demonstrate the problems of https://github.com/zalando/connexion/issues/975
    - Taken mostly from existing PR: https://github.com/zalando/connexion/pull/987

* now splitting out multipart POSTs into files[] and form[], handling duplicate keys as the rest of connexion expects
    - Based parly on existing PR: https://github.com/zalando/connexion/pull/987

* rewrote how operations/openapi.py::_get_body_argument() works to better build the arguments[] list according to what the spec says and what the handler accepts.  This fixes a bug when requests contain mixed files and form values and the handler is expecting variable names matching the request property names.

* Adding unit tests to improve code converage test

* post merge fixes - using 'async' keyword now in new unit test file

* unit test improvements -- now testing the contents of the files we upload too

* making some code a bit clearer regarding duplicate names of file submissions

* fixing up unit tests since merging main

* fixing isort-check-tests and flake8

* clarified a comment

* comment correction

* after discussions with maintainer, reverted _get_body_argument back to the original where it does not attempt to break out the body into individual arguments for the handler.  But left in changes that make the normal behavior of not passing a body argument to a handler without one more consistent when the body itself is empty or not an object type.

* fixing unit tests after after reverting _get_body_argument behavior
2022-02-18 17:44:51 +01:00
Ruwann
1f07bde2cb Fix sanitization of function arguments (#1442)
* Add test for incorrectly cased params with pythonic_params

* Fix 1307: only sanitize when checking view func arguments

* Don't sanitize original request form

* Fix OpenAPI3 test fixture for form data

* Fix view function for test
2022-02-01 23:20:40 +01:00
Daisie Huang
4fd5d63ce7 #1424: add keywords to the list of pythonic words (#1425)
* #1424: add keywords to the list of pythonic words

* reorder imports

* add test query parameter

* add test query parameter "class"

* add class query param to test

* add class query param to openapi spec

* Update connexion/decorators/parameter.py

Co-authored-by: Ruwann <ruwan.lambrichts@ml6.eu>

Co-authored-by: Ruwann <ruwan.lambrichts@ml6.eu>
2021-09-13 20:28:11 +02:00
Christian Clauss
8c49a61156 Tox.ini: Run mypy in ignore_outcome mode (#1405)
* Tox.ini: Run mypy in allow errors mode

* py39: mypy

* touch .mypy_cache

* Make sure .mypy_cache exists

* Update tox.ini

* mkdir .mypy_cache

* mkdir .mypy_cache

* mkdir .mypy_cache

* mypy --install-types --non-interactive . || true

* mypy --exclude=/examples/ --install-types --non-interactive . || true

* mypy --exclude /examples/ --install-types --non-interactive .

* mypy --exclude /examples/* --install-types --non-interactive .

* mypy --exclude '/app\.py$' --install-types --non-interactive .

* mypy --exclude '/(app|hello)\.py$' --install-types --non-interactive .

* mypy --exclude '/(api|app|hello)\.py$' --install-types --non-interactive .

* mypy --exclude '/(__init__|api|app|hello)\.py$' --install-types --non-interactive .

* mypy --exclude '/(__init__|api|api.pets|app|hello)\.py$' --install-types --non-interactive .

* mypy --exclude '/(__init__|api|api.pets|app|hello|resty)\.py$' --install-types --non-interactive .

* mypy --exclude '/(__init__|api|api.pets|app|hello|orm|resty)\.py$' --install-types --non-interactive .

* Update pipeline.yml

* Update tox.ini

* Update pipeline.yml

* Update tox.ini

* Update mypy invocation and fix typing errors

Make it such that mypy will not return an exit code 2, which
indicates a failure in running mypy itself.

Co-authored-by: Ruwan <ruwanlambrichts@gmail.com>
2021-08-23 14:20:05 +02:00
Logi Ragnarsson
a8375a1beb More liberal flask number converters for float and int in paths (#1306)
* Use more liberal flask converters for float and int

These don't try to enforce a "single representation" of paths but instead try to convert the numbers that callers pass in.

Addresses #1040 and #1041

* Use f-strings instead of string concat or %-formats

* Complying with style rules added long after this PR was made
2021-07-14 21:02:54 +02:00
Christian Clauss
6c4f99051d Upgrade syntax for Python >= 3.6 (#1383)
* pyupgrade --py36-plus **/*.py

* Fix indentation

* Fix indentation
2021-07-04 20:04:22 +02:00
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
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
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
simondrabble
4a1c69e372 Fixes #510 in upstream: multiple file uploads via POST now work correctly. (#1000) 2019-11-05 10:08:17 +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
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
Daniel Grossmann-Kavanagh
212820bf35 add more test cases for form params 2018-07-25 08:50:30 +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
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
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
Dan Ballance
702142ec48 Fixes #340 | Convert camelcased parameter names to Python style 2017-03-09 16:42:17 +00:00
Leena Bhegade
f7b3d9a0bb add parameter to decode 2017-02-08 23:48:04 +00:00
Leena Bhegade
c1020bf0f6 Fix tests 2017-02-08 21:31:35 +00:00
Michael Wild
b638b1168e Adds parameter name sanitization in parameters_to_args()
Without sanitization e.g. OData query parameters, such as $skip, $top,
$filter cannot be passed to the controller (except by use of **kwargs).

Fixes: zalando/connexion#334
2016-10-31 15:16:03 +01:00
Rafael Caricio
c02fad46f7 Fix import ordering 2016-09-13 11:12:45 +02:00
Henning Jacobs
b5cd358b4f #270 add test for kwargs 2016-09-01 12:06:04 +02:00
Dylan Semler
b7c6dede95 Add flag for strict_validation on extra parameters 2016-07-31 20:21:19 -04:00
Dylan Semler
f1d436c859 Validate that requests don't have extra parameters
Request validation is enhanced to verify requests only include query or
formData parameters that are specified in the spec.

This validation does not occur for header or path parameters.  This is
because most applications probably prefer to ignore extra headers and
a request with extra path parameters would point to a different
endpoint.
2016-07-31 20:17:30 -04:00
Greg Brockman
a6cc07cca8 Make JSON printing a bit nicer 2016-04-04 21:59:54 -07:00
João Santos
ddcb4ce4a5 Merge pull request #197 from rafaelcaricio/accept-nullable-values
Support nullable parameters
2016-03-31 14:10:17 +02:00
David Hotham
75fe338937 Python3 compatibility 2016-03-29 12:21:31 +01:00
David Hotham
c3ced5fc2d Add validation of formData parameters 2016-03-29 11:58:33 +01:00
David Hotham
604e7274f1 Unit tests for file uploads 2016-03-29 10:09:56 +01:00
Rafael Caricio
75c94a428b Support x-nullable in body parameters 2016-03-25 19:31:33 +01:00
Rafael Caricio
7052ff3722 Support x-nullable parameters 2016-03-25 18:07:35 +01:00
João Santos
625c60beaa #173 Fix unpythonic function names 2016-03-08 08:33:46 +01:00
Rafael Caricio
2558a611f4 #104 typecasting in path parameters 2016-03-04 18:41:57 +01:00
Rafael Caricio
a7aec5d53c Split tests in isolated modules 2016-02-25 14:49:19 +01:00