openfisca-core
openfisca-core copied to clipboard
Add variable metadata
New features
- Introduce
metadataattribute to Variable classmetadatais a python dict- it accepts all basic types and can be nested to arbitrary depth
- Adds
metadatakey to the web-api route "/variable/<id>"- converts dict to JSON and includes in Response
Use Case
- Allows the addition of arbitrary structured metadata to OpenFisca variables
- Allows retrieval of that structured metadata in the web-api
- Can allow for presenting additional context-specific details in frontend applications, such as structured regulation references like these
- Can allow for filtering/search in frontend applications ...
This feature is essentially an extension of the reference attribute, but allows for arbitrary dictionaries instead of just strings and lists of strings...
Example
Example of structured metadata:
class ABCD(Variable):
...
metadata = {"regulation_reference": {"part": 5,
"clause": "A",
"schedule": "34b",
"notes": ["foo", "bar"],
},
"is_output": True
}
Example web-api Response for GET /variables/ABCD/:
{
id: "ABCD",
...
metadata:{"regulation_reference": {"part": 5,
"clause": "A",
"schedule": "34b",
"notes": ["foo", "bar"],
},
"is_output": True
}
}
Notes
- Tests for the
web_apiResponse are tightly coupled to the "openfisca_country_template" repo, so I've (for the moment) forgone testing for theweb_apiResponse. - Failing tests are fixed by branch 'fix-doc-test-api'
If #984 is accepted, I can add web_api tests as appropriate.