【发布时间】:2015-05-09 15:59:09
【问题描述】:
resources.js
'use strict';
var sw = require('swagger-node-express');
var paramTypes = sw.paramTypes;
var swe = sw.errors;
var petData = require('./service.js');
// the description will be picked up in the resource listing
exports.findById = {
'spec': {
description : 'Operations about pets',
path : '/pet/{petId}',
method: 'GET',
summary : 'Find pet by ID',
notes : 'Returns a pet based on ID',
type : 'Pet',
nickname : 'getPetById',
produces : ['application/json'],
parameters : [paramTypes.path('petId', 'ID of pet that needs to be fetched', 'string')],
responseMessages : [swe.invalid('id'), swe.notFound('pet')]
},
'action': function (req,res) {
console.log('findById call');
if (!req.params.petId) {
throw swe.invalid('id'); }
var id = parseInt(req.params.petId);
var pet = petData.getPetById(id);
if(pet) {
res.send(JSON.stringify(pet));
} else {
throw swe.notFound('pet', res);
}
}
};
model.js
exports.models = {
'Pet':{
'id':'Pet',
'required': ['id', 'name'],
'properties':{
'id':{
'type':'integer',
'format':'int64',
'description': 'Unique identifier for the Pet',
'minimum': '0.0',
'maximum': '100.0'
},
'name':{
'type':'string',
'description': 'Friendly name of the pet'
}
}
}
};
您好,我在我的 node.js 应用程序中使用 swagger-node-express。我已成功配置,并且工作正常。
但是现在我在使用 swagger-ui 进行记录时遇到了问题。 swagger-ui 需要 JSON 文件。 如何从这两个文件生成文档。
【问题讨论】:
标签: node.js swagger swagger-ui