6

I have an API that returns rows of data based on a request. The rows are JSON elements containing name:value pairs. However, the attribute names (and datatypes of the values) need to be fluid and undefined in the spec.

For example:

{
    "row_id": 1234,
    "data": {
        "foo": "bar",
        "date": "2019-07-31",
        "some_number": 5
    }
 }

In this example, the attributes 'row_id' and 'data' are the only fixed things. All the name:values pairs inside the data element can be anything.

I believe I can use open api additionalProperties to describe this, but no examples I can find tell me how or confirm that this is correct.

Does anyone have an idea how to do this or can point me in the right direction?

1

1 Answer 1

10

It looks like what I was looking for was:

    recordData:
      type: object
      additionalProperties: {}

type: object defines it as a general object, and additionalProperties: {} says the object contains properties that have not been specifically defined.

The docs I finally located also say that additionalProperties: true would also work.

Sign up to request clarification or add additional context in comments.

1 Comment

above is all i had to do. i didn't have to specify json in particular. i believe the {} implies it in this situation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.