mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-02-23 17:49:49 +08:00
fix: generate array items defaults only when generating state examples
This commit is contained in:
parent
8e59b852ec
commit
5c2e03d8f7
@ -323,7 +323,7 @@ export class ComponentModel implements IComponentModel {
|
||||
private genStateExample() {
|
||||
if (!this.spec) return [];
|
||||
const componentStateSpec = this.spec.spec.state;
|
||||
let _temp = generateDefaultValueFromSpec(componentStateSpec, true) as Record<
|
||||
let _temp = generateDefaultValueFromSpec(componentStateSpec, true, true) as Record<
|
||||
string,
|
||||
any
|
||||
>;
|
||||
@ -336,7 +336,7 @@ export class ComponentModel implements IComponentModel {
|
||||
_temp[key] = AnyTypePlaceholder;
|
||||
}
|
||||
} else {
|
||||
_temp = merge(_temp, generateDefaultValueFromSpec(t.spec.spec.state, true));
|
||||
_temp = merge(_temp, generateDefaultValueFromSpec(t.spec.spec.state, true, true));
|
||||
}
|
||||
});
|
||||
this.stateExample = _temp;
|
||||
|
@ -72,7 +72,8 @@ function getObject(
|
||||
|
||||
export function generateDefaultValueFromSpec(
|
||||
spec: JSONSchema7,
|
||||
returnPlaceholderForAny = false
|
||||
returnPlaceholderForAny = false,
|
||||
genArrayItemDefaults = false
|
||||
): JSONSchema7Type {
|
||||
if (!spec.type) {
|
||||
if ((spec.anyOf && spec.anyOf!.length > 0) || (spec.oneOf && spec.oneOf.length > 0)) {
|
||||
@ -112,7 +113,9 @@ export function generateDefaultValueFromSpec(
|
||||
? Array.isArray(spec.items)
|
||||
? getArray(spec.items, returnPlaceholderForAny)
|
||||
: isJSONSchema(spec.items)
|
||||
? [generateDefaultValueFromSpec(spec.items, returnPlaceholderForAny)]
|
||||
? genArrayItemDefaults
|
||||
? [generateDefaultValueFromSpec(spec.items, returnPlaceholderForAny)]
|
||||
: []
|
||||
: null
|
||||
: [];
|
||||
case spec.type === 'number':
|
||||
|
Loading…
Reference in New Issue
Block a user