1- import * as _ from 'lodash' ;
1+ import cloneDeep = require( 'lodash/cloneDeep' ) ;
2+ import get = require( 'lodash/get' ) ;
3+ import isArray = require( 'lodash/isArray' ) ;
4+ import isEmpty = require( 'lodash/isEmpty' ) ;
5+ import map = require( 'lodash/map' ) ;
6+ import mapValues = require( 'lodash/mapValues' ) ;
27import { IResolvedProp } from './types' ;
38
49const _dereferenceSchema = ( options : any = { } ) => {
@@ -18,11 +23,11 @@ const _dereferenceSchema = (options: any = {}) => {
1823 let isCombiner ;
1924 let isAllOf ;
2025
21- if ( _ . isEmpty ( schemas ) ) {
26+ if ( isEmpty ( schemas ) ) {
2227 return schema ;
2328 }
2429
25- if ( _ . get ( schema , '$ref' ) ) {
30+ if ( get ( schema , '$ref' ) ) {
2631 schema = _dereferenceSchemaRef ( {
2732 target : schema ,
2833 schemas,
@@ -34,9 +39,9 @@ const _dereferenceSchema = (options: any = {}) => {
3439 hideInheritedFrom,
3540 isRoot,
3641 } ) ;
37- } else if ( _ . get ( schema , 'properties' ) ) {
42+ } else if ( get ( schema , 'properties' ) ) {
3843 properties = schema . properties ;
39- } else if ( _ . get ( schema , 'items' ) ) {
44+ } else if ( get ( schema , 'items' ) ) {
4045 if ( schema . items . $ref ) {
4146 schema . items = _dereferenceSchemaRef ( {
4247 target : schema . items ,
@@ -60,21 +65,21 @@ const _dereferenceSchema = (options: any = {}) => {
6065 properties = schema . items . anyOf ;
6166 isCombiner = true ;
6267 }
63- } else if ( _ . get ( schema , 'allOf' ) ) {
68+ } else if ( get ( schema , 'allOf' ) ) {
6469 properties = schema . allOf ;
6570 isCombiner = true ;
6671 isAllOf = true ;
67- } else if ( _ . get ( schema , 'oneOf' ) ) {
72+ } else if ( get ( schema , 'oneOf' ) ) {
6873 properties = schema . oneOf ;
6974 isCombiner = true ;
70- } else if ( _ . get ( schema , 'anyOf' ) ) {
75+ } else if ( get ( schema , 'anyOf' ) ) {
7176 properties = schema . anyOf ;
7277 isCombiner = true ;
73- } else if ( _ . get ( schema , 'additionalProperties' ) ) {
78+ } else if ( get ( schema , 'additionalProperties' ) ) {
7479 properties = schema . additionalProperties ;
75- } else if ( _ . get ( schema , 'patternProperties' ) ) {
80+ } else if ( get ( schema , 'patternProperties' ) ) {
7681 properties = schema . patternProperties ;
77- } else if ( _ . get ( schema , 'dependencies' ) ) {
82+ } else if ( get ( schema , 'dependencies' ) ) {
7883 properties = schema . dependencies ;
7984 }
8085
@@ -131,7 +136,7 @@ const _dereferenceSchemaRef = (options: any = {}) => {
131136
132137 // defensive clone to protect against mutations :(
133138 const refPath = ref . replace ( '#/' , '' ) . split ( '/' ) ;
134- const schema = _ . cloneDeep ( _ . get ( schemas , refPath . concat ( 'schema' ) ) || _ . get ( schemas , refPath ) ) ;
139+ const schema = cloneDeep ( get ( schemas , refPath . concat ( 'schema' ) ) || get ( schemas , refPath ) ) ;
135140
136141 if ( schema ) {
137142 let propsInherited : boolean | string = false ;
@@ -161,12 +166,12 @@ const _dereferenceSchemaRef = (options: any = {}) => {
161166 }
162167
163168 if ( propsInherited ) {
164- const iterFunc = _ . isArray ( schema [ propsInherited ] ) ? _ . map : _ . mapValues ;
169+ const iterFunc = isArray ( schema [ propsInherited ] ) ? map : mapValues ;
165170
166171 // @ts -ignore
167172 schema [ propsInherited ] = iterFunc ( schema [ propsInherited ] , item => {
168173 if ( item . properties ) {
169- item . properties = _ . mapValues ( item . properties , val => {
174+ item . properties = mapValues ( item . properties , val => {
170175 return {
171176 ...val ,
172177 // Don't show hideInheritedFrom for combiners anymore.
@@ -219,7 +224,7 @@ const _dereferenceSchemaRef = (options: any = {}) => {
219224/**
220225 * Replace all $ref's with their respective JSON Schema objects
221226 * @param {Object } target - Schema to dereference
222- * @param {Object } schemas - Schemas that the target may reference. For example a Swagger or {definitions: {}}. This function will use _. get and .split('/') to find the reference path. #/responses/foo will be in {responses: {foo: {}}}
227+ * @param {Object } schemas - Schemas that the target may reference. For example a Swagger or {definitions: {}}. This function will use get and .split('/') to find the reference path. #/responses/foo will be in {responses: {foo: {}}}
223228 * @param {Boolean } hideInheritedFrom - Don't add the __inheritedFrom property to the dereferenced schema
224229 * @return {Object } - An object with no $refs
225230 */
@@ -228,7 +233,7 @@ export const dereferenceSchema = (target: object, schemas: object, hideInherited
228233 return { } ;
229234 }
230235
231- const schema = _ . cloneDeep ( target ) ;
236+ const schema = cloneDeep ( target ) ;
232237
233238 return _dereferenceSchema ( { target : schema , schemas, hideInheritedFrom, isRoot : true } ) ;
234239} ;
0 commit comments