@@ -739,49 +739,51 @@ let QUERYPARAM = 'query',
739
739
/**
740
740
* Processes and resolves types from Nested JSON schema structure.
741
741
*
742
- * @param {Object } resolvedSchema - The resolved JSON schema to process.
743
- * @param {Set<string> } [parentRequired=new Set()] - A set of parent-required property keys to inherit.
742
+ * @param {Object } resolvedSchema - The resolved JSON schema to process for type extraction.
744
743
* @returns {Object } The processed schema details.
745
744
*/
746
745
processSchema = ( resolvedSchema ) => {
747
746
if ( resolvedSchema . type === 'object' && resolvedSchema . properties ) {
748
747
const schemaDetails = {
749
- type : resolvedSchema . type || 'unknown' ,
748
+ type : resolvedSchema . type ,
750
749
properties : { } ,
751
750
required : [ ]
752
751
} ,
753
752
requiredProperties = new Set ( resolvedSchema . required || [ ] ) ;
754
753
755
- for ( let [ key , prop ] of Object . entries ( resolvedSchema . properties ) ) {
754
+ for ( let [ propName , propValue ] of Object . entries ( resolvedSchema . properties ) ) {
755
+ if ( ! propValue . type ) {
756
+ continue ;
757
+ }
756
758
const propertyDetails = {
757
- type : prop . type || 'unknown' ,
758
- deprecated : prop . deprecated ,
759
- enum : prop . enum || undefined ,
760
- minLength : prop . minLength !== undefined ? prop . minLength : undefined ,
761
- maxLength : prop . maxLength !== undefined ? prop . maxLength : undefined ,
762
- minimum : prop . minimum !== undefined ? prop . minimum : undefined ,
763
- maximum : prop . maximum !== undefined ? prop . maximum : undefined ,
764
- pattern : prop . pattern || undefined ,
765
- example : prop . example !== undefined ? prop . example : undefined ,
766
- description : prop . description !== undefined ? prop . description : undefined ,
767
- format : prop . format || undefined
759
+ type : propValue . type ,
760
+ deprecated : propValue . deprecated ,
761
+ enum : propValue . enum || undefined ,
762
+ minLength : propValue . minLength ,
763
+ maxLength : propValue . maxLength ,
764
+ minimum : propValue . minimum ,
765
+ maximum : propValue . maximum ,
766
+ pattern : propValue . pattern ,
767
+ example : propValue . example ,
768
+ description : propValue . description ,
769
+ format : propValue . format
768
770
} ;
769
771
770
- if ( requiredProperties . has ( key ) ) {
771
- schemaDetails . required . push ( key ) ;
772
+ if ( requiredProperties . has ( propName ) ) {
773
+ schemaDetails . required . push ( propName ) ;
772
774
}
773
- if ( prop . properties ) {
774
- let res = processSchema ( prop ) ;
775
- propertyDetails . properties = res . properties ;
776
- if ( res . required ) {
777
- propertyDetails . required = res . required ;
775
+ if ( propValue . properties ) {
776
+ let processedProperties = processSchema ( propValue ) ;
777
+ propertyDetails . properties = processedProperties . properties ;
778
+ if ( processedProperties . required ) {
779
+ propertyDetails . required = processedProperties . required ;
778
780
}
779
781
}
780
- else if ( prop . type === 'array' && prop . items ) {
781
- propertyDetails . items = processSchema ( prop . items ) ;
782
+ else if ( propValue . type === 'array' && propValue . items ) {
783
+ propertyDetails . items = processSchema ( propValue . items ) ;
782
784
}
783
785
784
- schemaDetails . properties [ key ] = propertyDetails ;
786
+ schemaDetails . properties [ propName ] = propertyDetails ;
785
787
}
786
788
if ( schemaDetails . required && schemaDetails . required . length === 0 ) {
787
789
schemaDetails . required = undefined ;
@@ -790,15 +792,15 @@ let QUERYPARAM = 'query',
790
792
}
791
793
else if ( resolvedSchema . type === 'array' && resolvedSchema . items ) {
792
794
const arrayDetails = {
793
- type : resolvedSchema . type || 'unknown' ,
795
+ type : resolvedSchema . type ,
794
796
items : processSchema ( resolvedSchema . items )
795
797
} ;
796
798
if ( resolvedSchema . minItems !== undefined ) { arrayDetails . minItems = resolvedSchema . minItems ; }
797
799
if ( resolvedSchema . maxItems !== undefined ) { arrayDetails . maxItems = resolvedSchema . maxItems ; }
798
800
return arrayDetails ;
799
801
}
800
802
return {
801
- type : resolvedSchema . type || 'unknown'
803
+ type : resolvedSchema . type
802
804
} ;
803
805
} ,
804
806
@@ -820,6 +822,7 @@ let QUERYPARAM = 'query',
820
822
) => {
821
823
// reset readOnly and writeOnly prop cache before resolving schema to make sure we have fresh cache
822
824
resetReadWritePropCache ( context ) ;
825
+
823
826
let resolvedSchema = _resolveSchema ( context , schema , stack , resolveFor , seenRef ) ;
824
827
825
828
/**
@@ -844,6 +847,7 @@ let QUERYPARAM = 'query',
844
847
_ . unset ( resolvedSchema , utils . getJsonPathArray ( key ) ) ;
845
848
} ) ;
846
849
}
850
+
847
851
return resolvedSchema ;
848
852
} ,
849
853
@@ -1590,6 +1594,7 @@ let QUERYPARAM = 'query',
1590
1594
}
1591
1595
} ) ;
1592
1596
}
1597
+
1593
1598
// This is to handle cases when the jsf throws errors on finding unsupported types/formats
1594
1599
try {
1595
1600
bodyData = fakeSchema ( context , requestBodySchema , shouldGenerateFromExample ) ;
@@ -1603,11 +1608,12 @@ let QUERYPARAM = 'query',
1603
1608
bodyData = '' ;
1604
1609
}
1605
1610
}
1611
+
1606
1612
}
1607
- if ( context . enableTypeFetching && requestBodySchema . type !== undefined &&
1608
- requestBodySchema . type !== 'unknown' ) {
1609
- let properties = processSchema ( requestBodySchema ) ;
1610
- resolvedSchemaTypes . push ( properties ) ;
1613
+
1614
+ if ( context . enableTypeFetching && requestBodySchema . type !== undefined ) {
1615
+ const requestBodySchemaTypes = processSchema ( requestBodySchema ) ;
1616
+ resolvedSchemaTypes . push ( requestBodySchemaTypes ) ;
1611
1617
}
1612
1618
1613
1619
// Generate multiple examples when either request or response contains more than one example
@@ -1639,13 +1645,16 @@ let QUERYPARAM = 'query',
1639
1645
if ( _ . isEmpty ( matchedRequestBodyExamples ) ) {
1640
1646
matchedRequestBodyExamples = requestBodyExamples ;
1641
1647
}
1648
+
1642
1649
const generatedBody = generateExamples (
1643
1650
context , responseExamples , matchedRequestBodyExamples , requestBodySchema , isBodyTypeXML ) ;
1651
+
1644
1652
return {
1645
1653
generatedBody,
1646
1654
resolvedSchemaType : resolvedSchemaTypes [ 0 ]
1647
1655
} ;
1648
1656
}
1657
+
1649
1658
return {
1650
1659
generatedBody : [ { [ bodyKey ] : bodyData } ] ,
1651
1660
resolvedSchemaType : resolvedSchemaTypes [ 0 ]
@@ -1660,7 +1669,7 @@ let QUERYPARAM = 'query',
1660
1669
urlencoded : urlEncodedParams
1661
1670
} ,
1662
1671
resolvedBody ,
1663
- result ,
1672
+ resolvedBodyResult ,
1664
1673
resolvedSchemaTypeObject ;
1665
1674
1666
1675
if ( _ . isEmpty ( requestBodyContent ) ) {
@@ -1671,15 +1680,16 @@ let QUERYPARAM = 'query',
1671
1680
requestBodyContent . schema = resolveSchema ( context , requestBodyContent . schema ) ;
1672
1681
}
1673
1682
1674
- result = resolveBodyData ( context , requestBodyContent . schema ) ;
1683
+ resolvedBodyResult = resolveBodyData ( context , requestBodyContent . schema ) ;
1675
1684
resolvedBody =
1676
- result && Array . isArray ( result . generatedBody ) && result . generatedBody . length > 0 ?
1677
- result . generatedBody [ 0 ] :
1678
- undefined ;
1679
- resolvedSchemaTypeObject =
1680
- result && result . resolvedSchemaType !== undefined ?
1681
- result . resolvedSchemaType :
1685
+
1686
+ resolvedBodyResult && Array . isArray ( resolvedBodyResult . generatedBody ) &&
1687
+ resolvedBodyResult . generatedBody [ 0 ] ?
1688
+ resolvedBodyResult . generatedBody [ 0 ] :
1682
1689
undefined ;
1690
+
1691
+ resolvedSchemaTypeObject = resolvedBodyResult &&
1692
+ resolvedBodyResult . resolvedSchemaType ? resolvedBodyResult . resolvedSchemaType : undefined ;
1683
1693
resolvedBody && ( bodyData = resolvedBody . request ) ;
1684
1694
1685
1695
const encoding = requestBodyContent . encoding || { } ;
@@ -1728,22 +1738,25 @@ let QUERYPARAM = 'query',
1728
1738
formdata : formDataParams
1729
1739
} ,
1730
1740
resolvedBody ,
1731
- result ,
1741
+ resolvedBodyResult ,
1732
1742
resolvedSchemaTypeObject ;
1733
1743
1734
1744
if ( _ . isEmpty ( requestBodyContent ) ) {
1735
1745
return requestBodyData ;
1736
1746
}
1737
1747
1738
- result = resolveBodyData ( context , requestBodyContent . schema ) ;
1748
+ resolvedBodyResult = resolveBodyData ( context , requestBodyContent . schema ) ;
1739
1749
resolvedBody =
1740
- result && Array . isArray ( result . generatedBody ) && result . generatedBody . length > 0 ?
1741
- result . generatedBody [ 0 ] :
1742
- undefined ;
1750
+ resolvedBodyResult && Array . isArray ( resolvedBodyResult . generatedBody ) &&
1751
+ resolvedBodyResult . generatedBody [ 0 ] ?
1752
+ resolvedBodyResult . generatedBody [ 0 ] :
1753
+ undefined ;
1754
+
1743
1755
resolvedSchemaTypeObject =
1744
- result && result . resolvedSchemaType !== undefined ?
1756
+ resolvedBodyResult && resolvedBodyResult . resolvedSchemaType ?
1745
1757
result . resolvedSchemaType :
1746
1758
undefined ;
1759
+
1747
1760
resolvedBody && ( bodyData = resolvedBody . request ) ;
1748
1761
1749
1762
encoding = _ . get ( requestBodyContent , 'encoding' , { } ) ;
@@ -1848,7 +1861,7 @@ let QUERYPARAM = 'query',
1848
1861
dataToBeReturned = { } ,
1849
1862
{ concreteUtils } = context ,
1850
1863
resolvedBody ,
1851
- result ,
1864
+ resolvedBodyResult ,
1852
1865
resolvedSchemaTypeObject ;
1853
1866
1854
1867
headerFamily = getHeaderFamily ( bodyType ) ;
@@ -1860,15 +1873,18 @@ let QUERYPARAM = 'query',
1860
1873
}
1861
1874
// Handling for Raw mode data
1862
1875
else {
1863
- result = resolveBodyData ( context , requestContent [ bodyType ] , bodyType ) ;
1876
+ resolvedBodyResult = resolveBodyData ( context , requestContent [ bodyType ] , bodyType ) ;
1864
1877
resolvedBody =
1865
- result && Array . isArray ( result . generatedBody ) && result . generatedBody . length > 0 ?
1866
- result . generatedBody [ 0 ] :
1867
- undefined ;
1878
+ resolvedBodyResult && Array . isArray ( resolvedBodyResult . generatedBody ) &&
1879
+ resolvedBodyResult . generatedBody [ 0 ] ?
1880
+ resolvedBodyResult . generatedBody [ 0 ] :
1881
+ undefined ;
1882
+
1868
1883
resolvedSchemaTypeObject =
1869
- result && result . resolvedSchemaType !== undefined ?
1870
- result . resolvedSchemaType :
1884
+ resolvedBodyResult && resolvedBodyResult . resolvedSchemaType ?
1885
+ resolvedBodyResult . resolvedSchemaType :
1871
1886
undefined ;
1887
+
1872
1888
resolvedBody && ( bodyData = resolvedBody . request ) ;
1873
1889
1874
1890
if ( ( bodyType === TEXT_XML || bodyType === APP_XML || headerFamily === HEADER_TYPE . XML ) ) {
@@ -2015,20 +2031,21 @@ let QUERYPARAM = 'query',
2015
2031
return reqParam ;
2016
2032
} ,
2017
2033
2018
- createProperties = ( schema , param ) => {
2034
+ createProperties = ( param ) => {
2035
+ const { schema } = param ;
2019
2036
return {
2020
- type : schema . type || 'unknown' ,
2021
- format : schema . format || undefined ,
2022
- default : schema . default !== undefined ? schema . default : undefined ,
2037
+ type : schema . type ,
2038
+ format : schema . format ,
2039
+ default : schema . default ,
2023
2040
required : param . required || false ,
2024
2041
deprecated : param . deprecated || false ,
2025
2042
enum : schema . enum || undefined ,
2026
- minLength : schema . minLength !== undefined ? schema . minLength : undefined ,
2027
- maxLength : schema . maxLength !== undefined ? schema . maxLength : undefined ,
2028
- minimum : schema . minimum !== undefined ? schema . minimum : undefined ,
2029
- maximum : schema . maximum !== undefined ? schema . maximum : undefined ,
2030
- pattern : schema . pattern || undefined ,
2031
- example : schema . example !== undefined ? schema . example : undefined
2043
+ minLength : schema . minLength ,
2044
+ maxLength : schema . maxLength ,
2045
+ minimum : schema . minimum ,
2046
+ maximum : schema . maximum ,
2047
+ pattern : schema . pattern ,
2048
+ example : schema . example
2032
2049
} ;
2033
2050
} ,
2034
2051
@@ -2060,15 +2077,14 @@ let QUERYPARAM = 'query',
2060
2077
keyName ,
2061
2078
paramValue = resolveValueOfParameter ( context , param ) ;
2062
2079
2063
- if ( param && param . schema ) {
2064
- const { name, schema } = param ;
2065
- keyName = name ;
2066
- properties = createProperties ( schema , param ) ;
2080
+ if ( param && param . name && param . schema && param . schema . type ) {
2081
+ keyName = param . name ;
2082
+ properties = createProperties ( param ) ;
2067
2083
}
2084
+
2068
2085
queryParamTypeInfo = { keyName, properties } ;
2069
- if ( keyName && param . schema && param . schema . type ) {
2070
- queryParamTypes . push ( queryParamTypeInfo ) ;
2071
- }
2086
+
2087
+ queryParamTypes . push ( queryParamTypeInfo ) ;
2072
2088
2073
2089
if ( typeof paramValue === 'number' || typeof paramValue === 'boolean' ) {
2074
2090
// the SDK will keep the number-ness,
@@ -2114,16 +2130,13 @@ let QUERYPARAM = 'query',
2114
2130
keyName ,
2115
2131
paramValue = resolveValueOfParameter ( context , param ) ;
2116
2132
2117
- if ( param && param . schema ) {
2118
- const { name, schema } = param ;
2119
- keyName = name ;
2120
- properties = createProperties ( schema , param ) ;
2133
+ if ( param && param . name && param . schema && param . schema . type ) {
2134
+ keyName = param . name ;
2135
+ properties = createProperties ( param ) ;
2121
2136
}
2122
2137
2123
2138
pathParamTypeInfo = { keyName, properties } ;
2124
- if ( keyName && param . schema && param . schema . type ) {
2125
- pathParamTypes . push ( pathParamTypeInfo ) ;
2126
- }
2139
+ pathParamTypes . push ( pathParamTypeInfo ) ;
2127
2140
2128
2141
if ( typeof paramValue === 'number' || typeof paramValue === 'boolean' ) {
2129
2142
// the SDK will keep the number-ness,
@@ -2202,10 +2215,10 @@ let QUERYPARAM = 'query',
2202
2215
paramValue = resolveValueOfParameter ( context , param ) ;
2203
2216
2204
2217
if ( param && param . name && param . schema && param . schema . type ) {
2205
- const { name, schema } = param ;
2206
- keyName = name ;
2207
- properties = createProperties ( schema , param ) ;
2218
+ keyName = param . name ;
2219
+ properties = createProperties ( param ) ;
2208
2220
}
2221
+
2209
2222
headerTypeInfo = { keyName, properties } ;
2210
2223
2211
2224
headerTypes . push ( headerTypeInfo ) ;
@@ -2354,17 +2367,17 @@ let QUERYPARAM = 'query',
2354
2367
keyName = name ;
2355
2368
properties = {
2356
2369
type : schema . type ,
2357
- format : schema . format || undefined ,
2358
- default : schema . default !== undefined ? schema . default : undefined ,
2370
+ format : schema . format ,
2371
+ default : schema . default ,
2359
2372
required : schema . required || false ,
2360
2373
deprecated : schema . deprecated || false ,
2361
2374
enum : schema . enum || undefined ,
2362
- minLength : schema . minLength !== undefined ? schema . minLength : undefined ,
2363
- maxLength : schema . maxLength !== undefined ? schema . maxLength : undefined ,
2364
- minimum : schema . minimum !== undefined ? schema . minimum : undefined ,
2365
- maximum : schema . maximum !== undefined ? schema . maximum : undefined ,
2366
- pattern : schema . pattern || undefined ,
2367
- example : schema . example !== undefined ? schema . example : undefined
2375
+ minLength : schema . minLength ,
2376
+ maxLength : schema . maxLength ,
2377
+ minimum : schema . minimum ,
2378
+ maximum : schema . maximum ,
2379
+ pattern : schema . pattern ,
2380
+ example : schema . example
2368
2381
} ;
2369
2382
2370
2383
}
@@ -2516,7 +2529,6 @@ let QUERYPARAM = 'query',
2516
2529
{ resolvedHeaderTypes, headers } = resolveResponseHeaders ( context , responseSchema . headers ) ,
2517
2530
responseBodyHeaderObj ;
2518
2531
resolvedExamplesObject = resolvedExamples [ 0 ] && resolvedExamples [ 0 ] . resolvedResponseBodyTypes ;
2519
- // eslint-disable-next-line one-var
2520
2532
responseBodyHeaderObj =
2521
2533
{
2522
2534
body : JSON . stringify ( resolvedExamplesObject , null , 2 ) ,
0 commit comments