Skip to content

Commit

Permalink
Merge pull request #11 from danleonard-nj/parameter-bug-fix
Browse files Browse the repository at this point in the history
Parameter bug fix
  • Loading branch information
danleonard-nj authored Jun 26, 2022
2 parents dd0be9c + 214723b commit 465e987
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
17 changes: 9 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from setuptools import setup, find_packages

VERSION = '0.1.1'
VERSION = '0.1.2'
DESCRIPTION = 'Swagger UI for Flask apps'
LONG_DESCRIPTION = 'Automatically generate Swagger UI documentation for a Flask app. Batteries included.'

setup(
name="swagger-gen",
name='swagger-gen',
python_requires='>=3.9.0',
version=VERSION,
author="Dan Leonard",
author_email="dcl525@gmail.com",
author='Dan Leonard',
author_email='dcl525@gmail.com',
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
package_data={'swagger_gen': ['./resources/swagger.pkl']},
packages=find_packages(),
install_requires=['flask'],
keywords=['python', 'swagger-gen'],
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
'Development Status :: 3 - Alpha',
'Programming Language :: Python :: 3',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
]
)
5 changes: 4 additions & 1 deletion swagger_gen/lib/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from swagger_gen.lib.utils import element_at, not_null
from swagger_gen.lib.utils import (
element_at,
not_null
)
from swagger_gen.lib.constants import Method
from werkzeug.routing import Rule
from typing import List
Expand Down
12 changes: 6 additions & 6 deletions swagger_gen/lib/metadata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from functools import wraps
from importlib.metadata import metadata
from typing import Callable, Iterable, List, Union

from numpy import isin
from swagger_gen.lib.endpoint import SwaggerEndpoint
from swagger_gen.lib.utils import not_null
from typing import (
Callable,
Iterable,
List,
Union
)


class EndpointMetadata:
Expand Down
11 changes: 7 additions & 4 deletions swagger_gen/lib/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SwaggerDefinition:
- Less likely to break shit in the schema
- Separate implementation details. i.e. generic schema objects that
should be interchangable to generate JSON, YAML, etc.
- generating the schema can be hidden.
- generating the schema can be hidden.
'''

def __init__(
Expand Down Expand Up @@ -116,7 +116,7 @@ def _add_component(
self,
component_key: str,
component_type: str,
component_model: dict):
component_model: dict) -> None:
'''Add the generated component schema to the definition'''

not_null(component_key, 'component_key')
Expand Down Expand Up @@ -166,7 +166,7 @@ def _create_endpoint_definition(
# from Flask's formatting to match Swagger conventions. Basically
# just swapping the carats for curly braces
parameters = list()
if not any(endpoint.segment_params):
if any(endpoint.segment_params):

# Generate the documentation for the route segment
path_parameters = (
Expand Down Expand Up @@ -258,6 +258,9 @@ def _add_metadata(
])
parameters.extend(query_parameters)

if any(parameters):
method_definition[Schema.PARAMETERS] = parameters

# If a request model is defined in the metadata
if metadata.request_model:
method_definition[Schema.REQUEST_BODY] = (
Expand Down Expand Up @@ -388,7 +391,7 @@ def _get_base_definition(self) -> dict:
base[Schema.INFO] = info
return base

def _get_default_responses(self):
def _get_default_responses(self) -> dict:
'''The default endpoint responses, used if no others are defined'''

# TODO: Pass down responses from create_endpoint -> _create_path, etc
Expand Down
19 changes: 12 additions & 7 deletions swagger_gen/lib/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@

from swagger_gen.lib.metadata import (
EndpointMetadata,
MetadataCollection
)
from swagger_gen.lib.utils import (
element_at,
defined,
is_type,
not_null
)
from typing import Callable
from flask import Blueprint
from functools import wraps
import inspect
import logging
from typing import Callable
from swagger_gen.lib.metadata import EndpointMetadata, MetadataCollection
from swagger_gen.lib.utils import element_at, defined, is_type, not_null
from flask import Blueprint
from inspect import FrameInfo

logger = logging.getLogger(__name__)
endpoint_metadata = MetadataCollection()
Expand Down Expand Up @@ -38,7 +44,6 @@ def get_blueprint_from_context():
'''

# Fetch the stack frame second from the top if we can
frames = inspect.stack()
caller_frame = element_at(inspect.stack(), 2)

# Short out and return null if we can't for some reason
Expand Down
5 changes: 4 additions & 1 deletion swagger_gen/swagger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from swagger_gen.lib.utils import (
is_type,
not_null
)
from swagger_gen.lib.dependency import DependencyProvider
from swagger_gen.lib.endpoint import SwaggerEndpoint
from swagger_gen.lib.schema import SwaggerDefinition
from swagger_gen.lib.utils import is_type, not_null
from typing import List
from flask import Flask

Expand Down

0 comments on commit 465e987

Please sign in to comment.