Nomralize component start()/stop()
Also fixed the /schema swagger/rest entry. It did not work
because the 3rdparty protobuf_to_dict library cannot handle
Map fields. Changed the two map fields to a single list
entry.
Change-Id: Ib25a528701b67d58d32451687724c8247da6efa5
diff --git a/protoc_plugins/gw_gen.py b/protoc_plugins/gw_gen.py
index 5398c32..20249c2 100755
--- a/protoc_plugins/gw_gen.py
+++ b/protoc_plugins/gw_gen.py
@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
import sys
from google.protobuf.compiler import plugin_pb2 as plugin
@@ -56,11 +57,22 @@
{% else %}
riase NotImplementedError('cannot handle specific body field list')
{% endif %}
- req = dict_to_protobuf({{ method['input_type'] }}, data)
+ try:
+ req = dict_to_protobuf({{ method['input_type'] }}, data)
+ except Exception, e:
+ log.error('cannot-convert-to-protobuf', e=e, data=data)
+ raise
res = grpc_client.invoke(
{{ '.'.join([package, method['service']]) }}Stub,
'{{ method['method'] }}', req)
- out_data = protobuf_to_dict(res, use_enum_labels=True)
+ try:
+ out_data = protobuf_to_dict(res, use_enum_labels=True)
+ except AttributeError, e:
+ filename = '/tmp/chameleon_failed_to_convert_data.pbd'
+ with file(filename, 'w') as f:
+ f.write(res.SerializeToString())
+ log.error('cannot-convert-from-protobuf', outdata_saved=filename)
+ raise
request.setHeader('Content-Type', 'application/json')
log.debug('{{ method_name }}', **out_data)
return dumps(out_data)
diff --git a/protoc_plugins/schema2dict.py b/protoc_plugins/schema2dict.py
new file mode 100644
index 0000000..31c0417
--- /dev/null
+++ b/protoc_plugins/schema2dict.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Convert a schema.Schema object given on the standard input as protobuf data
+file (from standard output) to a Python dictionary.
+"""
+import json
+import sys
+from chameleon.protos.third_party.google.api import annotations_pb2
+_ = annotations_pb2
+from chameleon.protos import schema_pb2
+from protobuf_to_dict import protobuf_to_dict
+
+
+if __name__ == '__main__':
+
+ data = sys.stdin.read()
+ schemas = schema_pb2.Schemas()
+ schemas.ParseFromString(data)
+
+ data = protobuf_to_dict(schemas, use_enum_labels=True)
+ json.dump(data, sys.stdout)