Skip to content

Commit 4d61f3f

Browse files
committed
Update OAS 2 syntax in tests
1 parent b48c580 commit 4d61f3f

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

openfisca_web_api/loader/spec.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def build_openAPI_specification(api_data):
2525

2626
for entity in tax_benefit_system.entities:
2727
name = entity.key.title()
28-
spec['definitions'][name] = get_entity_json_schema(entity, tax_benefit_system)
28+
spec['components']['schemas'][name] = get_entity_json_schema(entity, tax_benefit_system)
2929

3030
situation_schema = get_situation_json_schema(tax_benefit_system)
31-
dpath.util.new(spec, 'definitions/SituationInput', situation_schema)
32-
dpath.util.new(spec, 'definitions/SituationOutput', situation_schema.copy())
33-
dpath.util.new(spec, 'definitions/Trace/properties/entitiesDescription/properties', {
31+
dpath.util.new(spec, 'components/schemas/SituationInput', situation_schema)
32+
dpath.util.new(spec, 'components/schemas/SituationOutput', situation_schema.copy())
33+
dpath.util.new(spec, 'components/schemas/Trace/properties/entitiesDescription/properties', {
3434
entity.plural: {'type': 'array', 'items': {"type": "string"}}
3535
for entity in tax_benefit_system.entities
3636
})
@@ -43,24 +43,24 @@ def build_openAPI_specification(api_data):
4343
parameter_example = api_data['parameters'][parameter_path]
4444
else:
4545
parameter_example = next(iter(api_data['parameters'].values()))
46-
dpath.util.new(spec, 'definitions/Parameter/example', parameter_example)
46+
dpath.util.new(spec, 'components/schemas/Parameter/example', parameter_example)
4747

4848
if tax_benefit_system.open_api_config.get('variable_example'):
4949
variable_example = api_data['variables'][tax_benefit_system.open_api_config['variable_example']]
5050
else:
5151
variable_example = next(iter(api_data['variables'].values()))
52-
dpath.util.new(spec, 'definitions/Variable/example', variable_example)
52+
dpath.util.new(spec, 'components/schemas/Variable/example', variable_example)
5353

5454
if tax_benefit_system.open_api_config.get('simulation_example'):
5555
simulation_example = tax_benefit_system.open_api_config['simulation_example']
56-
dpath.util.new(spec, 'definitions/SituationInput/example', simulation_example)
57-
dpath.util.new(spec, 'definitions/SituationOutput/example', handlers.calculate(tax_benefit_system, deepcopy(simulation_example))) # calculate has side-effects
58-
dpath.util.new(spec, 'definitions/Trace/example', handlers.trace(tax_benefit_system, simulation_example))
56+
dpath.util.new(spec, 'components/schemas/SituationInput/example', simulation_example)
57+
dpath.util.new(spec, 'components/schemas/SituationOutput/example', handlers.calculate(tax_benefit_system, deepcopy(simulation_example))) # calculate has side-effects
58+
dpath.util.new(spec, 'components/schemas/Trace/example', handlers.trace(tax_benefit_system, simulation_example))
5959
else:
6060
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)
61-
dpath.util.new(spec, 'definitions/SituationInput/example', message)
62-
dpath.util.new(spec, 'definitions/SituationOutput/example', message)
63-
dpath.util.new(spec, 'definitions/Trace/example', message)
61+
dpath.util.new(spec, 'components/schemas/SituationInput/example', message)
62+
dpath.util.new(spec, 'components/schemas/SituationOutput/example', message)
63+
dpath.util.new(spec, 'components/schemas/Trace/example', message)
6464
return spec
6565

6666

tests/web_api/test_spec.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ def test_paths(body):
3636

3737

3838
def test_entity_definition(body):
39-
assert 'parents' in dpath.util.get(body, 'definitions/Household/properties')
40-
assert 'children' in dpath.util.get(body, 'definitions/Household/properties')
41-
assert 'salary' in dpath.util.get(body, 'definitions/Person/properties')
42-
assert 'rent' in dpath.util.get(body, 'definitions/Household/properties')
43-
assert 'number' == dpath.util.get(body, 'definitions/Person/properties/salary/additionalProperties/type')
39+
assert 'parents' in dpath.util.get(body, 'components/schemas/Household/properties')
40+
assert 'children' in dpath.util.get(body, 'components/schemas/Household/properties')
41+
assert 'salary' in dpath.util.get(body, 'components/schemas/Person/properties')
42+
assert 'rent' in dpath.util.get(body, 'components/schemas/Household/properties')
43+
assert 'number' == dpath.util.get(body, 'components/schemas/Person/properties/salary/additionalProperties/type')
4444

4545

4646
def test_situation_definition(body):
47-
situation_input = body['definitions']['SituationInput']
48-
situation_output = body['definitions']['SituationOutput']
47+
situation_input = body['components']['schemas']['SituationInput']
48+
situation_output = body['components']['schemas']['SituationOutput']
4949
for situation in situation_input, situation_output:
5050
assert 'households' in dpath.util.get(situation, '/properties')
5151
assert 'persons' in dpath.util.get(situation, '/properties')

0 commit comments

Comments
 (0)