Skip to content

Hyper-schema LDO: Replace "method" with behavioral descriptors #94

Closed
@handrews

Description

@handrews

In the current draft, a method of "get" just indicates the existence of a resource (but not necessarily that it can be fetched), while a method of "post" just indicates the existence of some sort of unsafe operation. Using these HTTP terms even though neither of them necessarily maps to those HTTP methods even when using HTTP is very confusing.

Issue #73 proposes an allow hint (see also issue #92 about JSON Home's hints approach). That does not replace the more abstract operation definition. In the abstract, we really just want to indicate behavior, so how about replacing method with one or two keywords that specify behavioral properties directly?

Specifically, "safe" and "idempotent" are the characteristics generally considered to be of interest. This can be done either with a single enumerated behavior keyword that can be set to either of those strings (or left out to indicate no behavioral keys. Or it can be done by using safe and idempotent as two boolean keywords.

I like the boolean option more, except that you have to make idempotent's default dependent on the value of safe. If an operation is safe, then idempotent should default to true. Otherwise it should default to false. Here's what the meta-schemas would look like for each approach.

Single keyword, no default (absent keyword indicates neither safe nor idempotent):

{
    "properties": {
        "behavior": {
            "enum": ["safe", "idempotent"],
        }
    }
}

Here's the two booleans approach, with some fun use of "oneOf" to make default behave ideally (I have no idea how many systems would even handle this properly):

{
    "properties": {
        "safe": {"type": "boolean", "default": false},
        "idempotent": {"type": "boolean"},
    },
    "oneOf": [
        {
            "properties": {
                "safe": {"enum": [true]},
                "idempotent": {"default": true}
            }
        },
        {
            "properties": {
                "safe": {
                    "oneOf": [
                        {"enum": [false]},
                        {"not": {}}
                    ]
                },
                "idempotent": {"default": false}
            }
        }
    ]
}

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