Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Alino/sails-swagger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.1.5
Choose a base ref
...
head repository: Alino/sails-swagger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 7 commits
  • 6 files changed
  • 1 contributor

Commits on Jul 25, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d59341c View commit details
  2. version bump

    Alino committed Jul 25, 2018
    Copy the full SHA
    cd0b0f5 View commit details
  3. fix a bug in logic

    Alino committed Jul 25, 2018
    Copy the full SHA
    f2500fe View commit details
  4. version bump

    Alino committed Jul 25, 2018
    Copy the full SHA
    d4da3ab View commit details

Commits on Jul 29, 2018

  1. Copy the full SHA
    3261b21 View commit details
  2. version bump

    Alino committed Jul 29, 2018
    Copy the full SHA
    c2ce431 View commit details

Commits on Jul 30, 2018

  1. Copy the full SHA
    f833b58 View commit details
Showing with 7,427 additions and 1,527 deletions.
  1. +2 −1 README.md
  2. +26 −7 lib/xfmr.js
  3. +1,628 −1,510 package-lock.json
  4. +3 −2 package.json
  5. +57 −7 test/xfmr.test.js
  6. +5,711 −0 yarn.lock
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ module.exports.swagger = {
},
definitions: {
// your optional additional custom #/definitions
}
},
ignoredRoutes: [] // routes that should not be picked into swagger file
};
```

33 changes: 26 additions & 7 deletions lib/xfmr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hoek from 'hoek'
import _ from 'lodash'
import { _ as lodash } from 'lodash-new'
import Spec from './spec'
import pluralize from 'pluralize'

@@ -85,7 +86,9 @@ const Transformer = {
getDefinitions(sails) {
let definitions = _.transform(sails.models, (definitions, model, modelName) => {
definitions[model.identity] = {
properties: Transformer.getDefinitionProperties(model.definition)
properties: Transformer.getDefinitionProperties(
_.merge(model._attributes, model.definition)
)
}
})
definitions = _.merge(definitions, Transformer.getDefinitionsFromSwaggerConfig(sails))
@@ -105,16 +108,31 @@ const Transformer = {
},

getDefinitionProperties(definition) {
console.log(JSON.stringify(definition, null, 2))

return _.mapValues(definition, (def, attrName) => {
let property = _.pick(def, [
'type', 'description', 'format', 'model', 'enum'
'type', 'description', 'format', 'model', 'enum', 'example', 'required', 'defaultsTo', 'collection'
])

return property.model && sails.config.blueprints.populate ?
{ '$ref': Transformer.generateDefinitionReference(property.model) }
: _.omit(_.merge(property, Spec.getPropertyType(property.type)), 'model')
if (property.model && sails.config.blueprints.populate)
return { '$ref': Transformer.generateDefinitionReference(property.model) }

if (property.collection)
return {
'type': 'array',
'items': {
'$ref': Transformer.generateDefinitionReference(property.collection)
}
}

if (property.defaultsTo) {
property.default = property.defaultsTo
delete property.defaultsTo
}

return _.chain(property)
.omit('model')
.merge(Spec.getPropertyType(property.type))
.value()
})
},

@@ -218,6 +236,7 @@ const Transformer = {
swaggerPaths[sPath] = _.merge( swaggerPaths[sPath] || {}, swaggerDefinitions[defRoute] );
}

swaggerPaths = _.omit(swaggerPaths, sails.config.swagger.ignoredRoutes);
return swaggerPaths || [];
},

Loading