cloudformation-cli icon indicating copy to clipboard operation
cloudformation-cli copied to clipboard

JSON pointer to elements in arrays of non-fixed length

Open unext-wendong opened this issue 1 year ago • 6 comments

Kindly let me know if this is the wrong place to ask this question.

Given the following sample schema, property Services is an array of non-fixed length.

{
    "definitions": {
        "Service": {
            "properties": {
                "Id": {
                    "description": "The ID of the service instance.",
                    "type": "string"
                },
                "Type": {
                    "description": "The type of the service instance.",
                    "type": "string"
                }
            },
            "additionalProperties": false
        }
    },
    "properties": {
        "Id": {
            "description": "Unique identifier.",
            "type": "string"
        },
        "Services": {
            "description": "The list of services.",
            "type": "array",
            "items": {
                "$ref": "#/definitions/Service"
            }
        }
    },
    "additionalProperties": false,
    "readOnlyProperties": [
        "/properties/Id"
    ],
    "primaryIdentifier": [
        "/properties/Id"
    ],
    "writeOnlyProperties": [
        "/properties/Services/0/Id"
    ]
}

How could I express in the schema that the Id property in the Service data is write-only? I mean what json pointers should I put in writeOnlyProperties.

If the Services array is of fixed length, I could list all /properties/Services/0/Id, /properties/Services/1/Id, ..., there, but it's of non-fixed length.

If it's not possible, is there any other way to express this?

Thanks,

unext-wendong avatar Jun 27 '24 13:06 unext-wendong

Couple of options for you to try. If everything under Services is write only "/properties/Services/*" or if its just the id "/properties/Services/*/Id"

kddejong avatar Jun 27 '24 14:06 kddejong

With *, I got error:

E   ValueError: invalid literal for int() with base 10: '*'

Seems to be an invalid syntax.

I'm using the cloudformation-cli-python-plugin==2.1.9.

unext-wendong avatar Jun 27 '24 14:06 unext-wendong

@ammokhov I have that right don't I? Is this an issue with the python plugin?

kddejong avatar Jun 27 '24 14:06 kddejong

@kddejong @ammokhov Sorry for pinging. Could you confirm if this is currently impossible to express?

Thanks,

unext-wendong avatar Jul 11 '24 06:07 unext-wendong

I believe that "/properties/Services/*" should be expressed as "/properties/Services"

ammokhov avatar Jul 11 '24 17:07 ammokhov

Thanks @ammokhov for the reply.

I believe that "/properties/Services/*" should be expressed as "/properties/Services"

Yeah, I understand this.

What I was asking for was a way to mark only the Id property of the Service data as write-only.

I just edited my sample schema to include another property Type in the Service definition, which is readable, to make it clearer.

Is there a way to do that?

unext-wendong avatar Jul 12 '24 02:07 unext-wendong