AlexStocks commented on code in PR #3609:
URL: https://github.com/apache/dubbo-go/pull/3609#discussion_r3733584581
##########
tools/protoc-gen-triple-openapi/internal/converter/schema/schema.go:
##########
@@ -51,27 +52,40 @@ func GenerateFileSchemas(tt protoreflect.FileDescriptor)
*orderedmap.Map[string,
}
}
+ sortedEnums := make([]protoreflect.EnumDescriptor, 0, len(enums))
+ for enum := range enums {
+ sortedEnums = append(sortedEnums, enum)
+ }
+ sort.Slice(sortedEnums, func(i, j int) bool {
+ return sortedEnums[i].FullName() < sortedEnums[j].FullName()
+ })
+
+ for _, enum := range sortedEnums {
+ id, schema := enumToSchema(enum)
+ schemas.Set(id, base.CreateSchemaProxy(schema))
Review Comment:
[P1] 处理 enum component 与内置 ErrorResponse 的 ID 冲突
这里直接以 enum.FullName() 写入 components。合法的无 package proto 如果声明 enum
ErrorResponse,生成的 ID 就是 ErrorResponse,随后 generateComponents 会用同名 Triple
错误对象覆盖它;请求字段仍引用 #/components/schemas/ErrorResponse,最终把 enum 解析成 object。我在 exact
Head 上用该 descriptor 可稳定复现。请为内置错误 schema 使用不可与 protobuf FullName 碰撞的 ID 并同步
response 引用,或在冲突时显式改名/报错;同时补无 package enum/message 的冲突回归测试。
##########
tools/protoc-gen-triple-openapi/internal/converter/schema/util.go:
##########
@@ -55,11 +55,16 @@ func messageToSchema(tt protoreflect.MessageDescriptor)
(string, *base.Schema) {
func fieldToSchema(parent *base.SchemaProxy, tt protoreflect.FieldDescriptor)
*base.SchemaProxy {
if tt.IsMap() {
- // Handle maps
root := ScalarFieldToSchema(parent, tt, false)
root.Title = string(tt.Name())
root.Type = []string{"object"}
- // TODO: todo
+ value := tt.MapValue()
+ switch value.Kind() {
+ case protoreflect.MessageKind, protoreflect.EnumKind:
Review Comment:
[P1] 为 message/enum map value 补能识别回归的 fixture
当前 golden 只覆盖 map<string,string> 和普通 enum 字段,没有经过这里的 MessageKind/EnumKind
分支。我在隔离副本中删除该分支、让所有 map value 都生成 scalar schema 后,现有 go test ./... 仍全部通过,因此
message/enum additionalProperties 的 $ref 行为没有测试保护。请在 descriptor/示例 proto 中加入
map<string, Message> 与 map<string, Enum>,同时断言 additionalProperties.$ref 和对应
enum component;删除本分支时测试应失败。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]