2

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 ?

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

Comments

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.