@fnet/object-from-schema
v0.1.3
Published
The **@fnet/object-from-schema** project is a functional utility designed to generate a JSON object based on the parameters defined in a provided JSON schema. The utility, interestingly, supports custom attributes as well, like `subtype`, which can be use
Downloads
10
Readme
@fnet/object-from-schema
The @fnet/object-from-schema project is a functional utility designed to generate a JSON object based on the parameters defined in a provided JSON schema. The utility, interestingly, supports custom attributes as well, like subtype
, which can be used for enhanced input types.
Functionality
The main function of the project takes a JSON schema as an argument and then prompts the user to input the values based on the schema. The schema can either be a direct object or a URL/local file path, which is then loaded parsed accordingly. The user prompt supports enhanced input types where users can input their responses. If the schema includes required fields, these are highlighted for the user. It also has provisions for setting default values and indicates optional fields where input is not mandatory.
Apart from the main functionality, @fnet/object-from-schema includes a few other extensions.
Object Inputs
If the value type in the JSON schema is recognized as an object, it is sent back to run through the collectInputsForSchema function again. This allows for the generation of nested objects.
SubTypes
A specific attribute subtype
is checked when reading each property of the object. If this is set to 'password', the input type in the prompt for that field will become a password field, which conceals characters input by the user for that particular property.
Process OneOf
An intermediary function processes oneOf
instances in the schema. If a schema option from oneOf
is selected, it's treated as the new schema, and its required fields and other properties are added to the generated object.
Load Schema
This function is used to check whether the schema provided is a direct object, URL, or a local file path. If it is an object, it gets returned outright. If it is a URL or file path, the content from the source is loaded, parsed into a schema, and then returned. However, if the type of source is neither an object nor a string (URL/file-path), an error is thrown.
In summary, @fnet/object-from-schema is a comprehensive JSON object generator utility that is capable of accepting a variety of schemas, supports custom attributes for enhanced input types, and actively prompts user input. This project simplifies the process of generating JSON objects based on pre-defined schemas, saving time and ensuring precision.