Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate the client from the Open API definition #2

Merged
merged 2 commits into from
Sep 27, 2019
Merged
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
1 change: 1 addition & 0 deletions openapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
swagger_generation_log
70 changes: 70 additions & 0 deletions openapi/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Auto Generate Rest Client and Models with AutoRest


**Warnings: DO NOT manually edit auto-generated files**.

## Getting Started

To build the SDKs for Rest APIs, simply install AutoRest via `npm` (`npm install -g autorest`), move command prompt to ./openapi folder, and run:
> `autorest readme.md`

To see additional help and options, run:
> `autorest --help

For other options on installation see [Installing AutoRest](https://aka.ms/autorest/install) on the AutoRest github page.

## Edit Swagger Specification File for Update
- These input files are listed in swagger folder. Edit these files for updating client definition.
- You can learn [how to write this specification](https://github.com/Azure/autorest/blob/master/docs/developer/guide/defining-clients-swagger.md)

## Inputs
We want a single client to be created from the following OpenAPI definition files:

``` yaml
input-file:
- swagger.yml
```
```yaml
title: rest_client
```

## Generation
```yaml
python:
add-credentials: true
namespace: restclient
no-namespace-folders: true
output-folder: restclient
package-version: 1.5.0
base-folder: ./../sdk/burdock/
```

## Temporary output folder to save output-artifact and source maps files. Please do not check in these files.

``` yaml
output-folder: swagger_generation_log
```



### Fully resolved OpenAPI definition

To support tools unable to process multiple OpenAPI definitions or definitions with external references (`$ref: "<URI to another OpenAPI definition>#/definitions/SomeModel"`), AutoRest allows exporting a single, fully resolved OpenAPI definition without any external references that tools should be able to consume.

``` yaml
output-artifact:
- swagger-document.norm.json
- swagger-document.norm.yaml
```

### Source maps

AutoRest tries to create source maps for output artifacts. These will relate the artifact with the original input files which may be helpful for tools created around AutoRest.
For example, AutoRest uses the source map internally in order to relate validation messages back to the original files.

``` yaml
output-artifact:
- swagger-document.norm.json.map
- swagger-document.norm.yaml.map
```

46 changes: 46 additions & 0 deletions openapi/swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
swagger: "2.0"
info:
description: This is the Open API specification of the Burdock execution service.
version: "0.0.1"
title: Swagger ReST Article
consumes:
- application/json
produces:
- application/json

basePath: /api

# Paths supported by the server application
paths:
/execute:
post:
operationId: execute.run
tags:
- execute
summary: Execute a differentially private module
description: Create a run of the specified module and return the results.
parameters:
- name: details
in: body
description: Configuration for the module run.
required: True
schema:
$ref: '#/definitions/ProjectRunDetails'
responses:
200:
description: Successfully executed the run
schema:
properties:
result:
type: string
description: Json string result, TODO release document
definitions:
ProjectRunDetails:
type: object
properties:
project_uri:
type: string
description: Git url of the project
params:
type: string
description: Input parameters of the project
Empty file added sdk/README.md
Empty file.
Empty file added sdk/burdock/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions sdk/burdock/restclient/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from .rest_client import RestClient
from .version import VERSION

__all__ = ['RestClient']

__version__ = VERSION

14 changes: 14 additions & 0 deletions sdk/burdock/restclient/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from .project_run_details import ProjectRunDetails
from .executerun_ok_response import ExecuterunOKResponse

__all__ = [
'ProjectRunDetails',
'ExecuterunOKResponse',
]
24 changes: 24 additions & 0 deletions sdk/burdock/restclient/models/executerun_ok_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model


class ExecuterunOKResponse(Model):
"""ExecuterunOKResponse.

:param result: Json string result, TODO release document
:type result: str
"""

_attribute_map = {
'result': {'key': 'result', 'type': 'str'},
}

def __init__(self, result=None):
super(ExecuterunOKResponse, self).__init__()
self.result = result
28 changes: 28 additions & 0 deletions sdk/burdock/restclient/models/project_run_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model


class ProjectRunDetails(Model):
"""ProjectRunDetails.

:param project_uri: Git url of the project
:type project_uri: str
:param params: Input parameters of the project
:type params: str
"""

_attribute_map = {
'project_uri': {'key': 'project_uri', 'type': 'str'},
'params': {'key': 'params', 'type': 'str'},
}

def __init__(self, project_uri=None, params=None):
super(ProjectRunDetails, self).__init__()
self.project_uri = project_uri
self.params = params
118 changes: 118 additions & 0 deletions sdk/burdock/restclient/rest_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.service_client import ServiceClient
from msrest import Configuration, Serializer, Deserializer
from .version import VERSION
from msrest.pipeline import ClientRawResponse
from msrest.exceptions import HttpOperationError
from . import models


class RestClientConfiguration(Configuration):
"""Configuration for RestClient
Note that all parameters used to create this instance are saved as instance
attributes.

:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""

def __init__(
self, credentials, base_url=None):

if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if not base_url:
base_url = '/api'

super(RestClientConfiguration, self).__init__(base_url)

self.add_user_agent('restclient/{}'.format(VERSION))

self.credentials = credentials


class RestClient(object):
"""This is the Open API specification of the Burdock service.

:ivar config: Configuration for client.
:vartype config: RestClientConfiguration

:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""

def __init__(
self, credentials, base_url=None):

self.config = RestClientConfiguration(credentials, base_url)
self._client = ServiceClient(self.config.credentials, self.config)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = '0.0.1'
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)


def executerun(
self, details, custom_headers=None, raw=False, **operation_config):
"""Execute a differentially private module.

Create a run of the specified module and return the results.

:param details: Configuration for the module run.
:type details: ~restclient.models.ProjectRunDetails
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: ExecuterunOKResponse or ClientRawResponse if raw=true
:rtype: ~restclient.models.ExecuterunOKResponse or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`HttpOperationError<msrest.exceptions.HttpOperationError>`
"""
# Construct URL
url = self.executerun.metadata['url']

# Construct parameters
query_parameters = {}

# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if custom_headers:
header_parameters.update(custom_headers)

# Construct body
body_content = self._serialize.body(details, 'ProjectRunDetails')

# Construct and send request
request = self._client.post(url, query_parameters)
response = self._client.send(
request, header_parameters, body_content, stream=False, **operation_config)

if response.status_code not in [200]:
raise HttpOperationError(self._deserialize, response)

deserialized = None

if response.status_code == 200:
deserialized = self._deserialize('ExecuterunOKResponse', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
executerun.metadata = {'url': '/execute'}
9 changes: 9 additions & 0 deletions sdk/burdock/restclient/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

VERSION = "1.5.0"

51 changes: 51 additions & 0 deletions sdk/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Setup file for differential privacy package."""
from setuptools import setup, find_packages
import os
import shutil

_major = "0.1"
_minor = "0.1"

VERSION = "{}.{}".format(_major, _minor)
SELFVERSION = VERSION
if os.path.exists("patch.version"):
with open("patch.version", "rt") as bf:
_patch = str(bf.read()).strip()
SELFVERSION = "{}.{}".format(VERSION, _patch)

DEPENDENCIES = [
"numpy",
"pandas",
"scikit-learn",
"msrest",
"antlr4-python3-runtime"
]

EXTRAS = { }

with open("README.md", "r", encoding="utf-8") as f:
README = f.read()
HISTORY = ""
inline_license = ""

setup(
name="burdock",

version=SELFVERSION,

description="",
long_description=README + "\n\n" + HISTORY,
long_description_content_type="text/x-rst",
author="burdock",
license=inline_license,
packages=find_packages(exclude=["*.tests"]),

install_requires=DEPENDENCIES,

include_package_data=True,

extras_require=EXTRAS,

data_files=[],
zip_safe=False
)