Programming Language independent Model Validation

前端 未结 4 495
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 18:05

Let\'s say you use several different programming languages and frameworks in your infrastructure to handle large amounts of traffic etc.

Example Stack:

相关标签:
4条回答
  • 2021-01-12 18:46

    If you want to go the way of full validation, I'd use SOAP. At least, as long as you have SOAP libraries, all you need to feed them is the WSDL for your interfaces.

    0 讨论(0)
  • 2021-01-12 18:52

    I would go on a "dictionary" of Regular Expressions. Regular Expressions are supported by all the languages you counted - and - translating their string representation from one language to another can be done by a passing the expressions themselves through regular expressions...

    To my observation - it's a lot less work then composing a parse and execute mechanism for each language...

    Like advised before - you can save this "dictionary" of Reg-Exps in an agnostic format, such as JSON. This narrows down the duplicated work to -

    • one source file of validation expressions that you maintain
    • per programming language:
      • converter from the main file to the format of the target language
      • thin mechanism of
        1. reading the JSON,
        2. selecting from it the configured checks
        3. executing them
      • edge cases (if any)

    Have fun :)

    0 讨论(0)
  • 2021-01-12 18:53

    To add to @Nathan Ostgard's post, XML, XSD and, when necessary, XSLT might work as well. The advantage to this would be a) XSD has the simple validation built into it b) most languages have good support for this c) you wouldn't have to write validation in each language; stuff that isn't handled in the schema could be written once in XSLT (with the caveat that XSLT implementations tend to vary :) )

    0 讨论(0)
  • 2021-01-12 19:01

    Your best bet would be a framework that allows you to specify model validation in a language agnostic format, like JSON. You might end up with a validation schema of sorts, say:

    {
      "name": [
        {
          "validate": "length",
          "minLength": 6,
          "maxLength": 10
        },
        ...
      ],
      ...
    }
    

    You would then have language-specific validators that could parse this format. The validators only need to be written once, and then you maintain a single schema for each model.

    However, this is probably sounding a lot like CORBA/SOAP/Thrift/ProtocolBuffers/etc. at this point. That's because they were written to solve these types of problems, and you'll end up reinventing a few wheels if you write it yourself.

    0 讨论(0)
提交回复
热议问题