Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .codegen/server/Dockerfile.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{#supportPython2}}
FROM python:2-alpine
{{/supportPython2}}
{{^supportPython2}}
FROM python:3-alpine
{{/supportPython2}}

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/

{{#supportPython2}}
RUN pip install --no-cache-dir -r requirements.txt
{{/supportPython2}}
{{^supportPython2}}
RUN pip3 install --no-cache-dir -r requirements.txt
{{/supportPython2}}

COPY . /usr/src/app

EXPOSE {{serverPort}}

{{#supportPython2}}
ENTRYPOINT ["python"]
{{/supportPython2}}
{{^supportPython2}}
ENTRYPOINT ["python3"]
{{/supportPython2}}

CMD ["-m", "{{packageName}}"]
60 changes: 60 additions & 0 deletions .codegen/server/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# OpenAPI generated server

## Overview
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the
[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This
is an example of building a OpenAPI-enabled Flask server.

This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.

## Requirements
{{#supportPython2}}
Python 2.7+
{{/supportPython2}}
{{^supportPython2}}
Python 3.5.2+
{{/supportPython2}}

## Usage
To run the server, please execute the following from the root directory:

```
{{#supportPython2}}
pip install -r requirements.txt
python -m {{packageName}}
{{/supportPython2}}
{{^supportPython2}}
pip3 install -r requirements.txt
python3 -m {{packageName}}
{{/supportPython2}}
```

and open your browser to here:

```
http://localhost:{{serverPort}}{{contextPath}}/ui/
```

Your OpenAPI definition lives here:

```
http://localhost:{{serverPort}}{{contextPath}}/openapi.json
```

To launch the integration tests, use tox:
```
sudo pip install tox
tox
```

## Running with Docker

To run the server on a Docker container, please execute the following from the root directory:

```bash
# building the image
docker build -t {{packageName}} .

# starting up a container
docker run -p {{serverPort}}:{{serverPort}} {{packageName}}
```
Empty file.
7 changes: 7 additions & 0 deletions .codegen/server/__init__model.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding: utf-8

# flake8: noqa
from __future__ import absolute_import
# import models into model package
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}{{/model}}
{{/models}}
16 changes: 16 additions & 0 deletions .codegen/server/__init__test.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging

import connexion
from flask_testing import TestCase

from {{packageName}}.encoder import JSONEncoder


class BaseTestCase(TestCase):

def create_app(self):
logging.getLogger('connexion.operation').setLevel('ERROR')
app = connexion.App(__name__, specification_dir='../openapi/')
app.app.json_encoder = JSONEncoder
app.add_api('openapi.yaml', pythonic_params=True)
return app.app
32 changes: 32 additions & 0 deletions .codegen/server/__main__.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{#supportPython2}}
#!/usr/bin/env python
{{/supportPython2}}
{{^supportPython2}}
#!/usr/bin/env python3
{{/supportPython2}}

import connexion
{{#featureCORS}}
from flask_cors import CORS
{{/featureCORS}}

from {{packageName}} import encoder


def main():
app = connexion.App(__name__, specification_dir='./openapi/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('openapi.yaml',
arguments={'title': '{{appName}}'},
pythonic_params=True)

{{#featureCORS}}
# add CORS support
CORS(app.app)

{{/featureCORS}}
app.run(port={{serverPort}})


if __name__ == '__main__':
main()
73 changes: 73 additions & 0 deletions .codegen/server/base_model_.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import pprint

import six
{{^supportPython2}}
import typing
{{/supportPython2}}

from {{packageName}} import util
{{^supportPython2}}

T = typing.TypeVar('T')
{{/supportPython2}}


class Model(object):
# openapiTypes: The key is attribute name and the
# value is attribute type.
openapi_types = {}

# attributeMap: The key is attribute name and the
# value is json key in definition.
attribute_map = {}

@classmethod
def from_dict(cls{{^supportPython2}}: typing.Type[T]{{/supportPython2}}, dikt){{^supportPython2}} -> T{{/supportPython2}}:
"""Returns the dict as a model"""
return util.deserialize_model(dikt, cls)

def to_dict(self):
"""Returns the model properties as a dict

:rtype: dict
"""
result = {}

for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value

return result

def to_str(self):
"""Returns the string representation of the model

:rtype: str
"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
return self.__dict__ == other.__dict__

def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
116 changes: 116 additions & 0 deletions .codegen/server/controller.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import connexion
import six

{{#imports}}{{import}} # noqa: E501
{{/imports}}
from {{packageName}} import util
from {{packageName}}.core.controllers import {{classFilename}} as controller
{{#operations}}
{{#operation}}


def {{operationId}}({{#allParams}}{{paramName}}{{^required}}=None{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): # noqa: E501
"""{{#summary}}{{.}}{{/summary}}{{^summary}}{{operationId}}{{/summary}}

{{#notes}}{{.}}{{/notes}} # noqa: E501

{{#allParams}}
:param {{paramName}}: {{description}}
{{^isContainer}}
{{#isPrimitiveType}}
:type {{paramName}}: {{>param_type}}
{{/isPrimitiveType}}
{{#isUuid}}
:type {{paramName}}: {{>param_type}}
{{/isUuid}}
{{^isPrimitiveType}}
{{#isFile}}
:type {{paramName}}: werkzeug.datastructures.FileStorage
{{/isFile}}
{{^isFile}}
{{^isUuid}}
:type {{paramName}}: dict | bytes
{{/isUuid}}
{{/isFile}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isArray}}
{{#items}}
{{#isPrimitiveType}}
:type {{paramName}}: List[{{>param_type}}]
{{/isPrimitiveType}}
{{^isPrimitiveType}}
:type {{paramName}}: list | bytes
{{/isPrimitiveType}}
{{/items}}
{{/isArray}}
{{#isMap}}
{{#items}}
{{#isPrimitiveType}}
:type {{paramName}}: Dict[str, {{>param_type}}]
{{/isPrimitiveType}}
{{^isPrimitiveType}}
:type {{paramName}}: dict | bytes
{{/isPrimitiveType}}
{{/items}}
{{/isMap}}
{{/allParams}}

:rtype: {{#returnType}}{{.}}{{/returnType}}{{^returnType}}None{{/returnType}}
"""
{{#allParams}}
{{^isContainer}}
{{#isDate}}
{{paramName}} = util.deserialize_date({{paramName}})
{{/isDate}}
{{#isDateTime}}
{{paramName}} = util.deserialize_datetime({{paramName}})
{{/isDateTime}}
{{^isPrimitiveType}}
{{^isFile}}
{{^isUuid}}
if connexion.request.is_json:
{{paramName}} = {{#baseType}}{{baseType}}{{/baseType}}{{^baseType}}{{#dataType}} {{dataType}}{{/dataType}}{{/baseType}}.from_dict(connexion.request.get_json()) # noqa: E501
{{/isUuid}}
{{/isFile}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isArray}}
{{#items}}
{{#isDate}}
if connexion.request.is_json:
{{paramName}} = [util.deserialize_date(s) for s in connexion.request.get_json()] # noqa: E501
{{/isDate}}
{{#isDateTime}}
if connexion.request.is_json:
{{paramName}} = [util.deserialize_datetime(s) for s in connexion.request.get_json()] # noqa: E501
{{/isDateTime}}
{{#complexType}}
if connexion.request.is_json:
{{paramName}} = [{{complexType}}.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
{{/complexType}}
{{/items}}
{{/isArray}}
{{#isMap}}
{{#items}}
{{#isDate}}
if connexion.request.is_json:
{{paramName}} = {k: util.deserialize_date(v) for k, v in six.iteritems(connexion.request.get_json())} # noqa: E501
{{/isDate}}
{{#isDateTime}}
if connexion.request.is_json:
{{paramName}} = {k: util.deserialize_datetime(v) for k, v in six.iteritems(connexion.request.get_json())} # noqa: E501
{{/isDateTime}}
{{#complexType}}
if connexion.request.is_json:
{{paramName}} = {k: {{baseType}}.from_dict(v) for k, v in six.iteritems(connexion.request.get_json())} # noqa: E501
{{/complexType}}
{{/items}}
{{/isMap}}
{{/allParams}}
return controller.{{operationId}}(
{{#allParams}}{{paramName}}={{paramName}}{{^-last}},
{{/-last}}{{/allParams}}
)
{{/operation}}
{{/operations}}
Loading