trailsjs / sails-swagger

Swagger integration for sails.js
107 stars 47 forks source link

Is there library for converting js objects to valid Swagger spec? #1

Closed Znack closed 9 years ago

Znack commented 9 years ago

Hi everyone! I'm trying to connect waterline models in my sails project and swagger definitions for avoiding the duplications in models' properties. My main idea is converting waterline's "attributes" property to valid swagger doc. For example, we have this object defined in models/User.js

module.exports = {
    model: "User", // add this field only for usage in swagger converter
    attributes: {
        local: {
            email: {
              type: 'string',
              required: true,
              swagger: {
                  description: "User's email"  // I'm not sure will waterline allow me use my own properties in fields' descriptors
              }
            },
            password:{
               type: 'string',
               required: true,
              swagger: {
                  description: "User's super secret password"
              }
            }
        }
    }
}

And after converting we would be able automagically get something like:

"User":{
  "id":"User",
  "required": ["email", "password"],
  "properties":{
    "id":{
      "type":"integer",
      "format": "int64",
      "description": "User unique identifier",
      "minimum": "0.0",
      "maximum": "100.0"
    },
    "email":{
      "type":"string",
      "description": "User's email"
    }, 
    "password":{
      "type":"string",
      "description": "User's super secret password"
    },
  }
},

I didn't manage to find something appropriate among this projects: https://github.com/swagger-api/swagger-spec#nodejs If there is no such tool anywhere I will be happy to create first basic version :)

Thanks.

renanvieira commented 9 years ago

What I'm trying to do is get the routes and generate Swagger spec. But I'm being unable to find how to list all blueprint routes.

tjwebb commented 9 years ago

The routes are stored in sails.router._privateRouter.routes

renanvieira commented 9 years ago

@tjwebb The route below repeat several times (aprox. 5~6 time) for different methods in my testing application, I did something wrong or is this normal?

  { path: '/*',
    method: 'post',
    callbacks: [ [Function: routeTargetFnWrapper] ],
    keys: [],
    regexp: /^\/(.*)\/?$/i }
marcusradell commented 9 years ago

I haven't looked at it any closer, but could https://github.com/lbovet/docson#swagger be on the right track?