2015-01-28 5 views
2

{swagger-express} 라이브러리를 사용하고 있으며 코드는 모두 CoffeeScript입니다. 나의 정의는, 내가 가진 :Express로 Swagger를 설정하는 방법은 무엇입니까?

### 
    * @swagger 
    * path: /login 
    * operations: 
    * - httpMethod: POST 
    *  summary: Login with username and password 
    *  notes: Returns a user based on username 
    *  responseClass: User 
    *  nickname: login 
    *  consumes: 
    *  - text/html 
    *  parameters: 
    *  - name: username 
    *   description: Your username 
    *   paramType: query 
    *   required: true 
    *   dataType: string 
    *  - name: password 
    *   description: Your password 
    *   paramType: query 
    *   required: true 
    *   dataType: string 
    ### 

을하고 잘 작동 : routes에서

app.use swagger.init app, 
    apis: ['./src/routes.coffee', './src/models.yml'] 
    apiVersion: '0.1.0' 
    basePath: "http://localhost:#{port}" 
    info: 
    title: 'My API' 
    description: 'A complete listing of all API functions' 
    swaggerUI: path.join __dirname, 'public' 
    swaggerURL: '/swagger' 

require('./src/routes') app 

, 나는있다.

definitions: 
    User: 
    properties: 
     user_id: 
     type: string 
     description: Unique ID to represent the user 
     first_name: 
     type: string 
     description: First name of the Uber user. 
     last_name: 
     type: string 
     description: Last name of the Uber user. 
     email: 
     type: string 
     description: Email address of the Uber user 
     picture: 
     type: string 
     description: Image URL of the Uber user. 
     promo_code: 
     type: string 
     description: Promo code of the Uber user. 

그러나 그것은 api-docs.json에 표시되지 않습니다 내 model.yml 파일입니다. 한 파일에 models을 정의하고 다른 파일에 paths을 정의하려고합니다. 그게 끝날 수 있습니까?

답변

2

각 형식을 별도로 읽고 resourcePath을 키로 사용하는 해시에 저장하기 때문에 작동하지 않을 것이라고 생각합니다.

https://github.com/fliptoo/swagger-express/blob/a5560af936e5398affe36d347af5be2a1bb64fc2/lib/swagger-express/index.js#L27

같은 resourcePath의 더 이상의 선언은 이전의 선언을 무시합니다.

I는 resourcePath으로 업데이트 YML 형식으로 이름 models 대신 definitions하고 모델 id 고유의 테스트. 이 모델은 표시했지만 내 다른 어떠한 정보 :/

resourcePath: /login 
models: 
    User: 
    id: User 
    properties: 
     user_id: 
     type: String 
     description: Unique ID to represent the user 
     first_name: 
     type: String 
     description: First name of the Uber user. 
     last_name: 
     type: String 
     description: Last name of the Uber user. 
     email: 
     type: String 
     description: Email address of the Uber user 
     picture: 
     type: String 
     description: Image URL of the Uber user. 
     promo_code: 
     type: String 
     description: Promo code of the Uber user. 

예 자신의 GitHub의에이 작동하지만 나는 그것이 작동 할 수없는 것처럼 보이게합니다.

관련 문제