@@ -30,39 +30,38 @@ export default class Model extends Component {
3030
3131 render ( ) {
3232 let { getComponent, specSelectors, schema, required, name, isRef } = this . props
33- let ObjectModel = getComponent ( "ObjectModel" )
34- let ArrayModel = getComponent ( "ArrayModel" )
35- let PrimitiveModel = getComponent ( "PrimitiveModel" )
33+ const ObjectModel = getComponent ( "ObjectModel" )
34+ const ArrayModel = getComponent ( "ArrayModel" )
35+ const PrimitiveModel = getComponent ( "PrimitiveModel" )
36+ let type = "object"
3637 let $$ref = schema && schema . get ( "$$ref" )
37- let modelName = $$ref && this . getModelName ( $$ref )
38- let modelSchema , type
39-
40- const deprecated = specSelectors . isOAS3 ( ) && schema . get ( "deprecated" )
41-
42- if ( schema && ( schema . get ( "type" ) || schema . get ( "properties" ) ) ) {
43- modelSchema = schema
44- } else if ( $$ref ) {
45- modelSchema = this . getRefSchema ( modelName )
38+
39+ // If we weren't passed a `name` but have a ref, grab the name from the ref
40+ if ( ! name && $$ref ) {
41+ name = this . getModelName ( $$ref )
4642 }
47-
48- type = modelSchema && modelSchema . get ( "type" )
49- if ( ! type && modelSchema && modelSchema . get ( "properties" ) ) {
50- type = "object"
43+ // If we weren't passed a `schema` but have a ref, grab the schema from the ref
44+ if ( ! schema && $$ref ) {
45+ schema = this . getRefSchema ( name )
5146 }
52-
47+
48+ const deprecated = specSelectors . isOAS3 ( ) && schema . get ( "deprecated" )
49+ isRef = isRef !== undefined ? isRef : ! ! $$ref
50+ type = schema && schema . get ( "type" ) || type
51+
5352 switch ( type ) {
5453 case "object" :
5554 return < ObjectModel
5655 className = "object" { ...this . props }
57- schema = { modelSchema }
58- name = { modelName || name }
56+ schema = { schema }
57+ name = { name }
5958 deprecated = { deprecated }
60- isRef = { isRef !== undefined ? isRef : ! ! $$ref } />
59+ isRef = { isRef } />
6160 case "array" :
6261 return < ArrayModel
6362 className = "array" { ...this . props }
64- schema = { modelSchema }
65- name = { modelName || name }
63+ schema = { schema }
64+ name = { name }
6665 deprecated = { deprecated }
6766 required = { required } />
6867 case "string" :
@@ -73,9 +72,10 @@ export default class Model extends Component {
7372 return < PrimitiveModel
7473 { ...this . props }
7574 getComponent = { getComponent }
76- schema = { modelSchema }
77- name = { modelName || name }
75+ schema = { schema }
76+ name = { name }
7877 deprecated = { deprecated }
79- required = { required } /> }
78+ required = { required } />
79+ }
8080 }
8181}
0 commit comments