Skip to content

Commit c5af711

Browse files
committed
fix description preset for anytypes
1 parent b38dd6c commit c5af711

File tree

14 files changed

+98
-7
lines changed

14 files changed

+98
-7
lines changed

src/helpers/CommonModelToMetaModel.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,19 @@ export function convertToAnyModel(
359359
if (!Array.isArray(jsonSchemaModel.type) || !isAnyType) {
360360
return undefined;
361361
}
362+
let originalInput = jsonSchemaModel.originalInput;
363+
if (typeof jsonSchemaModel.originalInput !== 'object') {
364+
originalInput = {
365+
value: jsonSchemaModel.originalInput,
366+
...(jsonSchemaModel.originalInput?.description !== undefined && {
367+
description: jsonSchemaModel.originalInput.description
368+
})
369+
};
370+
}
371+
362372
return new AnyModel(
363373
name,
364-
jsonSchemaModel.originalInput,
374+
originalInput,
365375
getMetaModelOptions(jsonSchemaModel, options)
366376
);
367377
}
@@ -519,9 +529,17 @@ export function convertToDictionaryModel(
519529
getOriginalInputFromAdditionalAndPatterns(jsonSchemaModel);
520530
const keyModel = new StringModel(name, originalInput, {});
521531
const valueModel = convertAdditionalAndPatterns(context);
532+
533+
const input = {
534+
originalInput,
535+
...(jsonSchemaModel.originalInput?.description !== undefined && {
536+
description: jsonSchemaModel.originalInput.description
537+
})
538+
};
539+
522540
return new DictionaryModel(
523541
name,
524-
originalInput,
542+
input,
525543
getMetaModelOptions(jsonSchemaModel, options),
526544
keyModel,
527545
valueModel,
@@ -610,6 +628,7 @@ export function convertToObjectModel(
610628
);
611629
metaModel.properties[String(propertyName)] = propertyModel;
612630
}
631+
// console.log(metaModel);
613632
return metaModel;
614633
}
615634

test/generators/go/presets/DescriptionPreset.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ const doc = {
1717
additionalProperties: false,
1818
$id: 'NestedTest',
1919
properties: { stringProp: { type: 'string', description: 'string prop' } }
20+
},
21+
anyProp: {
22+
type: 'object',
23+
$id: 'AnyTest',
24+
properties: {},
25+
description: 'AnyTest description'
2026
}
2127
}
2228
};

test/generators/go/presets/__snapshots__/DescriptionPreset.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type Test struct {
77
// Description
88
NumberProp float64
99
ObjectProp *NestedTest
10+
// AnyTest description
11+
AnyProp map[string]interface{}
1012
}"
1113
`;
1214

test/generators/java/presets/DescriptionPreset.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('JAVA_DESCRIPTION_PRESET', () => {
2020
type: 'string',
2121
description: 'Description for prop',
2222
examples: ['exampleValue']
23+
},
24+
anyProp: {
25+
type: 'object',
26+
$id: 'AnyTest',
27+
properties: {},
28+
description: 'AnyTest description'
2329
}
2430
}
2531
};

test/generators/java/presets/__snapshots__/DescriptionPreset.spec.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ exports[`JAVA_DESCRIPTION_PRESET should render description and examples for clas
6666
*/
6767
public class Clazz {
6868
private String prop;
69+
private Map<String, Object> anyProp;
6970
private Map<String, Object> additionalProperties;
7071
7172
/**
@@ -75,6 +76,12 @@ public class Clazz {
7576
public String getProp() { return this.prop; }
7677
public void setProp(String prop) { this.prop = prop; }
7778
79+
/**
80+
* AnyTest description
81+
*/
82+
public Map<String, Object> getAnyProp() { return this.anyProp; }
83+
public void setAnyProp(Map<String, Object> anyProp) { this.anyProp = anyProp; }
84+
7885
public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; }
7986
public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; }
8087
}"

test/generators/kotlin/presets/DescriptionPreset.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('KOTLIN_DESCRIPTION_PRESET', () => {
2020
type: 'string',
2121
description: 'Description for prop',
2222
examples: ['exampleValue']
23+
},
24+
anyProp: {
25+
type: 'object',
26+
$id: 'AnyTest',
27+
properties: {},
28+
description: 'AnyTest description'
2329
}
2430
}
2531
};

test/generators/kotlin/presets/__snapshots__/DescriptionPreset.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ exports[`KOTLIN_DESCRIPTION_PRESET should render description and examples for cl
55
* Description for class
66
*
77
* @property prop Description for prop
8+
* @property anyProp AnyTest description
89
* @property additionalProperties
910
*
1011
* Examples:
1112
* {\\"prop\\":\\"value\\"}
1213
*/
1314
data class Clazz(
1415
val prop: String? = null,
16+
val anyProp: Map<String, Any>? = null,
1517
val additionalProperties: Map<String, Any>? = null,
1618
)"
1719
`;

test/generators/php/presets/DescriptionPreset.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ describe('PHP_DESCRIPTION_PRESET', () => {
2222
type: 'string',
2323
description: 'Description for prop',
2424
examples: ['exampleValue']
25+
},
26+
anyProp: {
27+
type: 'object',
28+
$id: 'AnyTest',
29+
properties: {},
30+
description: 'AnyTest description'
2531
}
2632
}
2733
};

test/generators/php/presets/__snapshots__/DescriptionPreset.spec.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ exports[`PHP_DESCRIPTION_PRESET should render description and examples for class
77
final class Clazz
88
{
99
private ?string $prop;
10+
private mixed $anyProp;
1011
private mixed $additionalProperties;
1112
1213
public function getProp(): ?string { return $this->prop; }
1314
public function setProp(?string $prop): void { $this->prop = $prop; }
1415
16+
public function getAnyProp(): mixed { return $this->anyProp; }
17+
public function setAnyProp(mixed $anyProp): void { $this->anyProp = $anyProp; }
18+
1519
public function getAdditionalProperties(): mixed { return $this->additionalProperties; }
1620
public function setAdditionalProperties(mixed $additionalProperties): void { $this->additionalProperties = $additionalProperties; }
1721
}

test/generators/scala/presets/DescriptionPreset.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('SCALA_DESCRIPTION_PRESET', () => {
2020
type: 'string',
2121
description: 'Description for prop',
2222
examples: ['exampleValue']
23+
},
24+
anyProp: {
25+
type: 'object',
26+
$id: 'AnyTest',
27+
properties: {},
28+
description: 'AnyTest description'
2329
}
2430
}
2531
};

0 commit comments

Comments
 (0)