Coder Social home page Coder Social logo

egg-swagger-doc's People

Contributors

dg-wangtao avatar guchenhui avatar jasine avatar microud avatar mkc-yanshijie avatar sm2017 avatar yanshijie-el avatar yl2014 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

egg-swagger-doc's Issues

consumes/produces per method

We can configure consumes and produces like following

exports.swaggerdoc = {
  dirScanner: './app/controller',
  apiInfo: {
    title: 'egg-swagger',
    description: 'swagger-ui for egg',
    version: '1.0.0',
  },
  schemes: ['http', 'https'],
  consumes: ['application/json'],
  produces: ['application/json'],
  enable: true,
};

But how can set produces of a specific method?
Assume we have a download method that produces the application/octect-stream

一个请求的response就是一个自定义类型的array应该如何设置

一个api的response就是一个array,
在model中有
// 测试题
test: {
id: { type: 'integer', description: '测试题id' },
dailyReadTitle: { type: 'string', description: '测试题所在今日阅读的标题' },
planId: { type: 'integer', description: '测试题所在计划的id' },
topicId: { type: 'integer', description: '测试题所在话题的id' },
questionCode: { type: 'string', description: '测试题选项标志符' },
status: { type: 'integer', description: '测试题状态,0未答,1已答' },
questions: {
type: 'array',
itemType: 'option',
description: '测试题的问题选项',
},
},
这个请求的response是 test的array 应该如何设置 @response和 contract

捕获

Feature request : Multiple examples for a parameter

Can you please implement Multiple examples for a parameter:

parameters:
  - in: query
    name: limit
    schema:
      type: integer
      maximum: 50
    examples:       # Multiple examples
      zero:         # Distinct name
        value: 0    # Example value
        summary: A sample limit value # Optional description
      max: # Distinct name
        value: 50   # Example value
        summary: A sample limit value # Optional description

Same tag , different file

If you use

/**
 * @Controller user
 */

in two different file . we have user and user[1] as tag in swagger ui

404 Not Found

After upgrading from 1.4.3 to 1.4.3 , /swagger-ui.html returns 404 but swagger-doc works
I think #21 is wrong

@Scope

In config we can define scopes

exports.swaggerdoc = {
...
  securityDefinitions: {
    oauth2: {
       type: 'oauth2',
       tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
       flow: 'password',
       scopes: {
         'write:access_token': 'write access_token',
         'read:access_token': 'read access_token',
       },
     },
  },
...
};

But , I think there is no option to document , what scope needed to access a method , so @scope is needed

Default response

Always we have a default : successful operation in response , It must be removed
image

New versions

After my PR #27 , unfortunately you don't release a version and I see that you have huge changes and some releases
But I see that it is not currently stable and usable
When I can have a stable version?

只要在ts文件中添加备注 @Controller时就会报错

2019-08-16 16:20:25,122 ERROR 15776 [-/127.0.0.1/-/0ms GET /] nodejs.Error: [egg-swagger-doc] error at post:/agent/checkUser ,the type of response parameter does not exit
at generateResponse (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:370:17)
at getTag_Path (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:139:35)
at buildDocument (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:50:14)
at documentInit (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:497:7)
at module.exports.swaggerInit.app (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\index.js:10:3)
at app.beforeStart (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\app.js:8:5)
at Object.callFn (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-core\lib\utils\index.js:44:42)
at process.nextTick (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-core\lib\lifecycle.js:262:13)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

pid: 15776
hostname: USER-20190118FU

2019-08-16 16:20:25,124 ERROR 15776 nodejs.Error: [egg-swagger-doc] error at post:/agent/checkUser ,the type of response parameter does not exit
at generateResponse (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:370:17)
at getTag_Path (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:139:35)
at buildDocument (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:50:14)
at documentInit (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\document\index.js:497:7)
at module.exports.swaggerInit.app (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\lib\index.js:10:3)
at app.beforeStart (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-swagger-doc\app.js:8:5)
at Object.callFn (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-core\lib\utils\index.js:44:42)
at process.nextTick (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-core\lib\lifecycle.js:262:13)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

pid: 15776
hostname: USER-20190118FU

2019-08-16 16:20:25,124 ERROR 15776 [app_worker] start error, exiting with code:1
[2019-08-16 16:20:25.130] [cfork:master:3236] worker:15776 disconnect (exitedAfterDisconnect: false, state: disconnected, isDead: false, worker.disableRefork: true)
2019-08-16 16:20:25,131 ERROR 12376 nodejs.unhandledExceptionError: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
errno: "ECONNRESET"
code: "ECONNRESET"
syscall: "read"
name: "unhandledExceptionError"
pid: 12376
hostname: USER-20190118FU

[2019-08-16 16:20:25.131] [cfork:master:3236] don't fork, because worker:15776 will be kill soon
2019-08-16 16:20:25,134 INFO 3236 [master] app_worker#21:15776 disconnect, suicide: false, state: disconnected, current workers: ["21"]
[2019-08-16 16:20:25.143] [cfork:master:3236] worker:15776 exit (code: 1, exitedAfterDisconnect: false, state: dead, isDead: true, isExpected: false, worker.disableRefork: true)
2019-08-16 16:20:25,144 ERROR 3236 nodejs.AppWorkerDiedError: [master] app_worker#21:15776 died (code: 1, signal: null, suicide: false, state: dead), current workers: []
at Master.onAppExit (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-cluster\lib\master.js:510:21)
at Master.emit (events.js:182:13)
at Messenger.sendToMaster (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-cluster\lib\utils\messenger.js:137:17)
at Messenger.send (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-cluster\lib\utils\messenger.js:102:12)
at EventEmitter.cluster.on (C:\Users\Administrator\Desktop\5555\htetypescript\node_modules\egg-cluster\lib\master.js:353:22)
at EventEmitter.emit (events.js:187:15)
at ChildProcess.worker.process.once (internal/cluster/master.js:193:13)
at Object.onceWrapper (events.js:273:13)
at ChildProcess.emit (events.js:182:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
name: "AppWorkerDiedError"
pid: 3236
hostname: USER-20190118FU

npm run test 404

hello,项目clone下来后,跑npm run test跑不通,/swagger-ui.html/swagger-doc都404,需要做什么操作吗

securityDefinitions does not work

Hello.

I have added securityDefinitions like this:

securityDefinitions: {
    Bearer: {
      type: 'apiKey',
      name: 'Authorization',
      in: 'header',
    }
  },
 enableSecurity: true

Even if I add my token value in Authorize field in Swagger doc, there are no any header arguments:

image

Did I miss something?

Invalid swagger doc generated

I validate my swagger doc , I have the following error

{  
   "messages":[  
      "attribute paths.'/messages/{id}'(get).[id].example is unexpected"
   ],
   "schemaValidationMessages":[  
      {  
         "level":"error",
         "domain":"validation",
         "keyword":"pattern",
         "message":"ECMA 262 regex \"^[^{}/ :\\\\]+(?::\\d+)?$\" does not match input string \"\"",
         "schema":{  
            "loadingURI":"#",
            "pointer":"/properties/host"
         },
         "instance":{  
            "pointer":"/host"
         }
      }
   ]
}

the type of response parameter does not exit

`class AccountController extends Controller {
/**
* @router POST /login
* @response 0 body test
* @summary 登录接口
*/
async login() {
const { ctx, app, config } = this;
const name = ctx.request.body.name;
const password = ctx.request.body.password;

    const user = await app.mysql.get('user', {
        name,
    });

    if (!user || ctx.helper.md5(password) !== user.password) {
        ctx.body = ctx.ResultUtil.error(config.werror.ERR_ACCOUNT_LOGIN);
        return;
    }

    const userJSON = JSON.stringify(user);
    const token = app.jwt.sign(userJSON, app.config.jwt.secret);

    ctx.body = ctx.ResultUtil.success({ user, token });
}

}`

错误信息如下:
nodejs.Error: [egg-swagger-doc] error at post:/login ,the type of response parameter does not exit
at module.exports.app (E:\node\op-new\op-new-admin\node_modules\egg-swagger-doc\lib\swagger_loader.js:122:23)
at app.beforeStart (E:\node\op-new\op-new-admin\node_modules\egg-swagger-doc\app.js:11:21)
at Object.callFn (E:\node\op-new\op-new-admin\node_modules\egg-core\lib\utils\index.js:36:42)
at process.nextTick (E:\node\op-new\op-new-admin\node_modules\egg-core\lib\egg.js:226:13)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3

@response注释去掉就可以了,,这是为什么?怎么处理?

ts不支持

用ts的话,后缀是ts,我看了下扫描里面写死了扫描后缀为.js的文件,能不能加一个配置项,默认为扫描.js,但是可以配置为扫描其他的后缀
image

controller 多层目录扫描

由于项目需要,controller 具有多层目录结构

/controller
      /v1
         /user.js
      /v2
        /user.js

看源码已经扫描了多层目录,但是没有将扫描结果正确合并

Feature request : Describing Parameters

Please implement description for Parameters

paths:
  /users/{userId}:
    get:
      summary: Get a user by ID
      parameters:
        - in: path
          name: userId
          schema:
            type: integer
          required: true
          description: Numeric ID of the user to get

validate

Because the definition of contract and the definition of validate-rule have great similarity, the definition of contract in the current version will simply generate the corresponding validate-rule. The specific use of 'ctx.rule.' plus the Model name directly introduced .

The above model, you can use the following method when doing verification (use egg-validate)

ctx.validate(ctx.rule.createResource, ctx.request.body);

I understand that currently it is not ready for production for instance , see https://github.com/node-modules/parameter#string
When I set format as a regex value , it loose test method , As you do JSON.parse(JSON.stringify(contract));
https://github.com/Ysj291823/egg-swagger-doc/blob/master/lib/swagger_rule.js#L5

Why you do this?

@Request example

@Ysj291823 @mkc-yanshijie As you now the format of @Request is

@Request {Position} {Type} {Name} {Description}

How we can have an example for a query field ?

Wrong tag name

@Ysj291823 , @mkc-yanshijie If you create a controller under app/controller/foo/bar/foobar.js then current tag name is bar , I think it must be foo or at least foo/bar

Common response

I have a fixed error schema

{
  "code" : "string",
   "message" : "string"
}

Can I use egg-swagger-doc to produce the following responses in my document

{
  "code" : "NOT_FOUND",
   "message" : "string"
}
{
  "code" : "FORBIDDEN",
   "message" : "string"
}
{
  "code" : "RATE_LIMIT",
   "message" : "string"
}

I want to list error codes in responses

how to set global parameters?

the global config is following:

  config.swaggerdoc = {
    parameters: [
      {
        description: 'user token',
        name: 'accessToken',
        in: 'header',
      },
    ],
    securityDefinitions: {
      apiKey: {
        type: 'apiKey',
        description: 'user token',
        name: 'accessToken',
        in: 'header',
      },
    },
  };

the two config both are not effective, i want to set a global header params
i think it will be a useful functions.

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.