![]() Note that arrays and array items support single example but not multiple examples. If the array contains objects, you can specify a multi-item example as follows: components: Or an array-level example containing multiple items: components: You can add an example of an individual array item: components: Note that schemas and properties support single example but not multiple examples. You can also specify examples for objects and individual properties in the components section. Note: The examples in response and request bodies are free-form, but are expected to be compatible with the body schema. Multiple examples in response bodies: responses: Here is an example of the example in response bodies: responses: If needed, you can use multiple examples: paths: This is needed because $ref overwrites all the siblings alongside it. $ref: '#/components/schemas/User' # Reference to an objectĮxample: # Child of media type because we use $ref above If schema refers to some object defined in the components section, then you should make example a child of the media type keyword: paths: Note that in the code above, example is a child of schema. Here is an example of the example keyword in a request body: paths: Note: the sample values you specify should match the parameter data type. Also, in the code above, we used an optional summary keys with description. Summary: A sample limit value # Optional descriptionĪs you can see, each example has a distinct key name. Multiple examples for a parameter: parameters: Here is an example of a parameter value: parameters:Įxample: approved # Example of a parameter value A default value is what the server uses if the client does not provide the value. An example illustrates what the value is supposed to be. Note: Do not confuse example values with default values. Note for Swagger UI users: Support for multiple examples is available since Swagger UI 3.23.0 and Swagger Editor 3.6.31. To specify an example, you use the example or examples keys. ![]() You can specify examples for objects, individual properties and operation parameters. For example, an API mocking tool can use sample values to generate mock requests. Examples can be read by tools and libraries that process your API in some way. You can add examples to parameters, properties and objects to make OpenAPI specification of your web service clearer. If you use OpenAPI 2.0, see our OpenAPI 2.0 guide. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |