1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
2 | # contributor license agreements. See the NOTICE file distributed with |
||
3 | # this work for additional information regarding copyright ownership. |
||
4 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
||
5 | # (the "License"); you may not use this file except in compliance with |
||
6 | # the License. You may obtain a copy of the License at |
||
7 | # |
||
8 | # http://www.apache.org/licenses/LICENSE-2.0 |
||
9 | # |
||
10 | # Unless required by applicable law or agreed to in writing, software |
||
11 | # distributed under the License is distributed on an "AS IS" BASIS, |
||
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
13 | # See the License for the specific language governing permissions and |
||
14 | # limitations under the License. |
||
15 | # |
||
16 | import sys |
||
17 | |||
18 | |||
19 | TYPE_TABLE = { |
||
20 | dict: 'object', |
||
21 | list: 'array', |
||
22 | int: 'integer', |
||
23 | str: 'string', |
||
24 | float: 'number', |
||
25 | bool: 'boolean', |
||
26 | type(None): 'null', |
||
27 | } |
||
28 | |||
29 | if sys.version_info[0] < 3: |
||
30 | TYPE_TABLE[unicode] = 'string' |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
31 | |||
32 | |||
33 | def _dict_to_schema(item): |
||
34 | schema = {} |
||
35 | for key, value in item.iteritems(): |
||
36 | if isinstance(value, dict): |
||
37 | schema[key] = { |
||
38 | 'type': 'object', |
||
39 | 'parameters': _dict_to_schema(value) |
||
40 | } |
||
41 | else: |
||
42 | schema[key] = { |
||
43 | 'type': TYPE_TABLE[type(value)] |
||
44 | } |
||
45 | |||
46 | return schema |
||
47 | |||
48 | |||
49 | def render_output_schema_from_output(output): |
||
50 | """Given an action output produce a reasonable schema to match. |
||
51 | """ |
||
52 | return _dict_to_schema(output) |
||
53 |