From 68e169748db231a6cfda9c6cd6ed4fd2c8a993e0 Mon Sep 17 00:00:00 2001 From: vojtechpavlu Date: Sun, 24 Mar 2024 20:28:12 +0100 Subject: [PATCH] Add documentation --- .../Generators/06_objects.md | 140 +++++++++++++++++- 1 file changed, 136 insertions(+), 4 deletions(-) diff --git a/docs/docs/System-Documentation/Generators/06_objects.md b/docs/docs/System-Documentation/Generators/06_objects.md index 3c8647c..3cdcf85 100644 --- a/docs/docs/System-Documentation/Generators/06_objects.md +++ b/docs/docs/System-Documentation/Generators/06_objects.md @@ -26,10 +26,6 @@ schema object will be used to generate nested falsum. } } } - - const config: ObjectFromSchemaConfig = { - schema: fieldSchema - } const generator = new ObjectFromSchemaGenerator(config); @@ -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' } + ] + } + ```