@@ -799,7 +799,7 @@ struct protobuf_schema_definition::impl {
799799
800800 void render_field (
801801 std::ostream& os,
802- std::string_view edition,
802+ pb::Edition edition,
803803 const pb::FieldDescriptorProto& field,
804804 const pb::FieldDescriptor* descriptor,
805805 int indent,
@@ -859,7 +859,7 @@ struct protobuf_schema_definition::impl {
859859 };
860860
861861 const auto label = [&]() {
862- bool is_proto2 = edition == " proto2 " ;
862+ bool is_proto2 = edition == pb::Edition::EDITION_PROTO2 ;
863863 if (descriptor &&
864864 (descriptor->is_map () || descriptor->real_containing_oneof () ||
865865 ((descriptor->is_optional () && !field.proto3_optional ()) && !(is_proto2 && !descriptor->containing_oneof ())))) {
@@ -989,7 +989,7 @@ struct protobuf_schema_definition::impl {
989989 template <typename Descriptor>
990990 void render_extensions (
991991 std::ostream& os,
992- std::string_view edition,
992+ pb::Edition edition,
993993 const pb::RepeatedPtrField<pb::FieldDescriptorProto>& raw_extensions,
994994 const Descriptor& descriptor,
995995 int indent) const {
@@ -1127,7 +1127,7 @@ struct protobuf_schema_definition::impl {
11271127 // Render a message, including nested messages
11281128 void render_nested (
11291129 std::ostream& os,
1130- std::string_view edition,
1130+ pb::Edition edition,
11311131 const std::optional<pb::FieldDescriptorProto>& field,
11321132 const pb::FieldDescriptor* field_descriptor,
11331133 const pb::DescriptorProto& message,
@@ -1595,9 +1595,18 @@ struct protobuf_schema_definition::impl {
15951595 std::ostream& os,
15961596 const pb::FileDescriptorProto& fdp,
15971597 const pb::FileDescriptor& descriptor) const {
1598- auto syntax = fdp.has_syntax () ? fdp.syntax () : " proto2" ;
1599- std::string_view edition = syntax;
1600- fmt::print (os, " syntax = {};\n " , pb_string_value (syntax));
1598+ auto edition = fdp.edition ();
1599+ if (edition == pb::Edition::EDITION_UNKNOWN) {
1600+ auto syntax = fdp.has_syntax () ? fdp.syntax () : " proto2" ;
1601+ edition = syntax == " proto3" ? pb::Edition::EDITION_PROTO3
1602+ : pb::Edition::EDITION_PROTO2;
1603+ fmt::print (os, " syntax = {};\n " , pb_string_value (syntax));
1604+ } else {
1605+ fmt::print (
1606+ os,
1607+ " edition = {};\n " ,
1608+ pb_string_value (Edition_Name (fdp.edition ())));
1609+ }
16011610
16021611 if (fdp.has_package () && !fdp.package ().empty ()) {
16031612 fmt::print (os, " package {};\n " , fdp.package ());
0 commit comments