@@ -1326,6 +1326,31 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
13261326 return this . _typeToValue ( value , dt [ '@id' ] ) ;
13271327 }
13281328
1329+ /**
1330+ * Computes default enum value for given range.
1331+ *
1332+ * @param {Object } range AMF's range definition for a shape.
1333+ * @return {string|number|boolean|null } Value cast to the corresponding type
1334+ */
1335+ _computeDefaultEnumRangeValue ( range ) {
1336+ let enumOptions = range [ this . _getAmfKey ( this . ns . w3 . shacl . in ) ]
1337+ if ( Array . isArray ( enumOptions ) ) {
1338+ [ enumOptions ] = enumOptions ;
1339+ }
1340+ const rdfKey = this . _getAmfKey ( this . ns . w3 . rdfSchema . key ) ;
1341+ const firstOptionKey = Object . keys ( enumOptions ) . find ( ( key ) => key . indexOf ( rdfKey ) !== - 1 ) ;
1342+ let firstOption = enumOptions [ firstOptionKey ] ;
1343+ if ( Array . isArray ( firstOption ) ) {
1344+ [ firstOption ] = firstOption ;
1345+ }
1346+ const vKey = this . _getAmfKey ( this . ns . raml . vocabularies . data . value ) ;
1347+ const value = this . _getValue ( firstOption , vKey ) ;
1348+ if ( value ) {
1349+ return value ;
1350+ }
1351+ return null ;
1352+ }
1353+
13291354 /**
13301355 * Computes default value for given range.
13311356 *
@@ -1338,6 +1363,14 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
13381363 * @return {string|number|boolean|null } Value casted to the corresponding type
13391364 */
13401365 _computeDefaultRangeValue ( range ) {
1366+ const isEnum = this . _hasProperty ( range , this . ns . w3 . shacl . in )
1367+ if ( isEnum ) {
1368+ const value = this . _computeDefaultEnumRangeValue ( range ) ;
1369+ if ( value ) {
1370+ return value ;
1371+ }
1372+ }
1373+
13411374 const type = this . _computeScalarType ( range ) ;
13421375 switch ( type ) {
13431376 case 'Number' :
0 commit comments