From 8722d2c347aa526ca57952914f07ed7592f90fd6 Mon Sep 17 00:00:00 2001 From: Lois Postula Date: Wed, 24 May 2017 14:36:00 +0200 Subject: [PATCH 1/2] Allow to encode custom attributes dict on Field object and Link --- openapi_codec/encode.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/openapi_codec/encode.py b/openapi_codec/encode.py index 4a6fbec..1bbca24 100644 --- a/openapi_codec/encode.py +++ b/openapi_codec/encode.py @@ -79,6 +79,7 @@ def _get_paths_object(document): def _get_operation(operation_id, link, tags): encoding = get_encoding(link) description = link.description.strip() + custom_attributes = link.custom_attributes summary = description.splitlines()[0] if description else None operation = { @@ -95,6 +96,9 @@ def _get_operation(operation_id, link, tags): operation['consumes'] = [encoding] if tags: operation['tags'] = tags + if custom_attributes: + for key in custom_attributes: + operation[key] = custom_attributes[key] return operation @@ -127,6 +131,10 @@ def _get_field_type(field): }.get(field.schema.__class__, 'string') +def _get_field_custom_attributes(field): + return getattr(field, 'custom_attributes', None) + + def _get_parameters(link, encoding): """ Generates Swagger Parameter Item object. @@ -139,6 +147,7 @@ def _get_parameters(link, encoding): location = get_location(link, field) field_description = _get_field_description(field) field_type = _get_field_type(field) + field_custom_attributes = _get_field_custom_attributes(field) if location == 'form': if encoding in ('multipart/form-data', 'application/x-www-form-urlencoded'): # 'formData' in swagger MUST be one of these media types. @@ -189,6 +198,10 @@ def _get_parameters(link, encoding): } if field_type == 'array': parameter['items'] = {'type': 'string'} + if field_custom_attributes: + # custom attributes can only be set when location is not body + for key in field_custom_attributes: + parameter[key] = field_custom_attributes[key] parameters.append(parameter) if properties: From a5798025cbe5d0bf309860c8791f33007874827f Mon Sep 17 00:00:00 2001 From: Lois Postula Date: Wed, 24 May 2017 14:59:05 +0200 Subject: [PATCH 2/2] Sanitize the way custom attributes are get, if coreapi is not up to date --- openapi_codec/encode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_codec/encode.py b/openapi_codec/encode.py index 1bbca24..2bb44e6 100644 --- a/openapi_codec/encode.py +++ b/openapi_codec/encode.py @@ -79,7 +79,7 @@ def _get_paths_object(document): def _get_operation(operation_id, link, tags): encoding = get_encoding(link) description = link.description.strip() - custom_attributes = link.custom_attributes + custom_attributes = getattr(link, 'custom_attributes', None) summary = description.splitlines()[0] if description else None operation = { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy