schemapi
v1.4.4
Published
The `create` command allows you to create a new schema file. The generated file will be a JSON file containing the essential properties to define a schema.
Readme
Schemapi
Command create
The create command allows you to create a new schema file. The generated file will be a JSON file containing the essential properties to define a schema.
npx schemapi create <schema>Parameters
<schema>: The name of the schema to be created. The generated file will have the format<schema>.schema.jsonand will be saved in the.schemafolder.
Usage Example
To create a new schema called user, run:
npx schemapi create userEnter the name of your schema: Users
Enter the description of your schema: Model schema of user informations
Enter the length of your schema (can be negative): -30
Enter the seed for your schema: 900A number indicating the length of the data. If the value is negative, the size of the generated data will vary between 1 and the absolute value of length. If positive, the data will have a fixed size defined by the length value.
Once these values are entered, the schema will be created as a JSON file in the .schema directory.
Command delete
The delete command allows you to delete an entire schema that has already been created. This command removes the corresponding schema file from the .schema folder.
npx schemapi delete <schema>Parameters
<schema>: The name of the schema to be deleted. The corresponding schema file must be located in the.schemafolder and have the format<schema>.schema.json.
Usage Example
To delete a schema called user, run:
npx schemapi delete userAre you sure you want to delete the schema <schema>? (y/N)Type
y(yes) to confirm and delete the schema. TypeN(no) or press Enter to cancel the operation and keep the schema.
Command add
The add command allows you to add new properties (content keys) to an existing schema. This command helps you define the types of data that will be generated as well as how the data is constructed.
npx schemapi add <schema>Enter the key for the new content: key
Select the type of content to add:
address
email
name
number
options
pattern
schema
username
uuidDepending on the content type chosen, you may be asked for additional configuration options.
Example Usage
To add a new email field to an existing schema called user, run:
npx schemapi add userThe prompts will guide you through entering the key and selecting the type, along with any additional options based on the type selected.
Command remove
The remove command allows you to remove one or more content keys from an existing schema. It will list all available content keys in the schema, and you can select one or more to delete. If no content keys are selected, nothing will be removed.
npx schemapi remove <schema>Parameters
<schema>: The name of the schema from which content keys will be removed. The corresponding schema file must be located in the.schemafolder and have the format<schema>.schema.json.
Usage Example
To remove content keys from a schema called user, run:
npx schemapi remove userSelect the keys to remove from content (use space to select multiple or enter to cancel): <key1>, <key2>
Are you sure you want to delete the selected keys: <key1>, <key2>? (y/N)Type
y(yes) to confirm and delete the props of schema. TypeN(no) to cancel the operation and keep the props of schema.
Here’s how you can structure the documentation for the server command:
Command server
The server command starts an Express server that serves the schema data stored in the .schema directory. This server will monitor the .schema folder and automatically reload the schemas whenever they are updated, enabling dynamic development. It also provides an HTML interface to view the schemas and their contents.
npx schemapi server -p <port>Options
-p, --port <port>:
Specify the port on which the server will run. If not provided, the server will default to port1104.
Example Usage
Start the server with the default port (
1104):npx schemapi serverStart the server on a custom port (
3000):npx schemapi server -p 3000
Description of Features
Request Logging: Each request to the server will be logged in the console, including details such as HTTP method, status code, and response time.
Dynamic Routes for Schemas:
Every.schema.jsonfile in the.schemadirectory generates a corresponding route. You can access these routes athttp://localhost:<port>/<schemaName>.
For example, if you have auser.schema.jsonfile, it will be accessible athttp://localhost:1104/user.Automatic Schema Reloading:
The server detects any changes made to the.schemafiles and automatically reloads them. When a change is detected, a notification is shown in the console.HTML Interface:
The root route (/) displays a rendered HTML page (using Handlebars) listing all available schemas and their contents. This makes it easy to visualize the data being served.
Example Output
When you run the server, you’ll see logs like:
Server started on port http://localhost:1104When accessing a specific schema (e.g., user), you will see:
http://localhost:1104/user