How to make schema for dict fields with variable names?
See original GitHub issueFor example, suppose we have the following JSON schema:
...
"metrics": {
"type": "object",
"patternProperties": {
"^[a-zA-Z]+$": {
"type": "object",
"required": ["v", "date"],
"properties": {
"v": {"type": "number"},
"date": {"type": "string"}
},
"additionalProperties": false
}
}
}
...
How to define marshmallow’s schema for it?
I can validate it like this:
@MetricsSchema.validator
def validate_metrics(schema, input_data):
metric_key, metric_value = input_data['metrics'].items()[0]
if not re.compile(r'^[a-zA-Z]+$').match(metric_key):
raise ValidationError('Metric\'s name must be alphabetical symbols.')
errors = PredefinedMetricSchema().validate(metric_value)
if errors:
raise ValidationError(errors)
But how to make schema for serializing? I think it should have clear decision, because this case can be occured in schemas in your new project named smore.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
how to create a schema of a table by fetching column names ...
The idea is to split the string by "=" and use the first part as a dict key (for table name) and create...
Read more >Creating a REDCap Data Dictionary - UT Southwestern
In either case, what you're creating is referred to as the data dictionary, a description of all the field (variable) names, field types,...
Read more >Generating a Dictionary Mapping from Field Names to Column ...
This recipe shows a function that takes a DB API 2.0 cursor object and returns a dictionary with column numbers keyed to field...
Read more >How to use the marshmallow.fields.Dict function in ... - Snyk
To help you get started, we've selected a few marshmallow.fields.Dict examples ... description="Schema name", example="prefs",) schema_version = fields.
Read more >Specifying a schema | BigQuery - Google Cloud
To create a JSON schema file, enter a TableFieldSchema for each column. The name and type fields are required. All other fields are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vovanbo Apologies for the delayed response. Here’s a stab at a
DictField
that might meet your use case:I noticed you added a regular Dict(), but are there any plans to support the DictField() as presented above? I have lots of maps of named objects for which this functionality would be useful.