Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechpavlu committed Mar 24, 2024
1 parent 23e2c2d commit 68e1697
Showing 1 changed file with 136 additions and 4 deletions.
140 changes: 136 additions & 4 deletions docs/docs/System-Documentation/Generators/06_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ schema object will be used to generate nested falsum.
}
}
}

const config: ObjectFromSchemaConfig = {
schema: fieldSchema
}

const generator = new ObjectFromSchemaGenerator(config);

Expand Down Expand Up @@ -108,3 +104,139 @@ schema object will be used to generate nested falsum.
```
{ nested: { value: 'd' } }
```


## List of Objects from Schema

Builds up a list of an objects by given schema.

The configuration object is required to have `schema` field containing
a [Schema Input](../Building-Blocks/02_schema-input.md) object. This configured
schema object will be used to generate nested falsum.

It also expects field `n` describing how many items should it generate.


### Examples

=== "Instance access"

``` typescript linenums="1"
const config: ListOfObjectsFromSchemaConfig = {
n: 3,
schema: {
fields: {
testField1: {
type: "constant-string",
config: {
text: "testValue"
}
},
testField2: {
type: "constant-string",
config: {
text: "testValue"
}
}
}
}
}

const generator = new ListOfObjectsFromSchemaGenerator(config);

console.log(generator.generate());
```

!!! abstract "Output"

```
[
{ testField1: 'testValue', testField2: 'testValue' },
{ testField1: 'testValue', testField2: 'testValue' },
{ testField1: 'testValue', testField2: 'testValue' }
]
```


=== "Declarative access"

``` typescript linenums="1"
const config: ListOfObjectsFromSchemaConfig = {
n: 3,
schema: {
fields: {
testField1: {
type: "constant-string",
config: {
text: "testValue"
}
},
testField2: {
type: "constant-string",
config: {
text: "testValue"
}
}
}
}
}

const generator = getValueGenerator('list-of-schema', config);

const value = generator.generate();
```

!!! abstract "Output"

```
[
{ testField1: 'testValue', testField2: 'testValue' },
{ testField1: 'testValue', testField2: 'testValue' },
{ testField1: 'testValue', testField2: 'testValue' }
]
```

=== "Schema access"

``` javascript linenums="1"
const fieldSchema: SchemaInput = {
fields: {
value: {
type: 'array-picker',
config: {
array: ['a', 'b', 'c', 'd']
}
}
}
}

const schema: SchemaInput = {
fields: {
nested: {
type: 'list-of-schema',
config: {
n: 5,
schema: fieldSchema
}
}
}
}
const fabricator = new Fabricator(schema);
console.log(fabricator.generate());
```

!!! abstract "Output"

```
{
nested: [
{ value: 'a' },
{ value: 'c' },
{ value: 'c' },
{ value: 'b' },
{ value: 'a' }
]
}
```

0 comments on commit 68e1697

Please sign in to comment.