opa icon indicating copy to clipboard operation
opa copied to clipboard

JSON Schema: `additionalProperties` support

Open ffortier opened this issue 1 year ago • 2 comments

Short description

I have a jsonschema containing a map definition of typed objects, but opa check is not able to detect typos in it. My current workaround is to define an array instead of a map but it might not work if I need to unify with the key as a string value.

I put some code in this repo to reproduce this issue: https://github.com/ffortier/opa-jsonschema-test

Steps To Reproduce

  1. Create a json schema with the following definition:
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {},
    "required": [],
    "additionalProperties": {
        "$ref": "#/definitions/User"
    },
    "definitions": {
        "User": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                }
            },
            "required": [
                "name"
            ]
        }
    }
}
  1. Create a rego policy with the schemas annotation
  2. Create a rule with a typo
  3. Run opa check with the schema

Expected behavior

opa check should detect schema issues in maps but does not.

Additional context

I tested the same schema with python's jsonschema package just to be sure and the errors are detected correctly.

ffortier avatar Jan 16 '24 14:01 ffortier

The schema feature does not currently support additionalProperties or additionalItems.

For the example above, using properties instead should work.

anderseknert avatar Jan 16 '24 15:01 anderseknert

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

stale[bot] avatar Feb 16 '24 01:02 stale[bot]