내 GET 서비스가 Swagger (Node.js 사용)에서 작동하지만 POST 작업을 할 수 없습니다. 누군가 내가 아래 testPost 서비스에서 실수를 저질렀다는 것을 지적 할 수 있습니까?swagger POST node.js express
내 서비스 정의하는 서비스 (파일 이름 = myService.js)에서
"/people/testPost": {
"post": {
"summary": "write the test POST.",
"description": "Test",
"operationId": "myService",
"consumes": [
"application/json"
],
"tags": [
"test"
],
"parameters": [
{
"name":"body",
"paramType":"body",
"description": "body for the POST request",
"required":false
}
]
, 나는 여기에이
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:true}));
app.post("/people/testPost", function (req, res) {
console.log("I am in the testPost service); //this gets printed
console.log("The req body", req.body) //says 'undefined'
});
을 시도하고 내가
curl -H "Content-Type: application/json" -X POST -d '{"arg1":"open", "arg2":"IVR","arg3":"", "arg4" :"1234567"}' http://localhost:8016/people/testPost
을 게시하려면 사용 내 CURL 명령입니다
Node에서 Swagger를 사용하는 간단한 POST 요청 (필요한 모든 것은 json 파일에서 "body"를 구성하는 방법입니다) 잘하면 내게로 가겠다.
어떤 사람은 내 "매개 변수"와 컬 POST를보고 변경/수정해야하는 부분을 확인하십시오.
이 서비스 정의가 큰 파일의 일부이거나 "post"및 "/ people/testPost"속성의 중괄호를 닫는 것을 잊었습니까? – num8er
요청 본문에 아무것도 보이지 않습니까? –
num8er, 조사해 주셔서 감사합니다. 예, 큰 파일의 일부입니다. POST가 Swagger와 어떻게 작동하는지 알고 싶습니다. 모든 간단한 예제 (작동하는 hello world 프로그램에 대한 링크)로 충분합니다. – JBone