2016-08-13 9 views
4

200 OK에 응답하고 HTML을 반환하는 API 호출이 있습니다. 나는 내 API 문서 에 이것을 추가하고 싶습니다 (특히 dredd를 사용하여 유효성을 검사하고 테스트 응답이 예상되는 본문을 제공하지 않는 한). 어떻게 나는 Swagger에서 이것을 할 것입니까?콘텐츠 유형의 응답 본문에 예제 값을 제공하는 방법 : Swagger에서 text/html (dredd를 사용하여 테스트)

은 --- API 호출에 대한 나의 응답은 200 OK과 한 줄 응답 바디와 함께 자세한 내용입니다 --- :

<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>

내가 쉽게에서 청사진에 응답 바디를 정의 할 수 있습니다 다음 형식 :

+ Response 302 (text/html; charset=utf-8) 

    + Body 

     `<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>` 

하지만 Swagger에서이 작업을 수행하는 방법을 잘 모르겠습니다. 거의 모든 예제는 내가 찾을 수있는 응용 프로그램/json 응답 (이해할 수있는) 및 나는 문제가 있습니다. 응답이 이런 종류의 올바른 구문을 추측하고 있습니다.

내 문서의 관련 자신감 텍스트이있다 (응답 본체 <html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>을해야하기 때문에 빈 몸 을 저지 드레드와, 그래서 응답 본문을 지정하지 않고 지금까지 실패) :

# this is my API spec in YAML 
swagger: '2.0' 
info: 
    title: My API (Swagger) 
    description: blablabla 
    version: "1.0.0" 
# the domain of the service 
host: my.domain.com 
# array of all schemes that your API supports 
schemes: 
    - https 
# will be prefixed to all paths 
basePath:/
produces: 
    - application/json; charset=utf-8 
paths: 
    /users/password: 
    post: 
     summary: Password Reset 
     description: | 
     Handles Reset password for existing user. 
     consumes: 
     - application/x-www-form-urlencoded 
     produces: 
     - text/html; charset=utf-8 
     parameters: 
     - name: "user[email]" 
      description: email 
      in: formData 
      required: true 
      type: string 
      default: "[email protected]" 
     tags: 
     - Reset Password 
     responses: 
     200: 
      description: Success 

당신이 경우 의견을주십시오 이것에 대한 제안 사항이있다. 감사!

답변

6

알아 냈습니다. 응답 객체에는 API 응답에 예제를 보여줄 수있는 "examples"라는 필드가 있습니다.

구문이 명확하게 사양에 표시되어 있으며 기본적으로 예제 응답의 MIME 유형을 식별해야한다고 나와 있습니다.이 경우 text/html이고 값은 실제 텍스트입니다. 이 같은

너무 : 그것 뿐이다

responses: 
     200: 
     description: success and returns some html text 
     examples: 
      text/html: 
      <html><body>Your HTML text</body></html> 

. dredd가이 가치를 지니고 그것을 비교하는 것을 알고 있는지 여부는 이제 또 다른 이야기입니다. JSON 이외의 응답은 일반 텍스트로 확인되므로이 이어야합니다.

희망이 도움이되었습니다.