Git Product home page Git Product logo

amis-server's Introduction

amis 后端功能辅助

目前实现了:

  • amis 表单验证,用于实现和 amis 同样的后端验证,避免重复开发

使用方法

目前还没发布到 maven center,所以暂时需要通过拷贝源码的方式使用

import com.baidu.amis.validation.Validator;

// 第一个参数是 amis schema,第二个参数是表单 name,第三个参数是提交数据的 json
// 为了方便查看,下面示例使用 java 15 的 text block
List<ConstraintViolation> violations=Validator.validate("""
{
  "type": "page",
  "body": {
    "type": "form",
    "api": "/api/mock2/form/saveForm",
    "name": "myForm",
    "body": [
      {
        "type": "input-text",
        "label": "文本",
        "name": "text",
        "validations": {
          "isNumeric": true
        },
        "validationErrors": {
          "isNumeric": "同学,请输入数字哈"
        }
      }
    ]
  }
}
""","myForm","""
{
  "text": "v"
}
""");

// 如果 violations 的结果应该是
violations[0].getMessage()=="同学,请输入数字哈"

开发

目前主要以库的形式对外提供,但还没有 maven 仓库,只能先拷贝代码使用

测试

因为需要构造大量 JSON 进行测试,而 Java 在 15 之前不支持多行字符串,构造起来麻烦,所以测试的代码是基于 kotlin,可以直接在 IDE 里运行单个测试,或者使用下面的命令运行所有测试:

./gradlew check

生成测试报告

./gradlew clean build

amis-server's People

Contributors

nwind avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.