-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Background
We have a scenario where we are updating the state for a scene (for instance to update vitals). To do this we are adding a scene[].state field as specified here:
itm-scenario-validator/api_files/api.yaml
Line 870 in 4f6ebf4
| state: |
For example:
scenes:
- index: 4
state: { ... }The scene state is of type State
itm-scenario-validator/api_files/api.yaml
Lines 870 to 871 in 4f6ebf4
| state: | |
| $ref: "#/components/schemas/State" |
Which has the following required fields:
itm-scenario-validator/api_files/api.yaml
Lines 472 to 477 in 4f6ebf4
| State: | |
| required: | |
| - unstructured | |
| - environment | |
| - supplies | |
| - characters |
So in order to update a small portion of the state (i.e. changing vitals), we must fully redefine unstructured, environment, supplies, and characters.
Further, scene[].state.environment (type: #/components/schemas/Environment) has the following required fields:
itm-scenario-validator/api_files/api.yaml
Lines 547 to 549 in 4f6ebf4
| Environment: | |
| required: | |
| - sim_environment |
And scene[].state.environment.sim_environment (type: #/components/schemas/SimEnvironment) has the following required fields:
itm-scenario-validator/api_files/api.yaml
Lines 557 to 559 in 4f6ebf4
| SimEnvironment: | |
| required: | |
| - type |
Issue
So to recap, scene[].state.environment.sim_environment.type is always required in order to update any part of the state. However, when defining this field in a scene state update, the scenario is no longer valid according to the validator tool:
It looks like this discrepancy is caused by manually swapping out the state schema here:
itm-scenario-validator/validator.py
Lines 194 to 200 in 4f6ebf4
| def validate_state_change(self, obj_to_validate): | |
| ''' | |
| Under Scenes in the API, state should be defined slightly differently. | |
| Use state_changes.yaml and perform as before. | |
| ''' | |
| schema = self.state_changes_yaml['components']['schemas'] | |
| top_level = schema['State']['properties'] |
This manual schema swap makes the validator tool incompatible with its own schema file (since the schema file cannot include this manual swap) so we must either (1) define the data according to the schema and have errors from the validator tool or (2) define according to the validator tool and have errors in the schema.
Since we are using standard OpenAPI tools for our server, we cannot have (2). The libraries we are using simply won't consume the data if it doesn't match the schema. So we are currently settling for (1).
Potential Fixes
- Move
state.environment.sim_environment.typefromEnvironmentto the top-levelScenarioobject since it can only be used one time in each scenario anyway - Define explicit objects for
SceneState,SceneEnviroment, andSceneSimEnvironmentthat can be used for state updates in a scene that encode the special rules ofapi/state_changes.yamldirectly in the schema file.- This would have the added benefit of allowing us to remove all required fields from these objects and allowing small updates without defining the entire state again
- Make
scene[].state.environment.sim_environment.typeoptional. This is technically incorrect since it is not optional for the first state but could be a shortcut until (1) is done to at least make it so the validator tool isn't broken
