Reputation: 49
I am creating swagger documentation for an API and I would like to add XML example but I can't do it.
This is the swagger documentation that I've written:
swagger: "2.0"
info:
title: Documentatie API
description: Descriere documentatie API metode POST
version: 1.0.0
host: xxx.ro
basePath: /v1
schemes:
- https
paths:
/stareMesaj:
post:
summary: Stare mesaj
description: Descriere stare mesaj
consumes:
- application/xml
produces:
- application/xml
responses:
200:
description: OK
schema:
type: object
properties:
id:
type: integer
example: 4
name:
type: string
example: Arthur Dent
I was thinking that the proprieties under schema would transform in an example but it says :
<?xml version="1.0" encoding="UTF-8"?>
<!-- XML example cannot be generated; root element name is undefined -->
Can you please give me an example ?
Upvotes: 2
Views: 7193
Reputation: 97677
Your inline schema doesn't have a name, so Swagger UI does not know how to name the root element in XML.
Either add xml.name
to your schema:
responses:
200:
description: OK
schema:
type: object
properties:
...
xml: # <-----
name: user
or define a named schema in the definitions
section and reference it:
responses:
200:
description: OK
schema:
$ref: '#/definitions/user'
definitions:
user:
type: object
properties:
id:
type: integer
example: 4
name:
type: string
example: Arthur Dent
Upvotes: 5