Giter VIP home page Giter VIP logo

Comments (7)

crdoconnor avatar crdoconnor commented on May 18, 2024

I'm not sure about this one. You can already read unstructured, schemaless data using strictyaml and you can also create partial schemas. You can ratchet up the strictness incrementally rather than generating a great big schema (which will likely change).

I'm also pretty averse to writing code generation tools (I've seen them go wrong too many times).

I'm intending on allowing the use of kwalify schemas at some point, but since these don't work for more complex schemas, it would be alongside the existing pythonic schema language.

from strictyaml.

kshpytsya avatar kshpytsya commented on May 18, 2024

Correct me if I am mistaken, but I see it as very straightforward recursive constructor for validators with uniform direct correspondence to existing python validator classes and their parameters.
This would be trivial to implement but would be a pain to keep up-to-date if not being part of the strictyaml itself. I suspect that creative (isn't it always?) use of decorators on Validator classes could make this simple and elegant.

I don't quite get your remark on "code generation tools".

from strictyaml.

crdoconnor avatar crdoconnor commented on May 18, 2024

Are you suggesting something like this::

x:
  a: 1
  b: 2

strictyaml.generate_schema(yaml_string) == """Map({"x": Map({"a": Int(), "b": Int()})})"""

from strictyaml.

kshpytsya avatar kshpytsya commented on May 18, 2024

No. Rather:

schema = Map({
    "u": Seq(Bool),
    "x": Int(),
    "y": Enum(["a", "b", "c"]),
    "z": MapPattern(Int(), Str())
})
data = strictyaml.load(yaml_str, schema)

could be done as:

yaml_schema_str="""
type: Map
validator:
    - u:
        type: Seq
        validator:
            type: Bool
    - x:
        type: Int
    - y:
        type: Enum
        restricted_to:
              - a
              - b
              - c
    - z:
        type: MapPattern
        key_validator:
            type: Int
        value_validator:
            type: Str
"""
yaml_schema_data = strictyaml.load(yaml_schema_str)
schema = strictyaml.construct_schema_from_data(yaml_schema_data)
data = strictyaml.load(yaml_str, schema)

The values in "type" can be any of the leaf Validator classes (I am not sure if all classes in the validators module are meant to be usable by the user, or rather some are meant as base classes only). The rest of the keys should correspond to constructor arguments.
Just as I said earlier, I believe that something like that can be elegantly implementing by some decorators decorating Validator subclasses. I even imagine/suggest that you can generate "schema schema" using the annotation from those decorators, which could be used in the

yaml_schema_data = strictyaml.load(yaml_schema_str, strictyaml.SCHEMA_SCHEMA)

call.

Defining schema in Python is, of course, more concise, but in my use case, I need the ability to give the end-user a way to describe schema without resorting to Python programming, following the rule of least power.

from strictyaml.

crdoconnor avatar crdoconnor commented on May 18, 2024

Yes, I'd like to do this feature like so::

data = strictyaml.load(yaml_str, Kwalify(kwalify_schema_str))

Defining schema in Python is, of course, more concise, but in my use case, I need the ability to give the end-user a way to describe schema without resorting to Python programming, following the rule of least power.

Sure, I think YAML is sometimes better provided it can represent the schema you need.

from strictyaml.

crdoconnor avatar crdoconnor commented on May 18, 2024

I'm not sure if constructing the kwalify schema from data belongs in this library though. That might work better as a separate library (especially since it's very edge-casey).

from strictyaml.

crdoconnor avatar crdoconnor commented on May 18, 2024

On second thoughts, I think I'm going to close this. I think it's a decent enough idea in principle, but:

  • In all the time I've been dogfooding this library, I haven't really felt the desire to use kwalify (or something similarly turing incomplete) instead. By contrast this library exists because I was almost instantly frustrated by kwalify's limitations when I first used it. I'm not 100% convinced, but I'm edging around to the view that turing completeness is needed in schemas frequently enough that it should be the default.

  • If I'm wrong about that (quite possible), I still think if it did exist it would work better as a separate library that generates a strictyaml validator from a kwalify YAML string.

If somebody else builds this as a separate library I'll be more than happy to point people to it in the README and docs.

from strictyaml.

Related Issues (20)

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.