Skip to content

Commit

Permalink
Update OAS 2 syntax in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 16, 2022
1 parent b48c580 commit 4d61f3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions openfisca_web_api/loader/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def build_openAPI_specification(api_data):

for entity in tax_benefit_system.entities:
name = entity.key.title()
spec['definitions'][name] = get_entity_json_schema(entity, tax_benefit_system)
spec['components']['schemas'][name] = get_entity_json_schema(entity, tax_benefit_system)

situation_schema = get_situation_json_schema(tax_benefit_system)
dpath.util.new(spec, 'definitions/SituationInput', situation_schema)
dpath.util.new(spec, 'definitions/SituationOutput', situation_schema.copy())
dpath.util.new(spec, 'definitions/Trace/properties/entitiesDescription/properties', {
dpath.util.new(spec, 'components/schemas/SituationInput', situation_schema)
dpath.util.new(spec, 'components/schemas/SituationOutput', situation_schema.copy())
dpath.util.new(spec, 'components/schemas/Trace/properties/entitiesDescription/properties', {
entity.plural: {'type': 'array', 'items': {"type": "string"}}
for entity in tax_benefit_system.entities
})
Expand All @@ -43,24 +43,24 @@ def build_openAPI_specification(api_data):
parameter_example = api_data['parameters'][parameter_path]
else:
parameter_example = next(iter(api_data['parameters'].values()))
dpath.util.new(spec, 'definitions/Parameter/example', parameter_example)
dpath.util.new(spec, 'components/schemas/Parameter/example', parameter_example)

if tax_benefit_system.open_api_config.get('variable_example'):
variable_example = api_data['variables'][tax_benefit_system.open_api_config['variable_example']]
else:
variable_example = next(iter(api_data['variables'].values()))
dpath.util.new(spec, 'definitions/Variable/example', variable_example)
dpath.util.new(spec, 'components/schemas/Variable/example', variable_example)

if tax_benefit_system.open_api_config.get('simulation_example'):
simulation_example = tax_benefit_system.open_api_config['simulation_example']
dpath.util.new(spec, 'definitions/SituationInput/example', simulation_example)
dpath.util.new(spec, 'definitions/SituationOutput/example', handlers.calculate(tax_benefit_system, deepcopy(simulation_example))) # calculate has side-effects
dpath.util.new(spec, 'definitions/Trace/example', handlers.trace(tax_benefit_system, simulation_example))
dpath.util.new(spec, 'components/schemas/SituationInput/example', simulation_example)
dpath.util.new(spec, 'components/schemas/SituationOutput/example', handlers.calculate(tax_benefit_system, deepcopy(simulation_example))) # calculate has side-effects
dpath.util.new(spec, 'components/schemas/Trace/example', handlers.trace(tax_benefit_system, simulation_example))
else:
message = "No simulation example has been defined for this tax and benefit system. If you are the maintainer of {}, you can define an example by following this documentation: https://openfisca.org/doc/openfisca-web-api/config-openapi.html".format(country_package_name)
dpath.util.new(spec, 'definitions/SituationInput/example', message)
dpath.util.new(spec, 'definitions/SituationOutput/example', message)
dpath.util.new(spec, 'definitions/Trace/example', message)
dpath.util.new(spec, 'components/schemas/SituationInput/example', message)
dpath.util.new(spec, 'components/schemas/SituationOutput/example', message)
dpath.util.new(spec, 'components/schemas/Trace/example', message)
return spec


Expand Down
14 changes: 7 additions & 7 deletions tests/web_api/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_paths(body):


def test_entity_definition(body):
assert 'parents' in dpath.util.get(body, 'definitions/Household/properties')
assert 'children' in dpath.util.get(body, 'definitions/Household/properties')
assert 'salary' in dpath.util.get(body, 'definitions/Person/properties')
assert 'rent' in dpath.util.get(body, 'definitions/Household/properties')
assert 'number' == dpath.util.get(body, 'definitions/Person/properties/salary/additionalProperties/type')
assert 'parents' in dpath.util.get(body, 'components/schemas/Household/properties')
assert 'children' in dpath.util.get(body, 'components/schemas/Household/properties')
assert 'salary' in dpath.util.get(body, 'components/schemas/Person/properties')
assert 'rent' in dpath.util.get(body, 'components/schemas/Household/properties')
assert 'number' == dpath.util.get(body, 'components/schemas/Person/properties/salary/additionalProperties/type')


def test_situation_definition(body):
situation_input = body['definitions']['SituationInput']
situation_output = body['definitions']['SituationOutput']
situation_input = body['components']['schemas']['SituationInput']
situation_output = body['components']['schemas']['SituationOutput']
for situation in situation_input, situation_output:
assert 'households' in dpath.util.get(situation, '/properties')
assert 'persons' in dpath.util.get(situation, '/properties')
Expand Down

0 comments on commit 4d61f3f

Please sign in to comment.