1

I'd like to use my JSON schemas to generate the documentation.

In the example below, I want to list all combinations ErrorNumber/ErrorMessage available in my output messages in JSON.

But I can't find a way on the object level, my attempts with "examples" or "enum" failed.

Does anyone have a solution?

{
    "type": "object",
    "required": [
        "ErrorNumber",
        "ErrorMessage"
    ],
    "properties": {
        "ErrorNumber": {
            "$id": "#root/ErrorNumber", 
            "type": "integer"
        },
        "ErrorMessage": {
            "$id": "#root/ErrorMessage", 
            "type": "string"
        }
    }
}

1 Answer 1

1
  1. Did you mean to write "$ref" where you use "$id" in the example?

  2. Where exactly did you have problems with enum? The following works fine for me with a draft-2020-12 Validator (and after removing your "$id"!):

{
  // ... your JSON here ...
  "enum": [
    {"ErrorNumber": 200, "ErrorMessage": "OK"},
    {"ErrorNumber": 404, "ErrorMessage": "Not found."}
    // ...
  ]
}
  1. Different approaches, in case you still can change that:

If your error numbers start at 0 and are contiguous, then an Array of messages might serve your purpose.

Alternatively an object with numerical keys might:

{
  "200": "OK",
  "404": "Not found."
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.