# schemy-child-settings

> Allow using settings in child schemas without creating a Schemy instance separately

Latest version **1.0.0** (published 2021-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install schemy-child-settings
pnpm add schemy-child-settings
yarn add schemy-child-settings
bun add schemy-child-settings
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-08-18 |
| First published | 2021-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alan Berdinelli |
| Maintainers | aeberdinelli |
| Keywords | schemy, json, validation, schema, node, plugin |

## Links

- npm: https://www.npmjs.com/package/schemy-child-settings
- npm.io page: https://npm.io/package/schemy-child-settings

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-08-18

## README

# Child Settings Plugin
This plugin for Schemy will allow you to add settings to child schemas. Currently, the only way to do that is creating a Schemy instance separately before using it as a property type in the parent schema. <br />
This might be hard to understand so let's go directly into an example:

```javascript
const Schemy = require('schemy');
const ChildSettingsPlugin = require('schemy-child-settings');

// Load the plugin into Schemy
Schemy.extend(ChildSettingsPlugin);

// Now you can do something like this
const schema = new Schemy({
    name: {
        schema: {
            firstname: String,
            lastname: String
        },
        settings: {
            strict: true
        }
    }
}, { strict: false });

schema.validate({
	name: {
		firstname: 'Firstname',
		lastname: 'Lastname',
		middlename: 'Middlename'
	},
	age: 21
}); // => false

schema.getValidationErrors(); // => [ 'Property name.middlename not valid in schema' ]
```

What happens in the example above, is that we define the parent schema as not strict. That way we can add the `age` property even if is not defined. However, we set the `name` schema as `{ strict: true }` so when we try to add the `middlename` property we get the error that is not valid.
<br />
*Note*: Requires Schemy version >= 3.1.0

---
_Source: https://npm.io/package/schemy-child-settings · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
