1- var Hoek = require ( 'hoek' )
2- var _ = require ( 'lodash' )
3- var utils = require ( './utils' )
4- var generator = module . exports = { }
1+ 'use strict'
2+
3+ const Hoek = require ( 'hoek' )
4+ const _ = require ( 'lodash' )
5+ const utils = require ( './utils' )
6+ const generator = module . exports = { }
57
68generator . createProperties = function ( schema , definitions ) {
7- return _ . reduce ( Hoek . reach ( schema , '_inner.children' ) , function ( memo , property ) {
8- var schema = generator . fromJoiSchema ( property . schema , definitions )
9+ return _ . reduce ( Hoek . reach ( schema , '_inner.children' ) , ( memo , property ) => {
10+ const schema = generator . fromJoiSchema ( property . schema , definitions )
911
1012 if ( schema ) {
1113 memo [ property . key ] = schema
@@ -16,31 +18,31 @@ generator.createProperties = function (schema, definitions) {
1618}
1719
1820generator . newModel = function ( schema , definitions ) {
19- var schemaType = utils . getPrimitiveType ( schema )
21+ const schemaType = utils . getPrimitiveType ( schema )
2022 Hoek . assert ( schemaType !== 'array' , 'generator.newModel does not support array schema' )
2123
2224 // Don't generate model for primitive types!
2325 if ( utils . isPrimitiveSwaggerType ( schemaType ) ) {
24- var format = utils . getFormat ( schema )
26+ const format = utils . getFormat ( schema )
2527
2628 return {
2729 type : utils . mapSwaggerType ( schema , schemaType ) ,
2830 format : format
2931 }
3032 }
3133
32- var model = {
34+ const model = {
3335 required : [ ] ,
3436 properties : { }
3537 }
3638
37- var properties = generator . createProperties ( schema , definitions )
38- model . properties = _ . reduce ( properties , function ( memo , value , key ) {
39+ let properties = generator . createProperties ( schema , definitions )
40+ model . properties = _ . reduce ( properties , ( memo , value , key ) => {
3941 if ( value . required ) {
4042 model . required . push ( key )
4143 }
4244
43- var pick = _ . has ( value , '$ref' ) ? [ '$ref' ] : [ 'type' , 'format' , 'items' , 'default' , 'description' , '$ref' , 'enum' , 'minimum' , 'maximum' , 'minLength' , 'maxLength' , 'collectionFormat' ]
45+ const pick = _ . has ( value , '$ref' ) ? [ '$ref' ] : [ 'type' , 'format' , 'items' , 'default' , 'description' , '$ref' , 'enum' , 'minimum' , 'maximum' , 'minLength' , 'maxLength' , 'collectionFormat' ]
4446 memo [ key ] = _ . pick ( value , pick )
4547 return memo
4648 } , model . properties )
@@ -49,11 +51,11 @@ generator.newModel = function (schema, definitions) {
4951 delete model . required
5052 }
5153
52- var modelName = utils . generateNameWithFallback ( schema , definitions , model )
54+ let modelName = utils . generateNameWithFallback ( schema , definitions , model )
5355 definitions [ modelName ] = model
5456
5557 return {
56- $ref : ' #/definitions/' + modelName
58+ $ref : ` #/definitions/${ modelName } `
5759 }
5860}
5961
@@ -62,10 +64,10 @@ generator.newArray = function (schema, definitions, arrayModel) {
6264 arrayModel . type = 'array'
6365
6466 // TODO: Improve array handling, multiple inclusion types are not supported by swagger specs. Only possiblity would be to extract common denominator as interface-schema.
65- var firstInclusionType = utils . getFirstInclusionType ( schema )
67+ const firstInclusionType = utils . getFirstInclusionType ( schema )
6668
6769 if ( firstInclusionType ) {
68- var firstInclusionTypeModel = generator . fromJoiSchema ( firstInclusionType , definitions )
70+ const firstInclusionTypeModel = generator . fromJoiSchema ( firstInclusionType , definitions )
6971 if ( firstInclusionTypeModel . $ref ) {
7072 arrayModel . items = _ . pick ( firstInclusionTypeModel , [ '$ref' ] )
7173 } else {
@@ -78,32 +80,32 @@ generator.newArray = function (schema, definitions, arrayModel) {
7880
7981 return arrayModel
8082
81- /*
82- // May extract all arrays and use a reference? Sometimes inline required?
83- var required = arrayModel.required
84- delete arrayModel.required
85- var name = utils.generateNameWithFallback(schema, definitions, arrayModel)
86- definitions[name] = arrayModel
87-
88- return {
89- required: required,
90- description: arrayModel.description,
91- $ref: '#/definitions/' + name
92- }
93- */
83+ /*
84+ // May extract all arrays and use a reference? Sometimes inline required?
85+ var required = arrayModel.required
86+ delete arrayModel.required
87+ var name = utils.generateNameWithFallback(schema, definitions, arrayModel)
88+ definitions[name] = arrayModel
89+
90+ return {
91+ required: required,
92+ description: arrayModel.description,
93+ $ref: '#/definitions/' + name
94+ }
95+ */
9496}
9597
9698generator . extractAsDefinition = function ( schema , definitions , definition ) {
9799 if ( definition . type === 'array' ) {
98- var required = definition . required
100+ const required = definition . required
99101 delete definition . required
100- var name = utils . generateNameWithFallback ( schema , definitions , definition )
102+ let name = utils . generateNameWithFallback ( schema , definitions , definition )
101103 definitions [ name ] = definition
102104
103105 return {
104106 required : required ,
105107 description : definition . description ,
106- $ref : ' #/definitions/' + name
108+ $ref : ` #/definitions/${ name } `
107109 }
108110 }
109111
@@ -115,8 +117,8 @@ generator.fromJoiSchema = function (schema, definitions) {
115117 Hoek . assert ( schema . isJoi , 'Schema is no joi schema' )
116118
117119 if ( utils . isSupportedSchema ( schema ) ) {
118- var schemaType = utils . getPrimitiveType ( schema )
119- var baseModel = utils . parseBaseModelAttributes ( schema )
120+ const schemaType = utils . getPrimitiveType ( schema )
121+ const baseModel = utils . parseBaseModelAttributes ( schema )
120122
121123 if ( schemaType === 'object' ) {
122124 return Hoek . merge ( baseModel , generator . newModel ( schema , definitions ) )
0 commit comments