Code Monkey home page Code Monkey logo

koa-oai-router's People

Contributors

5ay3h avatar amazing-gao avatar dependabot[bot] avatar twz123 avatar yanick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

koa-oai-router's Issues

Not getting parameter from path

It looks like it's not parsing the parameter in path in any way.
Example: in the route /user/{userId}, the userID value is not in request.query or request.param
Could not find anywhere.

unable to mount two routers to koa

what I did:

const routerV0 = new Router({
  apiDoc: path.join(__dirname, 'api-v0'),
  apiExplorerVisible: true,
})
routerV0.mount(middleware, path.join(__dirname, 'controllers-v0'))
app.use(routerV0.routes())

const routerDash = new Router({
  apiDoc: path.join(__dirname, 'api-dash'),
  apiExplorerVisible: true,
})
routerDash.mount(middleware, path.join(__dirname, 'controllers-dash'))
app.use(routerDash.routes())

what I got:

$ curl http://localhost:8081/api-explorer
{"result":"<!-- HTML for static distribution bundle build -->\n<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\">\n    <title>Swagger UI</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"./swagger-ui.css\" >\n    <link rel=\"icon\" type=\"image/png\" href=\"./favicon-32x32.png\" sizes=\"32x32\" />\n    <link rel=\"icon\" type=\"image/png\" href=\"./favicon-16x16.png\" sizes=\"16x16\" />\n    <style>\n      html\n      {\n        box-sizing: border-box;\n        overflow: -moz-scrollbars-vertical;\n        overflow-y: scroll;\n      }\n\n      *,\n      *:before,\n      *:after\n      {\n        box-sizing: inherit;\n      }\n\n      body\n      {\n        margin:0;\n        background: #fafafa;\n      }\n    </style>\n  </head>\n\n  <body>\n    <div id=\"swagger-ui\"></div>\n\n    <script src=\"./swagger-ui-bundle.js\"> </script>\n    <script src=\"./swagger-ui-standalone-preset.js\"> </script>\n    <script>\n    window.onload = function() {\n\n      // Build a system\n      const ui = SwaggerUIBundle({\n        configUrl: \"./api-explorer-config.json\",\n        dom_id: '#swagger-ui',\n        deepLinking: true,\n        presets: [\n          SwaggerUIBundle.presets.apis,\n          SwaggerUIStandalonePreset\n        ],\n        plugins: [\n          SwaggerUIBundle.plugins.DownloadUrl\n        ],\n        layout: \"StandaloneLayout\"\n      })\n\n      window.ui = ui\n    }\n  </script>\n  </body>\n</html>\n","statusCode":200}⏎

Was it I made some mistake or two-router is not supported yet?

API Explorer shows Petstore instead of custom API

I configured the router according to document.

const router = new Router({
  apiDoc: path.join(__dirname, "api"),
  apiExplorerVisible: true
});
router.mount(middleware, path.join(__dirname, "controllers"));

All the APIs (http://localhost:8080/api/...) works fine.

The problem is, the API Explorer shows Petstore instead of my API.

deepinscreenshot_select-area_20180623022713

Validator fails for single value for arrays

I specified array parmeter as multi string:

        - in: query
          name: keywords 
          type: array
          collectionFormat: multi
          items:
            type: string

but when just single value is passed

curl localhost:3035/endpoint?keywords=mykeyword"

it fails with error

{
    "detail": {
        "dataPath": ".keywords",
        "keyword": "type",
        "message": "should be array",
        "params": {
            "type": "array"
        },
        "schemaPath": "#/properties/keywords/type"
    },
    "error": "should be array",
    "path": ".keywords",
    "status": 400,
    "type": "query"
}

What's wrong with this api path?

Hi,

General setup works fine and i can see the swagger doc with all the details of my api. However when I try to call an API with below swagger format:

'/user/{id}':
get:
x-oai-middleware:
- file: users
handler: get
parameters:
- name: Authorization
in: header
type: string
- name: id
in: path
type: integer

I get a 404. in swagger doc, my base path is set to /api. So in swagger explorer this particular api is listed as(after giving sample data);
curl -X GET "https://localhost:8000/api/user/1" -H "accept: application/json" -H "Authorization: sfasdff"

My /controller directory has users.js file with:

import koa from 'koa';
async function get(ctx:koa.Context, next:Function) {
ctx.response.body = ctx.params.id; //expects to echo the received id via path.
}

App didn't complain about whether it managed to load the controllers etc.. So i think below has worked fine;
router.mount(new routerMiddleware(), path.resolve(__dirname, 'controllers'));

Any idea why it gets a 404 ?

ctx.renderSwaggerApiExplorer is undefined

Hello,
First of all, I wanted to excuse myself for my terrible english and the quality of this issue.

While testing your module for my work project I bumped into this error, while requesting the docs/swagger-ui page:

> [email protected] start /home/marco/Projects/pollerExpress
> node --harmony api/server.js

ApiExplorer: http://127.0.0.1:9000/docs

  TypeError: ctx.renderSwaggerApiExplorer is not a function
      at /home/marco/Projects/pollerExpress/node_modules/koa-oai-router/dist/oai-explorer.js:53:17
      at Generator.next (<anonymous>)
      at step (/home/marco/Projects/pollerExpress/node_modules/koa-oai-router/dist/oai-explorer.js:33:191)
      at /home/marco/Projects/pollerExpress/node_modules/koa-oai-router/dist/oai-explorer.js:33:437
      at Promise (<anonymous>)
      at /home/marco/Projects/pollerExpress/node_modules/koa-oai-router/dist/oai-explorer.js:33:99
      at /home/marco/Projects/pollerExpress/node_modules/koa-oai-router/dist/oai-explorer.js:57:19
      at /home/marco/Projects/pollerExpress/node_modules/koa-mount/index.js:58:28
      at dispatch (/home/marco/Projects/pollerExpress/node_modules/koa-compose/index.js:44:32)
      at next (/home/marco/Projects/pollerExpress/node_modules/koa-compose/index.js:45:18)
      at /home/marco/Projects/pollerExpress/node_modules/koa-mount/index.js:52:26
      at dispatch (/home/marco/Projects/pollerExpress/node_modules/koa-compose/index.js:44:32)
      at next (/home/marco/Projects/pollerExpress/node_modules/koa-compose/index.js:45:18)
      at /home/marco/Projects/pollerExpress/node_modules/koa-mount/index.js:52:26
      at dispatch (/home/marco/Projects/pollerExpress/node_modules/koa-compose/index.js:44:32)
      at next (/home/marco/Projects/pollerExpress/node_modules/koa-compose/index.js:45:18)

the error is generated at ./koa-oai-router/lib/oai-explorer.js:24: await tx.renderSwaggerApiExplorer('index', options);

ctx.renderSwaggerApiExplorer should be provided by the koa-views-swagger package
but looking at it, the function exposed is, instead, ctx.render

In fact after correcting the name of the function everything was working correctly.

Unterminated Promise

An error occurred while I was testing a REST server with jest and supertest. It seems a stuck Promise in koa-oai-router was detected.

Jest has detected the following 3 open handles potentially keeping Jest from exiting:

  ●  DNSCHANNEL

      at dns.js:338:23


  ●  PROMISE



          at Promise.then (<anonymous>)
      at OAIRouter.routes (node_modules/koa-oai-router/lib/router.js:100:40)
      at Object.<anonymous> (src/index.ts:141:16)
      at Object.<anonymous> (test/app.test.ts:3:1)


  ●  PROMISE



          at Promise.then (<anonymous>)
          at Promise.catch (<anonymous>)
      at OAIRouter.routes (node_modules/koa-oai-router/lib/router.js:114:17)
      at Object.<anonymous> (src/index.ts:141:16)
      at Object.<anonymous> (test/app.test.ts:3:1)

[Question] wrap every route into a try catch

Is it possible to add a middleware as the first one of the chain for any route ? (without setting it mannually in the chain in the x-oai-controller section).

My plan is to easily wrap everything into a try catch.

How to handle file upload?

I'm trying to manage file upload in my application. I successfully implemented your lib for all "standard" routes, but now I would like, for one single route, to add the middleware koa-body to manage file upload.

And I don't find out where to put this middleware? Can you post an example? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.