2

In the following Swagger definition, I need the parameter labelValue to be of type LabelValueObject, so that it will be validated and correctly deserialized. However, I can't figure out the syntax! How can that be done?

swagger: "2.0" paths: /competition: post: parameters: - name: labelValue in: formData type: array items: type: string ### this has to be a LabelValueObject ### responses: default: description: Error schema: $ref: "#/definitions/AnyResponse" definitions: AnyResponse: properties: any: type: string LabelValueObject: properties: label: type: string value: type: string required: - label - value 
2
  • Does this parameter needs to be located in a formData? Commented Aug 27, 2016 at 22:16
  • You're right. I could set it to body and use a schema $ref I guess... I'm new to Swagger, so I missed that. If that's where you were going with your question, please post an answer. Commented Aug 28, 2016 at 0:37

1 Answer 1

4

The only way to pass an object as a parameter is to put it in the body (in: body) and then define this object in schema (inline definition or reference to an predefined object with $ref). Here's a full example:

swagger: "2.0" info: title: A dummy title version: 1.0.0 paths: /competition: post: parameters: - name: labelValue in: body schema: $ref: '#/definitions/LabelValueObject' responses: default: description: Error schema: $ref: "#/definitions/AnyResponse" definitions: AnyResponse: properties: any: type: string LabelValueObject: properties: label: type: string value: type: string required: - label - value 
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.