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

AnyOf/OneOf 子节点为$ref时,选项标题是“选项1、2...”,而非子节点的 title #354

Open
laorange opened this issue Apr 6, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@laorange
Copy link

laorange commented Apr 6, 2024

vue和ui框架

Vue2 & Vue3 + 所有ui框架 均能在playground复现该问题

问题描述

如下图所示,AnyOf/OneOf 子节点为$ref时,期望显示:“类型A、类型B”(子节点的 title),而不是“选项1、选项2”;

与RJSF中的表现有较大差异

vjsf-issue-tiny

如何复现

可用于复现的json-schema(对应Playground的链接):

{"$defs":{"ClassA":{"properties":{"fooA":{"default":0,"title":"ClassA的属性","type":"number"}},"title":"类型A","type":"object"},"ClassB":{"properties":{"fooB":{"default":0,"title":"ClassB的属性","type":"number"}},"title":"类型B","type":"object"}},"properties":{"common":{"oneOf":[{"$ref":"#/$defs/ClassA"},{"$ref":"#/$defs/ClassB"}],"title":"OneOf属性","description":"A/B类型二选一"}},"title":"OneOf模型测试","type":"object"}

该json的格式为:

vjsf-issue-json-schema-tiny

初步排查结果

初步排出:该问题是因为子节点为$ref;对比测试为:直接使用对应的Object内容而非$ref,使用以下json-schema能够正常显示(对应的Playground):

{"properties":{"common":{"oneOf":[{"properties":{"fooA":{"default":0,"title":"ClassA的属性","type":"number"}},"title":"类型A","type":"object"},{"properties":{"fooB":{"default":0,"title":"ClassB的属性","type":"number"}},"title":"类型B","type":"object"}],"title":"OneOf属性","description":"A/B类型二选一"}},"title":"OneOf模型测试","type":"object"}

期望的结果

😄希望与RJSF中展示效果相仿,能在选项中展示子节点的title,期待您的回复🫡

@laorange laorange changed the title AnyOf/OneOf 选项的标题会错误显示为“选项一、二...”,而非子节点 title 属性 AnyOf/OneOf 选项标题会显示为“选项1、2...”,而非子节点的 title Apr 6, 2024
@laorange

This comment was marked as duplicate.

@laorange laorange changed the title AnyOf/OneOf 选项标题会显示为“选项1、2...”,而非子节点的 title AnyOf/OneOf 子节点为$ref时,选项标题是“选项1、2...”,而非子节点的 title Apr 6, 2024
@lljj-x
Copy link
Owner

lljj-x commented Apr 10, 2024

子节点不是 $ref 的时候是可以正常取到标题的对吧 ?

@laorange
Copy link
Author

子节点不是 $ref 的时候是可以正常取到标题的对吧 ?

😄是的,上面提到的两个对比测试:

@lljj-x lljj-x added the bug Something isn't working label Apr 10, 2024
@lljj-x
Copy link
Owner

lljj-x commented Apr 10, 2024

这周处理下

@lljj-x
Copy link
Owner

lljj-x commented Apr 10, 2024

大致看了下,应该是 这里的schema 没有经过retrieve方法处理,要看看哪里处理合适,如果你有兴趣的话 也可以贡献代码

https://github.com/lljj-x/vue-json-schema-form/blob/master/packages/lib/vue2/vue2-core/src/fields/combiningSchemas/SelectLinkageField/index.js#L71C33-L71C39

类似下面

retrieveSchema(xxxx)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants