@@ -559,21 +559,26 @@ object RestActionBuilderV3 {
559559 example : Any? ,
560560 examples : Map <String , Example >? ,
561561 messages : MutableList <String >
562- ) : List <Any >{
562+ ) : List <Pair <Any ,String ?>>{
563+
564+ /* *
565+ * List of pairs value/name.
566+ * the name if optional, as only defined for "examples"
567+ */
568+ val data = mutableListOf<Pair <Any , String ?>>()
563569
564- val data = mutableListOf<Any >()
565570 if (example != null ){
566- data.add(example)
571+ data.add(Pair ( example, null ) )
567572 }
568573 if (! examples.isNullOrEmpty()){
569- examples.values .forEach {
570- val exm = if (it.`$ref` != null ){
571- SchemaUtils .getReferenceExample(schemaHolder, currentSchema, it.`$ref`, messages)
574+ examples.entries .forEach {
575+ val exm = if (it.value. `$ref` != null ){
576+ SchemaUtils .getReferenceExample(schemaHolder, currentSchema, it.value. `$ref`, messages)
572577 } else {
573- it
578+ it.value
574579 }
575580 if (exm != null ) {
576- data.add(exm.value)
581+ data.add(Pair ( exm.value, it.key) )
577582 }
578583 }
579584 }
@@ -780,7 +785,7 @@ object RestActionBuilderV3 {
780785 referenceClassDef : String? ,
781786 options : Options ,
782787 isInPath : Boolean = false,
783- examples : List <Any > = listOf(),
788+ examples : List <Pair < Any , String ?> > = listOf(),
784789 messages : MutableList <String >
785790 ): Gene {
786791
@@ -974,7 +979,7 @@ object RestActionBuilderV3 {
974979 history : Deque <String >,
975980 referenceTypeName : String? ,
976981 options : Options ,
977- examples : List <Any >,
982+ examples : List <Pair < Any , String ?> >,
978983 messages : MutableList <String >
979984 ): Gene {
980985
@@ -1131,7 +1136,7 @@ object RestActionBuilderV3 {
11311136 history : Deque <String >,
11321137 referenceTypeName : String? ,
11331138 options : Options ,
1134- examples : List <Any >,
1139+ examples : List <Pair < Any , String ?> >,
11351140 messages : MutableList <String >
11361141 ) : Gene {
11371142 /*
@@ -1237,7 +1242,7 @@ object RestActionBuilderV3 {
12371242 fields : List <Gene >,
12381243 additionalFieldTemplate : PairGene <StringGene , Gene >? ,
12391244 referenceTypeName : String? ,
1240- otherExampleValues : List <Any >,
1245+ otherExampleValues : List <Pair < Any , String ?> >,
12411246 messages : MutableList <String >
12421247 ) : Gene {
12431248 if (fields.isEmpty()) {
@@ -1269,19 +1274,29 @@ object RestActionBuilderV3 {
12691274 val exampleValue = if (options.probUseExamples > 0 ) schema.example else null
12701275 val multiExampleValues = if (options.probUseExamples > 0 ) schema.examples else null
12711276
1272- val examples = mutableListOf<ObjectGene >()
1277+ val examples = mutableListOf<Pair < ObjectGene , String ?> >()
12731278 if (exampleValue != null ){
12741279 duplicateObjectWithExampleFields(name,mainGene, exampleValue)?.let {
1275- examples.add(it )
1280+ examples.add(Pair (it, null ) )
12761281 }
12771282 }
12781283 if (multiExampleValues != null ){
1279- examples.addAll(multiExampleValues.mapNotNull { duplicateObjectWithExampleFields(name,mainGene, it) })
1284+ examples.addAll(multiExampleValues
1285+ .mapNotNull { duplicateObjectWithExampleFields(name,mainGene, it) }
1286+ .map { Pair (it, null ) }
1287+ )
12801288 }
1281- examples.addAll(otherExampleValues.mapNotNull { duplicateObjectWithExampleFields(name,mainGene, it) })
1289+ examples.addAll(otherExampleValues
1290+ .mapNotNull { duplicateObjectWithExampleFields(name,mainGene, it.first)
1291+ ?.let { obj -> Pair (obj,it.second) }
1292+ }
1293+ )
1294+
1295+ val v = examples.map { it.first } // values
1296+ val n = examples.map{it.second} // names
12821297
12831298 val exampleGene = if (examples.isNotEmpty()){
1284- ChoiceGene (EXAMPLES_NAME , examples )
1299+ ChoiceGene (EXAMPLES_NAME , v, valueNames = n )
12851300 } else null
12861301 val defaultGene = if (defaultValue != null ){
12871302 duplicateObjectWithExampleFields(" default" , mainGene, defaultValue)
@@ -1372,7 +1387,7 @@ object RestActionBuilderV3 {
13721387 options : Options ,
13731388 collectionTemplate : Gene ? ,
13741389 isInPath : Boolean ,
1375- examples : List <Any >,
1390+ examples : List <Pair < Any , String ?> >,
13761391 messages : MutableList <String >
13771392 ) : Gene {
13781393
@@ -1412,7 +1427,7 @@ object RestActionBuilderV3 {
14121427 collectionTemplate : Gene ? = null,
14131428 // might need to add extra constraints if in path
14141429 isInPath : Boolean ,
1415- exampleObjects : List <Any >,
1430+ exampleObjects : List <Pair < Any , String ?> >,
14161431 format : String? = null,
14171432 messages : MutableList <String >
14181433 ) : Gene {
@@ -1544,10 +1559,12 @@ object RestActionBuilderV3 {
15441559 val exampleValue = if (options.probUseExamples > 0 ) schema.example else null
15451560 val multiExampleValues = if (options.probUseExamples > 0 ) schema.examples else null
15461561
1547- val examples = mutableListOf<String >()
1562+ // value and optional name
1563+ val examples = mutableListOf<Pair <String ,String ?>>()
1564+
15481565 if (exampleValue != null ) {
15491566 val raw = asRawString(exampleValue)
1550- examples.add(raw)
1567+ examples.add(Pair ( raw, null ) )
15511568 val arrayM = if (raw.startsWith(" [" )) " If you are wrongly passing to it an array of values, " +
15521569 " the parser would read it as an array string or simply ignore it. "
15531570 else " "
@@ -1558,9 +1575,9 @@ object RestActionBuilderV3 {
15581575 }
15591576 if (multiExampleValues != null && multiExampleValues.isNotEmpty()){
15601577 // possibly bug in parser, but it was reading strings values double-quoted in this case
1561- examples.addAll(multiExampleValues.map { asRawString(it) })
1578+ examples.addAll(multiExampleValues.map { Pair ( asRawString(it), null ) })
15621579 }
1563- examples.addAll( exampleObjects.map { asRawString(it) })
1580+ examples.addAll( exampleObjects.map { Pair ( asRawString(it.first), it.second ) })
15641581
15651582
15661583 val defaultGene = if (defaultValue != null ){
@@ -1581,15 +1598,20 @@ object RestActionBuilderV3 {
15811598 }
15821599 } else null
15831600
1601+ // values
1602+ val v = examples.map { it.first }
1603+ // optional names
1604+ val n = examples.map { it.second }
1605+
15841606 val exampleGene = if (examples.isNotEmpty()){
15851607 when {
15861608 NumberGene ::class .java.isAssignableFrom(geneClass)
1587- -> EnumGene (EXAMPLES_NAME , examples ,0 ,true )
1609+ -> EnumGene (EXAMPLES_NAME , v ,0 ,true , n )
15881610
15891611 geneClass == StringGene ::class .java
15901612 || geneClass == Base64StringGene ::class .java
15911613 || geneClass == RegexGene ::class .java
1592- -> EnumGene <String >(EXAMPLES_NAME , examples ,0 ,false )
1614+ -> EnumGene <String >(EXAMPLES_NAME , v ,0 ,false , n )
15931615
15941616 // TODO Arrays
15951617 else -> {
@@ -1692,7 +1714,7 @@ object RestActionBuilderV3 {
16921714 currentSchema : SchemaOpenAPI ,
16931715 history : Deque <String > = ArrayDeque (),
16941716 options : Options ,
1695- examples : List <Any >,
1717+ examples : List <Pair < Any , String ?> >,
16961718 messages : MutableList <String >
16971719 ): Gene {
16981720
0 commit comments