openfisca-core icon indicating copy to clipboard operation
openfisca-core copied to clipboard

Add variable metadata

Open RamParameswaran opened this issue 4 years ago • 1 comments

New features

  • Introduce metadata attribute to Variable class
    • metadata is a python dict
    • it accepts all basic types and can be nested to arbitrary depth
  • Adds metadata key 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_api Response are tightly coupled to the "openfisca_country_template" repo, so I've (for the moment) forgone testing for the web_api Response.
  • Failing tests are fixed by branch 'fix-doc-test-api'

RamParameswaran avatar Mar 18 '21 07:03 RamParameswaran

If #984 is accepted, I can add web_api tests as appropriate.

RamParameswaran avatar Mar 23 '21 22:03 RamParameswaran