Skip to content

Validator tool is not compatible with its own schema #19

@np-soartech

Description

@np-soartech

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:

For example:

scenes:
  - index: 4
    state: { ... }

The scene state is of type State

state:
$ref: "#/components/schemas/State"

Which has the following required fields:

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:

Environment:
required:
- sim_environment

And scene[].state.environment.sim_environment (type: #/components/schemas/SimEnvironment) has the following required fields:

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:

image

It looks like this discrepancy is caused by manually swapping out the state schema here:

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

  1. Move state.environment.sim_environment.type from Environment to the top-level Scenario object since it can only be used one time in each scenario anyway
  2. Define explicit objects for SceneState, SceneEnviroment, and SceneSimEnvironment that can be used for state updates in a scene that encode the special rules of api/state_changes.yaml directly in the schema file.
    1. 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
  3. Make scene[].state.environment.sim_environment.type optional. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions