google / gnostic

A compiler for APIs described by the OpenAPI Specification with plugins for code generation and other API support tasks.
Apache License 2.0
2.09k stars 247 forks source link

output_path contains invalid UTF-8 data when parsing protobuf #94

Open xmonader opened 6 years ago

xmonader commented 6 years ago

I compiled petstore https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

gnostic petstore.json --pb-out=.   

in my python


from sys import argv
import os
# from gnostic.discovery_pb2 import Request, Response
from gnostic.OpenAPIv3_pb2 import Document
from gnostic.plugin_pb2 import *
from gnostic.surface_pb2 import Model

if __name__ == "__main__":
    srcfile = ""
    if len(argv) > 2:
        srcfile = argv[2]
    else:
        srcfile = os.path.join(os.path.dirname(__file__), "petstore.pb")
    sourceb = open(srcfile, "rb").read()

    req = Request().FromString(sourceb)

and I get

[libprotobuf ERROR google/protobuf/wire_format_lite.cc:534] String field 'gnostic.plugin.v1.Request.output_path' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
*** google.protobuf.message.DecodeError: Error parsing message

I also tried changing


_REQUEST = _descriptor.Descriptor(
  name='Request',
  full_name='gnostic.plugin.v1.Request',
  filename=None,
  file=DESCRIPTOR,
  containing_type=None,
  fields=[
    _descriptor.FieldDescriptor(
      name='source_name', full_name='gnostic.plugin.v1.Request.source_name', index=0,
      number=1, type=9, cpp_type=9, label=1,
      has_default_value=False, default_value=_b("").decode('utf-8'),
      message_type=None, enum_type=None, containing_type=None,
      is_extension=False, extension_scope=None,
      options=None),
    _descriptor.FieldDescriptor(
      name='output_path', full_name='gnostic.plugin.v1.Request.output_path', index=1,
      number=2, type=9, cpp_type=9, label=1,
      has_default_value=False, default_value=_b("").decode('utf-8'),
      message_type=None, enum_type=None, containing_type=None,
      is_extension=False, extension_scope=None,
      options=None),

output_path to 12 bytes instead of 9 string but the error still the same

[libprotobuf ERROR google/protobuf/wire_format_lite.cc:534] String field 'gnostic.plugin.v1.Request.output_path' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
google.protobuf.message.DecodeError: Error parsing message but it still sees it as bytes

compiled proto

b'\n\x053.0.0\x12 \n\x10Swagger Petstore*\x05\n\x03MIT2\x051.0.0\x1a\x1f\n\x1dhttp://petstore.swagger.io/v1"\xc0\x06\n\x81\x04\n\x05/pets\x12\xf7\x03"\xe7\x02\n\x04pets\x12\rList all pets*\x08listPets2V\nT\n\x05limit\x12\x05query\x1a.How many items to return at one time (max 100)R\x14\n\x12\xca\x01\x07integer\x9a\x02\x05int32B\xed\x01\nL\nJ\n\x10unexpected error\x1a6\n4\n\x10application/json\x12 \n\x1e\x12\x1c\n\x1a#/components/schemas/Error\x12\x9c\x01\n\x03200\x12\x94\x01\n\x91\x01\n\x15A paged array of pets\x12A\n?\n\x06x-next\x125\n3\n$A link to the next page of responsesB\x0b\n\t\xca\x01\x06string\x1a5\n3\n\x10application/json\x12\x1f\n\x1d\x12\x1b\n\x19#/components/schemas/Pets2\x8a\x01\n\x04pets\x12\x0cCreate a pet*\ncreatePetsBh\nL\nJ\n\x10unexpected error\x1a6\n4\n\x10application/json\x12 \n\x1e\x12\x1c\n\x1a#/components/schemas/Error\x12\x18\n\x03201\x12\x11\n\x0f\n\rNull response\n\xb9\x02\n\r/pets/{petId}\x12\xa7\x02"\xa4\x02\n\x04pets\x12\x17Info for a specific pet*\x0bshowPetById2=\n;\n\x05petId\x12\x04path\x1a\x1dThe id of the pet to retrieve \x01R\x0b\n\t\xca\x01\x06stringB\xb6\x01\nL\nJ\n\x10unexpected error\x1a6\n4\n\x10application/json\x12 \n\x1e\x12\x1c\n\x1a#/components/schemas/Error\x12f\n\x03200\x12_\n]\n$Expected response to a valid request\x1a5\n3\n\x10application/json\x12\x1f\n\x1d\x12\x1b\n\x19#/components/schemas/Pets*\xee\x01\n\xeb\x01\n]\n\x03Pet\x12V\nT\xba\x01\x02id\xba\x01\x04name\xfa\x01E\n\x1a\n\x02id\x12\x14\n\x12\xca\x01\x07integer\x9a\x02\x05int64\n\x13\n\x04name\x12\x0b\n\t\xca\x01\x06string\n\x12\n\x03tag\x12\x0b\n\t\xca\x01\x06string\n3\n\x04Pets\x12+\n)\xca\x01\x05array\xf2\x01\x1e\n\x1c\x12\x1a\n\x18#/components/schemas/Pet\nU\n\x05Error\x12L\nJ\xba\x01\x04code\xba\x01\x07message\xfa\x016\n\x1c\n\x04code\x12\x14\n\x12\xca\x01\x07integer\x9a\x02\x05int32\n\x16\n\x07message\x12\x0b\n\t\xca\x01\x06string'
maranqz commented 3 years ago

On the main page there are description, "writes the results in a binary form".