@@ -2004,6 +2004,125 @@ public CodegenProperty fromProperty(String name, Schema p) {
20042004 }
20052005
20062006 String type = getSchemaType (p );
2007+ setPropertyType (property , p , name );
2008+
2009+ //Inline enum case:
2010+ if (p .getEnum () != null && !p .getEnum ().isEmpty ()) {
2011+ List <Object > _enum = p .getEnum ();
2012+ property ._enum = new ArrayList <String >();
2013+ for (Object i : _enum ) {
2014+ property ._enum .add (String .valueOf (i ));
2015+ }
2016+ property .isEnum = true ;
2017+
2018+ Map <String , Object > allowableValues = new HashMap <String , Object >();
2019+ allowableValues .put ("values" , _enum );
2020+ if (allowableValues .size () > 0 ) {
2021+ property .allowableValues = allowableValues ;
2022+ }
2023+ }
2024+
2025+ Schema referencedSchema = ModelUtils .getReferencedSchema (this .openAPI , p );
2026+ setPropertyType (property , referencedSchema , name );
2027+
2028+ //Referenced enum case:
2029+ if (referencedSchema .getEnum () != null && !referencedSchema .getEnum ().isEmpty ()) {
2030+ List <Object > _enum = referencedSchema .getEnum ();
2031+ property ._enum = new ArrayList <String >();
2032+ for (Object i : _enum ) {
2033+ property ._enum .add (String .valueOf (i ));
2034+ }
2035+ property .isEnum = true ;
2036+
2037+ Map <String , Object > allowableValues = new HashMap <String , Object >();
2038+ allowableValues .put ("values" , _enum );
2039+ if (allowableValues .size () > 0 ) {
2040+ property .allowableValues = allowableValues ;
2041+ }
2042+ }
2043+
2044+ if (referencedSchema .getNullable () != null ) {
2045+ property .isNullable = referencedSchema .getNullable ();
2046+ }
2047+
2048+ property .dataType = getTypeDeclaration (p );
2049+ property .dataFormat = p .getFormat ();
2050+ property .baseType = getSchemaType (p );
2051+
2052+ // this can cause issues for clients which don't support enums
2053+ if (property .isEnum ) {
2054+ property .datatypeWithEnum = toEnumName (property );
2055+ property .enumName = toEnumName (property );
2056+ } else {
2057+ property .datatypeWithEnum = property .dataType ;
2058+ }
2059+
2060+ if (ModelUtils .isArraySchema (p )) {
2061+ property .isContainer = true ;
2062+ property .isListContainer = true ;
2063+ property .containerType = "array" ;
2064+ property .baseType = getSchemaType (p );
2065+ if (p .getXml () != null ) {
2066+ property .isXmlWrapped = p .getXml ().getWrapped () == null ? false : p .getXml ().getWrapped ();
2067+ property .xmlPrefix = p .getXml ().getPrefix ();
2068+ property .xmlNamespace = p .getXml ().getNamespace ();
2069+ property .xmlName = p .getXml ().getName ();
2070+ }
2071+
2072+ // handle inner property
2073+ property .maxItems = p .getMaxItems ();
2074+ property .minItems = p .getMinItems ();
2075+ String itemName = null ;
2076+ if (p .getExtensions () != null && p .getExtensions ().get ("x-item-name" ) != null ) {
2077+ itemName = p .getExtensions ().get ("x-item-name" ).toString ();
2078+ }
2079+ if (itemName == null ) {
2080+ itemName = property .name ;
2081+ }
2082+ Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ((ArraySchema ) p ).getItems ());
2083+ if (innerSchema == null ) {
2084+ LOGGER .error ("Undefined array inner type for `{}`. Default to String." , p .getName ());
2085+ innerSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to undefined type" );
2086+ ((ArraySchema ) p ).setItems (innerSchema );
2087+ }
2088+ CodegenProperty cp = fromProperty (itemName , innerSchema );
2089+ updatePropertyForArray (property , cp );
2090+ } else if (ModelUtils .isMapSchema (p )) {
2091+ property .isContainer = true ;
2092+ property .isMapContainer = true ;
2093+ property .containerType = "map" ;
2094+ property .baseType = getSchemaType (p );
2095+ property .minItems = p .getMinProperties ();
2096+ property .maxItems = p .getMaxProperties ();
2097+
2098+ // handle inner property
2099+ Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getAdditionalProperties (p ));
2100+ if (innerSchema == null ) {
2101+ LOGGER .error ("Undefined map inner type for `{}`. Default to String." , p .getName ());
2102+ innerSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to undefined type" );
2103+ p .setAdditionalProperties (innerSchema );
2104+ }
2105+ CodegenProperty cp = fromProperty ("inner" , innerSchema );
2106+ updatePropertyForMap (property , cp );
2107+ } else if (ModelUtils .isFreeFormObject (p )) {
2108+ property .isFreeFormObject = true ;
2109+ property .baseType = getSchemaType (p );
2110+ } else { // model
2111+ // TODO revise the logic below
2112+ //if (StringUtils.isNotBlank(p.get$ref())) {
2113+ // property.baseType = getSimpleRef(p.get$ref());
2114+ //}
2115+ // --END of revision
2116+ property .isModel = ModelUtils .isModel (p );
2117+ setNonArrayMapProperty (property , type );
2118+ }
2119+
2120+ LOGGER .debug ("debugging from property return: " + property );
2121+ return property ;
2122+ }
2123+
2124+
2125+ protected void setPropertyType (CodegenProperty property , Schema p , String name ) {
20072126 if (ModelUtils .isIntegerSchema (p )) { // integer type
20082127 property .isNumeric = Boolean .TRUE ;
20092128 if (SchemaTypeUtil .INTEGER64_FORMAT .equals (p .getFormat ())) { // int64/long format
@@ -2117,114 +2236,6 @@ public CodegenProperty fromProperty(String name, Schema p) {
21172236 p .setAdditionalProperties (innerSchema );
21182237 }
21192238 }
2120-
2121- //Inline enum case:
2122- if (p .getEnum () != null && !p .getEnum ().isEmpty ()) {
2123- List <Object > _enum = p .getEnum ();
2124- property ._enum = new ArrayList <String >();
2125- for (Object i : _enum ) {
2126- property ._enum .add (String .valueOf (i ));
2127- }
2128- property .isEnum = true ;
2129-
2130- Map <String , Object > allowableValues = new HashMap <String , Object >();
2131- allowableValues .put ("values" , _enum );
2132- if (allowableValues .size () > 0 ) {
2133- property .allowableValues = allowableValues ;
2134- }
2135- }
2136-
2137- Schema referencedSchema = ModelUtils .getReferencedSchema (this .openAPI , p );
2138-
2139- //Referenced enum case:
2140- if (referencedSchema .getEnum () != null && !referencedSchema .getEnum ().isEmpty ()) {
2141- List <Object > _enum = referencedSchema .getEnum ();
2142-
2143- Map <String , Object > allowableValues = new HashMap <String , Object >();
2144- allowableValues .put ("values" , _enum );
2145- if (allowableValues .size () > 0 ) {
2146- property .allowableValues = allowableValues ;
2147- }
2148- }
2149-
2150- if (referencedSchema .getNullable () != null ) {
2151- property .isNullable = referencedSchema .getNullable ();
2152- }
2153-
2154- property .dataType = getTypeDeclaration (p );
2155- property .dataFormat = p .getFormat ();
2156- property .baseType = getSchemaType (p );
2157-
2158- // this can cause issues for clients which don't support enums
2159- if (property .isEnum ) {
2160- property .datatypeWithEnum = toEnumName (property );
2161- property .enumName = toEnumName (property );
2162- } else {
2163- property .datatypeWithEnum = property .dataType ;
2164- }
2165-
2166- if (ModelUtils .isArraySchema (p )) {
2167- property .isContainer = true ;
2168- property .isListContainer = true ;
2169- property .containerType = "array" ;
2170- property .baseType = getSchemaType (p );
2171- if (p .getXml () != null ) {
2172- property .isXmlWrapped = p .getXml ().getWrapped () == null ? false : p .getXml ().getWrapped ();
2173- property .xmlPrefix = p .getXml ().getPrefix ();
2174- property .xmlNamespace = p .getXml ().getNamespace ();
2175- property .xmlName = p .getXml ().getName ();
2176- }
2177-
2178- // handle inner property
2179- property .maxItems = p .getMaxItems ();
2180- property .minItems = p .getMinItems ();
2181- String itemName = null ;
2182- if (p .getExtensions () != null && p .getExtensions ().get ("x-item-name" ) != null ) {
2183- itemName = p .getExtensions ().get ("x-item-name" ).toString ();
2184- }
2185- if (itemName == null ) {
2186- itemName = property .name ;
2187- }
2188- Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ((ArraySchema ) p ).getItems ());
2189- if (innerSchema == null ) {
2190- LOGGER .error ("Undefined array inner type for `{}`. Default to String." , p .getName ());
2191- innerSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to undefined type" );
2192- ((ArraySchema ) p ).setItems (innerSchema );
2193- }
2194- CodegenProperty cp = fromProperty (itemName , innerSchema );
2195- updatePropertyForArray (property , cp );
2196- } else if (ModelUtils .isMapSchema (p )) {
2197- property .isContainer = true ;
2198- property .isMapContainer = true ;
2199- property .containerType = "map" ;
2200- property .baseType = getSchemaType (p );
2201- property .minItems = p .getMinProperties ();
2202- property .maxItems = p .getMaxProperties ();
2203-
2204- // handle inner property
2205- Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getAdditionalProperties (p ));
2206- if (innerSchema == null ) {
2207- LOGGER .error ("Undefined map inner type for `{}`. Default to String." , p .getName ());
2208- innerSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to undefined type" );
2209- p .setAdditionalProperties (innerSchema );
2210- }
2211- CodegenProperty cp = fromProperty ("inner" , innerSchema );
2212- updatePropertyForMap (property , cp );
2213- } else if (ModelUtils .isFreeFormObject (p )) {
2214- property .isFreeFormObject = true ;
2215- property .baseType = getSchemaType (p );
2216- } else { // model
2217- // TODO revise the logic below
2218- //if (StringUtils.isNotBlank(p.get$ref())) {
2219- // property.baseType = getSimpleRef(p.get$ref());
2220- //}
2221- // --END of revision
2222- property .isModel = ModelUtils .isModel (p );
2223- setNonArrayMapProperty (property , type );
2224- }
2225-
2226- LOGGER .debug ("debugging from property return: " + property );
2227- return property ;
22282239 }
22292240
22302241 /**
0 commit comments