xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub! swagger & api error solution - & yaml bug bug & solution

swagger ui


# run server
$ swagger project start api-app

# call api
$ curl http://127.0.0.1:8080/hello?name=xgqfrms
# { "message": "Hello, xgqfrms!" }
# http://localhost:8080/users


# install CLI
$ npm i -g swagger

# create a new swagger project
$ swagger project create api-app

# editor API
$ swagger project edit api-app


# run server
$ swagger project start api-app


# call api
$ curl http://127.0.0.1:8080/hello?name=xgqfrms
# { "message": "Hello, xgqfrms!" }

controller


function hello(req, res) {
    var name = req.swagger.params.name.value || 'stranger';
    var hello = util.format('Hello, %s!', name);
    res.json({"message": hello});
}

    paths:
        /hello:
            x-swagger-router-controller: hello_world

./api/controllers

./api/controllers/hello_world.js


{
    "name": "swagger_api_test",
    "author": {
        "name": "xgqfrms"
    },
    "version": "1.0.0",
    "description": "swagger_api_test",
    "license": "MIT",
    "scripts": {
        "app": "npm run server"
    }
}

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
swagger & api
error
solution
-  & yaml bug
bug & solution


error

bug


Error initializing middleware
Error: Swagger document(s) failed validation so the server cannot start

https://github.com/swagger-api/swagger-node/issues/354


solution

solution


$ cd ./api/swagger && swagger validate swagger.yaml

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
swagger & api
error
solution
-  & yaml bug
bug & solution


- & yaml bug

missing - symbol bug

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
swagger & api
error
solution
-  & yaml bug
bug & solution


bug & solution

Error: Response validation failed: failed schema validation

https://github.com/xgqfrms/swagger-api/issues/5#issuecomment-430860246