Expected type 'object' but got 'number'


#1

Hello,

I’m getting the Expected type ‘object’ but got ‘number’ error in the value property in the example in the following code sample:

responses:
    200:
      body:
        application/json:
          type:
            {
                "type": "object",
                "required": ["value","currency"],
                "properties": {
                    "value": {
                        "type": "number",
                        "minimum": 0
                    },
                    "currency": {
                        "type": "string",
                        "maxLength": 3,
                        "minLength": 3
                    }
                }
            }
          example:
            value: 100.00
            currency: USD

The weird thing is that the issue disappears if I do either of the 2 options:

  • Rename value in the schema and example to anything else
  • Turn the value type to string.

Any idea what could be happening here? I’m very confused.

Thanks!


#2

I have never seen types declared with JSON structures like that before, and i can’t get that part to work at all.
However, the problem you are experiencing with the example seems to be that value is a reserved keyword, and if your object includes it, it needs to be wrapped in another level of value:

See example:
https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#example-of-how-to-define-exampleexamples-in-raml


#3

As @attah point-out, value has a meaning in the context of an example. If you change your example to something like:

    example:
      value:
        value: 100.00
        currency: USD

, it should work fine.