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

Flatc not generating JOSN #5628

Closed
swapniil opened this issue Nov 15, 2019 · 5 comments
Closed

Flatc not generating JOSN #5628

swapniil opened this issue Nov 15, 2019 · 5 comments

Comments

@swapniil
Copy link

swapniil commented Nov 15, 2019

First of all thanks for this very impressive serialization library with quite good documentation. I'm using it for now for a year. The issue I'm creating might be a trivial but I think it is needed to be fixed at least for my usage :) . Or this might be a non issue causing due to some incorrect IDL I have written :(.

I have written simple .fbs schema file contains line as below:
table test_type { inventory:[ubyte]; }

I need to generate C++ headers for this and jsonschema as well for string representation of this data.
when I'm executing command below:

flatc --jsonschema -o /tmp/fbs/ test.fbs --jsonschema

flatc has 'Segmentation fault'

The stack trace for this is as below:
` (gdb) r --jsonschema -o /tmp/fbs/ samples/test.fbs
Starting program: /usr/local/bin/flatc --jsonschema -o /tmp/fbs/ samples/test.fbs

Program received signal SIGSEGV, Segmentation fault.
0x00000000005410f0 in std::string flatbuffers::jsons::GenFullNameflatbuffers::StructDef(flatbuffers::StructDef const*) ()
(gdb) bt
#0 0x00000000005410f0 in std::string flatbuffers::jsons::GenFullNameflatbuffers::StructDef(flatbuffers::StructDef const*) ()
#1 0x00000000005428da in flatbuffers::jsons::JsonSchemaGenerator::generate() ()
#2 0x00000000005409e2 in flatbuffers::GenerateJsonSchema(flatbuffers::Parser const&, std::string const&, std::string const&) ()
#3 0x00000000005459b9 in flatbuffers::FlatCompiler::Compile(int, char const**) ()
#4 0x000000000041e46b in main ()
(gdb)
`

I have created a debug build of flatc to trace it down. It seems that there need to be a null check on below line.

Line Number:src/idl_gen_json_schema.cpp:202

Patch diff for this fix is :

diff --git a/src/idl_gen_json_schema.cpp b/src/idl_gen_json_schema.cpp
index b152fb2..2efa66c 100644
--- a/src/idl_gen_json_schema.cpp
+++ b/src/idl_gen_json_schema.cpp
@@ -199,8 +199,9 @@ class JsonSchemaGenerator : public BaseGenerator {
code_ += " },"; // close definitions

 // mark root type
  • code_ += " "$ref" : "#/definitions/" +
  •         GenFullName(parser_.root_struct_def_) + "\"";
    
  • if (parser_.root_struct_def_)

  •    code_ += "  \"$ref\" : \"#/definitions/" +
    
  •             GenFullName(parser_.root_struct_def_) + "\"";
    

    code_ += "}"; // close schema root
    const std::string file_path = GeneratedFileName(path_, file_name_);

Let me know if its a valid issue or there is incorrect IDL declaration.

Thanks,
Swapnil

@vglavnyy
Copy link
Contributor

Probably, this issue already fixed by #5622.

@swapniil
Copy link
Author

Yes It seems so but it fails to generate JOSN.
I'm debugging it with latest code. Crash is fixed but JSON is still pending on this. What is going wrong on this 3 lines IDL .

@swapniil swapniil changed the title Flatc crashing when using with --jsonschema flag Flatc not generating JOSN Nov 15, 2019
@vglavnyy
Copy link
Contributor

I have got flatc.exe: error: Unable to generate JsonSchema for test without SegFault (MSVC2019).
Code (#5622) works well.

    if (parser_.root_struct_def_ == nullptr) { return false; }

@vglavnyy
Copy link
Contributor

vglavnyy commented Nov 15, 2019

It is impossible to generate json-schema if a root table is unknown.
Can you try this schema?

table test_type { inventory:[ubyte]; }

root_type test_type;

@swapniil
Copy link
Author

It is impossible to generate json-schema if a root table is unknown.
Can you try this schema?

table test_type { inventory:[ubyte]; }

root_type test_type;

Yes that seems to be the cause. Thanks for immediate response. closing this issue with incorrect schema definition issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants