V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
beryl
V2EX  ›  程序员

可扩展接口协议设计-自定义 schema/Json 配置化?

  •  
  •   beryl · 2021-01-25 19:00:17 +08:00 · 1295 次点击
    这是一个创建于 1157 天前的主题,其中的信息可能已经有所发展或是发生改变。

    背景:
    做一个机审服务平台,但是业务方传过来的是个复杂 Json,里面某些字段需要做检测,但是不同接入方字段不确定,而且可能是多个字段。

    想了个思路是有个地方提前去做配置选择哪些字段做对应的哪些审核策略,但是具体思路还是不太清楚,请教下大家有没有其他的思路或者参考方案?

    参数举列:

    {
      "name": "ABC",
      "title": "XXX",
      "ext": {
          "desc": "ZZZ",
          "content": "YYY"
       }
    }
    // 以上这个需要对 name 和 ext.content 进行检测
    
    
    {
      "cnName": "ABCDD",
      "titleInfo": "XXX",
      
      "poiInfo": {
          "city": {
          	"desc": "ZZZ",
          	"name": "YYY"
           }
       }
    }
    // 以上这个需要对 titleInfo 和 poiInfo.city.name 和 poiInfo.city.desc 检测
    
    

    谢谢

    13 条回复    2021-01-27 11:00:29 +08:00
    Takamine
        1
    Takamine  
       2021-01-25 19:13:19 +08:00 via Android
    ……不知道为啥我第一反应是 GraphQL 。
    smilekung
        2
    smilekung  
       2021-01-25 19:18:11 +08:00
    jsonSchemaValidator
    beryl
        3
    beryl  
    OP
       2021-01-25 19:27:12 +08:00
    @Takamine 我能理解到的也是 graphQL,还在研究,但是可能不合适
    beryl
        4
    beryl  
    OP
       2021-01-25 19:28:12 +08:00
    @Takamine GraphQL 偏向于查询吧
    Takamine
        5
    Takamine  
       2021-01-25 20:14:09 +08:00 via Android
    @beryl 嗯呢,只是看到接口 schema 这几个词条件反射想到这个。_(:з」∠)_
    Takamine
        6
    Takamine  
       2021-01-25 20:16:10 +08:00 via Android
    话说这个接口接收不是用的实体吗,是 Map 可随意变吗。
    chendy
        7
    chendy  
       2021-01-25 21:10:22 +08:00
    参考 jsonschema,自己写也不麻烦
    buhi
        8
    buhi  
       2021-01-26 00:58:09 +08:00
    json schema, 这个是规范, 别的可以不用看了
    myCupOfTea
        9
    myCupOfTea  
       2021-01-26 08:47:36 +08:00
    json schema 太啰嗦了
    beryl
        10
    beryl  
    OP
       2021-01-26 11:20:03 +08:00
    @myCupOfTea 那还有更好的推荐么
    asmoker
        11
    asmoker  
       2021-01-26 11:35:56 +08:00
    marshmallow
    myCupOfTea
        12
    myCupOfTea  
       2021-01-27 10:17:22 +08:00
    @beryl 自定义(
    beryl
        13
    beryl  
    OP
       2021-01-27 11:00:29 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4787 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:58 · PVG 17:58 · LAX 02:58 · JFK 05:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.