Giter Club home page Giter Club logo

halogen's People

Contributors

amakhnach avatar blaise-io avatar bubenkoff avatar dzittersteyn avatar hvdklauw avatar olegpidsadnyi avatar ribeirojr avatar tarmack avatar youtux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

halogen's Issues

Allow a field with custom schema to be nullable during deserialization

Given these schema

class ChildSchema(halogen.Schema):
    some_other_field = halogen.Attr(halogen.types.String())

class ParentSchema(halogen.Schema):
    some_field = halogen.Attr(ChildSchema)

To make some_field nullable during deserialization, I have to create a deserialize class method on ChildSchema:

class ChildSchema(halogen.Schema):
    some_other_field = halogen.Attr(halogen.types.String())

    @classmethod
    def deserialize(self, value, **kwargs):
        return None if value is None else super().deserialize(value)

It would be nice if halogen.Attr supported a nullable parameter:
some_field = halogen.Attr(ChildSchema, nullable=True)

Or alternatively support wrapping:
some_field = halogen.Attr(halogen.Nullable(ChildSchema))

Object deserialization, not required attributes don't fallback to default value

I'm trying to deserialize an object which occasionally may contain a field. If the field is not present, I want to use a default value to deserialize the object.

If in the schema I use just the default value, during deserialization a validation error raises. If is use occasional = halogen.Attr(required=False, default="custom"), the deserialization works but the field occasional field is not populated with "custom" value.

Predictable Field Order

Haven't thought about how this might be done, but it would be very nice if there was a way to control the order of fields when the HAL document is created/rendered.

Curie lists have random order as they are constructed as set() internally.

Looking through the code it appears curies are initially constructed as a set() but subsequently converted to a plain list(). Therefore the order of curies is randomised.

This not only seems at odds with the expected behaviour of a list (or list-like) structure, but means tests become more complex --- having to convert the actual, and expected output to compare curies as sets is painful.

Perhaps this is more of an edge case, but would the developers be willing to discuss this possibility?

Conditional next/prev links

When implementing collection endpoints with paging support, the _link relations usually have next and prev links. A corresponding schema for a user collection could be something like

class UserCollectionSchema(Schema):

  self = halogen.Link(attr=lambda u: f"url?page={u.page}")
  next = halogen.Link(attr=lambda u: f"url?page={u.page + 1}")
  prev = halogen.Link(attr=lambda u: f"url?page={u.page - 1}")

  users = halogen.Embedded(halogen.types.List(UserSchema), attr=...)

Is it possible to only serialize/render the next and prev links only when a certain condition is met, e.g. when there is actually a next or a previous page?

ValidationError.to_dict() structure

Schema's are hierarchical, but we need to come up with somewhat more usable data structure than what ValidationError.to_dict() returns. It should be easy to associate the error with the field of the web form.

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.