@@ -57,8 +57,8 @@ angular
5757 schema = angular . copy ( schema ) ;
5858 angular . forEach ( schema . allOf , function ( def ) {
5959 var ref = resolveReference ( openApiSpec , def ) ;
60- if ( ! ref . discriminator ) {
61- // do not handle inhertited properties here
60+ if ( ! def . $ref || ! ref . discriminator ) {
61+ // do not handle inherited properties here
6262 angular . merge ( schema , ref ) ;
6363 }
6464 } ) ;
@@ -207,36 +207,40 @@ angular
207207 * generates new inline model name
208208 */
209209 function getInlineModelName ( ) {
210- var name = INLINE_MODEL_NAME + ( countInLineModels ++ ) ;
211- return name ;
210+ return INLINE_MODEL_NAME + ( countInLineModels ++ ) ;
212211 }
213212
214213 /**
215214 * identify models using inheritance
216215 */
217216 this . resolveInheritance = function ( openApiSpec ) {
218217 angular . forEach ( openApiSpec . definitions , function ( schema , modelName ) {
219- if ( schema . discriminator ) {
220- schema . subModelsRef = [ ] ;
221- angular . forEach ( openApiSpec . definitions , function ( subSchema , subModelName ) {
222- if ( schema !== subSchema && subSchema . allOf ) {
223- angular . forEach ( subSchema . allOf , function ( parent ) {
224- if ( parent . $ref && modelName === getClassName ( parent ) ) {
225- subSchema . parentModelsRef = subSchema . parentModelsRef || [ ] ;
226- subSchema . parentModelsRef . push ( {
227- '$ref' : '#/definitions/' + modelName
228- } ) ;
229- schema . subModelsRef . push ( {
230- '$ref' : '#/definitions/' + subModelName
231- } ) ;
232- }
233- } ) ;
234- }
235- } ) ;
236- }
218+ resolveItemInheritance ( openApiSpec , schema , schema , modelName ) ;
237219 } ) ;
238220 } ;
239221
222+ function resolveItemInheritance ( openApiSpec , schema , def , modelName ) {
223+ if ( def . discriminator && ! schema . subModelsRef ) {
224+ schema . subModelsRef = [ ] ;
225+ angular . forEach ( openApiSpec . definitions , function ( subSchema , subModelName ) {
226+ if ( modelName !== subModelName && subSchema . allOf ) {
227+ angular . forEach ( subSchema . allOf , function ( parent ) {
228+ if ( parent . $ref && modelName === getClassName ( parent ) ) {
229+ subSchema . parentModelsRef = subSchema . parentModelsRef || [ ] ;
230+ subSchema . parentModelsRef . push ( {
231+ '$ref' : '#/definitions/' + modelName
232+ } ) ;
233+ schema . subModelsRef . push ( {
234+ '$ref' : '#/definitions/' + subModelName
235+ } ) ;
236+ }
237+ resolveItemInheritance ( openApiSpec , subSchema , parent , subModelName ) ;
238+ } ) ;
239+ }
240+ } ) ;
241+ }
242+ }
243+
240244 /**
241245 * generate a model and its submodels from schema
242246 */
@@ -252,7 +256,7 @@ angular
252256 if ( schema . properties ) {
253257 // if inline model
254258 subModels [ getInlineModelName ( ) ] = schema ;
255- subModels = angular . merge ( subModels , findAllModels ( openApiSpec , schema , subModelIds ) ) ;
259+ angular . merge ( subModels , findAllModels ( openApiSpec , schema , subModelIds ) ) ;
256260 } else {
257261 subModels = findAllModels ( openApiSpec , schema , subModelIds ) ;
258262 }
0 commit comments