Skip to content

Commit f871fd5

Browse files
author
Peter Amstutz
committed
Refactor around swagger definition
1 parent 6d1f04a commit f871fd5

File tree

5 files changed

+314
-6
lines changed

5 files changed

+314
-6
lines changed

client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from bravado.client import SwaggerClient
2+
from bravado.requests_client import RequestsClient
3+
import json
4+
import pprint
5+
6+
f = open("swagger/proto/workflow_execution.swagger.json")
7+
client = SwaggerClient.from_spec(json.load(f), origin_url="http://localhost:8080")
8+
9+
r = client.WorkflowService.RunWorkflow(body={
10+
"workflow_url": "http://xyz",
11+
"inputs": {"message": "hello"}}).result()
12+
13+
pprint.pprint(r)

myapp.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def GetWorkflowStatus(workflow_ID):
2+
return {"workflow_ID": workflow_ID}
3+
4+
def GetWorkflowLog():
5+
pass
6+
7+
def CancelJob():
8+
pass
9+
10+
def RunWorkflow(body):
11+
print body
12+
return {"workflow_ID": "1"}

server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import connexion
2+
from connexion.resolver import Resolver
3+
import connexion.utils as utils
4+
import myapp
5+
6+
app = connexion.App(__name__, specification_dir='swagger/')
7+
def rs(x):
8+
return utils.get_function_from_name("myapp." + x)
9+
10+
app.add_api('proto/workflow_execution.swagger.json', resolver=Resolver(rs))
11+
12+
app.run(port=8080)

setup.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
license='Apache 2.0',
2222
py_modules=["cwltool_stream", "cwl_flask", "cwltool_client"],
2323
install_requires=[
24-
'Flask',
25-
'requests',
26-
'PyYAML'
24+
'connexion',
25+
'bravado'
2726
],
2827
entry_points={
29-
'console_scripts': [ "cwltool-stream=cwltool_stream:main",
30-
"cwl-server=cwl_flask:main",
31-
"cwl-client=cwl_client:main"]
28+
'console_scripts': [ "wes-server=wes_service:main",
29+
"wes-client=wes_client:main"]
3230
},
3331
zip_safe=True
3432
)
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "proto/workflow_execution.proto",
5+
"version": "version not set"
6+
},
7+
"schemes": [
8+
"http",
9+
"https"
10+
],
11+
"consumes": [
12+
"application/json"
13+
],
14+
"produces": [
15+
"application/json"
16+
],
17+
"paths": {
18+
"/v1/workflows": {
19+
"post": {
20+
"summary": "Run a task",
21+
"operationId": "RunWorkflow",
22+
"responses": {
23+
"200": {
24+
"description": "",
25+
"schema": {
26+
"$ref": "#/definitions/ga4gh_workflow_execWorkflowRunID"
27+
}
28+
}
29+
},
30+
"parameters": [
31+
{
32+
"name": "body",
33+
"in": "body",
34+
"required": true,
35+
"schema": {
36+
"$ref": "#/definitions/ga4gh_workflow_execWorkflowRequest"
37+
}
38+
}
39+
],
40+
"tags": [
41+
"WorkflowService"
42+
]
43+
}
44+
},
45+
"/v1/workflows/{workflow_ID}": {
46+
"get": {
47+
"summary": "Get info about a running workflow",
48+
"operationId": "GetWorkflowLog",
49+
"responses": {
50+
"200": {
51+
"description": "",
52+
"schema": {
53+
"$ref": "#/definitions/ga4gh_workflow_execWorkflowLog"
54+
}
55+
}
56+
},
57+
"parameters": [
58+
{
59+
"name": "workflow_ID",
60+
"in": "path",
61+
"required": true,
62+
"type": "string",
63+
"format": "string"
64+
}
65+
],
66+
"tags": [
67+
"WorkflowService"
68+
]
69+
},
70+
"delete": {
71+
"summary": "Cancel a running task",
72+
"operationId": "CancelJob",
73+
"responses": {
74+
"200": {
75+
"description": "",
76+
"schema": {
77+
"$ref": "#/definitions/ga4gh_workflow_execWorkflowRunID"
78+
}
79+
}
80+
},
81+
"parameters": [
82+
{
83+
"name": "workflow_ID",
84+
"in": "path",
85+
"required": true,
86+
"type": "string",
87+
"format": "string"
88+
}
89+
],
90+
"tags": [
91+
"WorkflowService"
92+
]
93+
}
94+
},
95+
"/v1/workflows/{workflow_ID}/status": {
96+
"get": {
97+
"summary": "Get info about a running workflow",
98+
"operationId": "GetWorkflowStatus",
99+
"responses": {
100+
"200": {
101+
"description": "",
102+
"schema": {
103+
"$ref": "#/definitions/ga4gh_workflow_execWorkflowStatus"
104+
}
105+
}
106+
},
107+
"parameters": [
108+
{
109+
"name": "workflow_ID",
110+
"in": "path",
111+
"required": true,
112+
"type": "string",
113+
"format": "string"
114+
}
115+
],
116+
"tags": [
117+
"WorkflowService"
118+
]
119+
}
120+
}
121+
},
122+
"definitions": {
123+
"ga4gh_task_execJobLog": {
124+
"type": "object",
125+
"properties": {
126+
"cmd": {
127+
"type": "array",
128+
"items": {
129+
"type": "string",
130+
"format": "string"
131+
},
132+
"title": "The command line that was run"
133+
},
134+
"endTime": {
135+
"type": "string",
136+
"format": "string",
137+
"title": "When the command completed"
138+
},
139+
"exitCode": {
140+
"type": "integer",
141+
"format": "int32",
142+
"title": "Exit code of the program"
143+
},
144+
"startTime": {
145+
"type": "string",
146+
"format": "string",
147+
"title": "When the command was executed"
148+
},
149+
"stderr": {
150+
"type": "string",
151+
"format": "string",
152+
"title": "Sample of stderr (not guaranteed to be entire log)"
153+
},
154+
"stdout": {
155+
"type": "string",
156+
"format": "string",
157+
"title": "Sample of stdout (not guaranteed to be entire log)"
158+
}
159+
}
160+
},
161+
"ga4gh_workflow_execWorkflowLog": {
162+
"type": "object",
163+
"properties": {
164+
"logs": {
165+
"type": "object",
166+
"additionalProperties": {
167+
"$ref": "#/definitions/ga4gh_task_execJobLog"
168+
}
169+
},
170+
"request": {
171+
"$ref": "#/definitions/ga4gh_workflow_execWorkflowRequest"
172+
}
173+
}
174+
},
175+
"ga4gh_workflow_execWorkflowRequest": {
176+
"type": "object",
177+
"properties": {
178+
"inputs": {
179+
"$ref": "#/definitions/protobufStruct"
180+
},
181+
"workflow_url": {
182+
"type": "string",
183+
"format": "string"
184+
}
185+
}
186+
},
187+
"ga4gh_workflow_execWorkflowRunID": {
188+
"type": "object",
189+
"properties": {
190+
"workflow_ID": {
191+
"type": "string",
192+
"format": "string"
193+
}
194+
}
195+
},
196+
"ga4gh_workflow_execWorkflowStatus": {
197+
"type": "object",
198+
"properties": {
199+
"workflow_ID": {
200+
"type": "string",
201+
"format": "string"
202+
}
203+
}
204+
},
205+
"protobufListValue": {
206+
"type": "object",
207+
"properties": {
208+
"values": {
209+
"type": "array",
210+
"items": {
211+
"$ref": "#/definitions/protobufValue"
212+
},
213+
"description": "Repeated field of dynamically typed values."
214+
}
215+
},
216+
"description": "`ListValue` is a wrapper around a repeated field of values.\n\nThe JSON representation for `ListValue` is JSON array."
217+
},
218+
"protobufNullValue": {
219+
"type": "string",
220+
"enum": [
221+
"NULL_VALUE"
222+
],
223+
"default": "NULL_VALUE",
224+
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
225+
},
226+
"protobufStruct": {
227+
"type": "object",
228+
"properties": {
229+
"fields": {
230+
"type": "object",
231+
"additionalProperties": {
232+
"$ref": "#/definitions/protobufValue"
233+
},
234+
"description": "Map of dynamically typed values."
235+
}
236+
},
237+
"description": "`Struct` represents a structured data value, consisting of fields\nwhich map to dynamically typed values. In some languages, `Struct`\nmight be supported by a native representation. For example, in\nscripting languages like JS a struct is represented as an\nobject. The details of that representation are described together\nwith the proto support for the language.\n\nThe JSON representation for `Struct` is JSON object."
238+
},
239+
"protobufValue": {
240+
"type": "object",
241+
"properties": {
242+
"bool_value": {
243+
"type": "boolean",
244+
"format": "boolean",
245+
"description": "Represents a boolean value."
246+
},
247+
"list_value": {
248+
"$ref": "#/definitions/protobufListValue",
249+
"description": "Represents a repeated `Value`."
250+
},
251+
"null_value": {
252+
"$ref": "#/definitions/protobufNullValue",
253+
"description": "Represents a null value."
254+
},
255+
"number_value": {
256+
"type": "number",
257+
"format": "double",
258+
"description": "Represents a double value."
259+
},
260+
"string_value": {
261+
"type": "string",
262+
"format": "string",
263+
"description": "Represents a string value."
264+
},
265+
"struct_value": {
266+
"$ref": "#/definitions/protobufStruct",
267+
"description": "Represents a structured value."
268+
}
269+
},
270+
"description": "`Value` represents a dynamically typed value which can be either\nnull, a number, a string, a boolean, a recursive struct value, or a\nlist of values. A producer of value is expected to set one of that\nvariants, absence of any variant indicates an error.\n\nThe JSON representation for `Value` is JSON value."
271+
}
272+
}
273+
}

0 commit comments

Comments
 (0)