openfisca / openfisca-core

OpenFisca core engine. See other repositories for countries-specific code & data.
https://openfisca.org
GNU Affero General Public License v3.0
171 stars 75 forks source link

Validate Web API example values #1028

Open MattiSG opened 3 years ago

MattiSG commented 3 years ago

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

Here is what I did:

I ran openfisca serve on OpenFisca France v61.0.0.

Here is what I expected to happen:

Here is what actually happened:

KeyError: 'cotsoc/gen/smic_h_b'
i/app.py", line 62, in create_app
    data = build_data(tax_benefit_system)
  File "/Users/mesaides/Documents/openfisca-france/.venv/lib/python3.8/site-packages/openfisca_web_api/loader/__init__.py", line 22, in build_data
    data['openAPI_spec'] = build_openAPI_specification(data)
  File "/Users/mesaides/Documents/openfisca-france/.venv/lib/python3.8/site-packages/openfisca_web_api/loader/spec.py", line 42, in build_openAPI_specification
    parameter_example = api_data['parameters'][parameter_path]
KeyError: 'cotsoc/gen/smic_h_b'

Here is data (or links to it) that can help you reproduce this issue:

Solution

The problem was actually that the parameter_example set up in the web API config did not exist in the tax and benefit system anymore, as can be seen in https://github.com/openfisca/openfisca-france/pull/1609. I expect that variable_example and simulation_example would lead to the same result.

I would have liked that the Web API tells me up front, when starting up (as opposed to when being accessed) that this key does not exist in the tax and benefit system, and that the error was clearer.

Context

I identify more as a: