marshmallow-jsonschema icon indicating copy to clipboard operation
marshmallow-jsonschema copied to clipboard

Add support for metadata on custom fields.

Open eligundry opened this issue 8 years ago • 6 comments

Custom fields now can have titles and stuff!

eligundry avatar Nov 30 '16 03:11 eligundry

Coverage Status

Coverage remained the same at 100.0% when pulling ff6bf106141da5a5ce350d78103990f7d05edb2d on eligundry:improve-custom-types into 6f51771fc809a0762b3d98f4d246b70eb653d802 on fuhrysteve:master.

coveralls avatar Nov 30 '16 03:11 coveralls

Sorry I didn't notice this before.

I like this functionality - I think even better than the _jsonschema_type_mapping hack I had. I think its only weakness is that it depends on that function to be there for this to work.

For example, this would not work:

from marshmallow import fields, Schema

class MySchema(Schema):
    name = fields.String(metadata={"title": "Full Name"})

What if we dropped the whole _jsonschema_type_mapping concept and instead make the API something like this:

from marshmallow import fields, Schema

class MySchema(Schema):
    name = fields.String(jsonschema_attributes={"title": "Full Name"})

When I originally made the _jsonschema_type_mapping method, I wasn't fully aware of the **metadata on fields. We whould be able to access it by doing something like:

field.metadata.get('metadata', {}).get('jsonschema_attributes')

Let me know what you think or if I missed anything!

fuhrysteve avatar Jan 08 '17 13:01 fuhrysteve

bump. I really like this, and I think I'd need it to be able to integrate this library into my project

Lacrymology avatar Mar 29 '17 17:03 Lacrymology

Hi @fuhrysteve @eligundry , could you please clarify what's the status of this PR? I wouldn't mind implementing any of the corrections needed myself to get this into master.

atmo avatar Jul 10 '19 16:07 atmo

If I'm not mistaken, you should be able to get this functionality by implementing _jsonschema_type_mapping today - however if you have ideas for how to improve that pattern circa this pull request, I'm not opposed to it!

To help me understand what we're working towards here, would you mind showing an example of what the API change would be (from a high level) so it's clear why this is an improvement on what already exists today?

fuhrysteve avatar Jul 10 '19 16:07 fuhrysteve

Is this just a way to make it so that you don't have to implement your own type in order to inject stuff into properties?

fuhrysteve avatar Jul 10 '19 16:07 fuhrysteve