@@ -843,9 +843,10 @@ class SchemaConverter {
843843 _build_object_rule (
844844 properties, required, name,
845845 schema.contains (" additionalProperties" ) ? schema[" additionalProperties" ] : json ()));
846- } else if ((schema_type.is_null () || schema_type == " object" ) && schema.contains (" allOf" )) {
846+ } else if ((schema_type.is_null () || schema_type == " object" || schema_type == " string " ) && schema.contains (" allOf" )) {
847847 std::unordered_set<std::string> required;
848848 std::vector<std::pair<std::string, json>> properties;
849+ std::map<std::string, size_t > enum_values;
849850 std::string hybrid_name = name;
850851 std::function<void (const json &, bool )> add_component = [&](const json & comp_schema, bool is_required) {
851852 if (comp_schema.contains (" $ref" )) {
@@ -857,6 +858,14 @@ class SchemaConverter {
857858 required.insert (prop.key ());
858859 }
859860 }
861+ } else if (comp_schema.contains (" enum" )) {
862+ for (const auto & v : comp_schema[" enum" ]) {
863+ const auto rule = _generate_constant_rule (v);
864+ if (enum_values.find (rule) == enum_values.end ()) {
865+ enum_values[rule] = 0 ;
866+ }
867+ enum_values[rule] += 1 ;
868+ }
860869 } else {
861870 // todo warning
862871 }
@@ -870,6 +879,17 @@ class SchemaConverter {
870879 add_component (t, true );
871880 }
872881 }
882+ if (!enum_values.empty ()) {
883+ std::vector<std::string> enum_intersection;
884+ for (const auto & p : enum_values) {
885+ if (p.second == schema[" allOf" ].size ()) {
886+ enum_intersection.push_back (p.first );
887+ }
888+ }
889+ if (!enum_intersection.empty ()) {
890+ return _add_rule (rule_name, " (" + string_join (enum_intersection, " | " ) + " ) space" );
891+ }
892+ }
873893 return _add_rule (rule_name, _build_object_rule (properties, required, hybrid_name, json ()));
874894 } else if ((schema_type.is_null () || schema_type == " array" ) && (schema.contains (" items" ) || schema.contains (" prefixItems" ))) {
875895 json items = schema.contains (" items" ) ? schema[" items" ] : schema[" prefixItems" ];
0 commit comments