Как сделать многоразовые примеры в формате xml - PullRequest
0 голосов
/ 26 октября 2019

Я пытаюсь создать несколько примеров ответов, которые можно использовать в форматах xml и json

Я пытался написать пример ответа двух типов, но есть ошибка

responses:
   '400':  
          description: Ошибки валидации запроса  
          content:   
            application/xml:  
              schema:  
                $ref: '#/components/schemas/ErrorResponse'  
              examples:  
                400wrongBodyFormat:  
                  $ref: '#/components/examples/400wrongBodyFormat'

examples:  
  400wrongBodyFormat:  
        value:   
          httpCode: 400
          httpMessage: Bad Request
          moreInformation: Body of the request is not valid according to json 
                           schema

schemas:
    ErrorResponse:
      type: object
      properties:
        httpCode:
          type: integer
        httpMessage:
          type: string
        moreInformation:
          type: integer 

Я хочу получить что-то вроде этого:

<400>
  <httpCode>400</httpCode>
  <httpMessage>Bad request</httpMessage>
</400>

Но получаю это

{
  "httpCode": 400,
  "httpMessage": "Bad Request",
  "moreInformation": "Body of the request is not valid according to json schema"
}

1 Ответ

0 голосов
/ 28 октября 2019

Укажите пример ответа XML в виде текста:

components:
  examples:  
    400wrongBodyFormat:  
      value: |-
        <?xml version="1.0"?>
        <ErrorResponse>
          <httpCode>400</httpCode>
          <httpMessage>Bad Request</httpMessage>
          <moreInformation>Body of the request is not valid according to json schema</moreInformation>
        </ErrorResponse>

Вы также можете удалить examples из ответа и вместо этого добавить значения примера свойств в схему, чтобы Swagger UI автоматически генерировал пример ответа на основесхема.

      responses:
       '400':  
          description: Ошибки валидации запроса  
          content:   
            application/xml:  
              schema:  
                $ref: '#/components/schemas/ErrorResponse'  

components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        httpCode:
          type: integer
          example: 400
        httpMessage:
          type: string
          example: Bad Request
        moreInformation:
          type: integer
          example: Body of the request is not valid according to json schema
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...