0

Object with same value format for all keys in swagger

I want to document an API in swagger with nodejs + fastify which has a request body like this.

body: {
  type: "object",
  properties: {
    body_param_1: {
        type: "object",
        properties: {
            1: {
                type: "object",
                properties: {
                    title: {
                        type: "string"
                    },
                    link: {
                        type: "string",
                    },
                    status: {
                        type: "boolean"
                    }
                }
            },
            2: {
                type: "object",
                properties: {
                    title: {
                        type: "string"
                    },
                    link: {
                        type: "string",
                    },
                    status: {
                        type: "boolean"
                    }
                }
            },
            .
            .
            .
            .
            "n": {
                type: "object",
                properties: {
                    title: {
                        type: "string"
                    },
                    link: {
                        type: "string",
                    },
                    status: {
                        type: "boolean"
                    }
                }
            }
        }
    }
}

}

In this case I don't want to define the value for all keys [1,2,3...n]. I'm just wondering whether swagger allows to define the default format for all key value pairs in the object.

Since the keys in body_param_1 object is dynamic, is there a way to define the value format in swagger ?

Thanks in advance.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • `body_param_1` is a string-to-object map - see [example 1](https://stackoverflow.com/q/68459144/113116) and [example 2](https://stackoverflow.com/q/36136885/113116) for sample OpenAPI definitions. – Helen May 22 '23 at 09:54

0 Answers0