5.12.93 • Published 11 months ago

@kollorg/voluptas-ducimus v5.12.93

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@kollorg/voluptas-ducimus

merge-json-schemas is a javascript library that build a logical product (AND) for multiple JSON schemas.

Installation

npm install @kollorg/voluptas-ducimus

Usage

const assert = require('node:assert')
const { mergeSchemas } = require('@kollorg/voluptas-ducimus');

const schema1 = {
  $id: 'schema1',
  type: 'object',
  properties: {
    foo: { type: 'string', enum: ['foo1', 'foo2'] },
    bar: { type: 'string', minLength: 3 }
  }
}

const schema2 = {
  $id: 'schema1',
  type: 'object',
  properties: {
    foo: { type: 'string', enum: ['foo1', 'foo3'] },
    bar: { type: 'string', minLength: 5 }
  },
  required: ['foo']
}

const mergedSchema = mergeSchemas([schema1, schema2])
assert.deepStrictEqual(mergedSchema, {
  $id: 'schema1',
  type: 'object',
  properties: {
    foo: { type: 'string', enum: ['foo1'] },
    bar: { type: 'string', minLength: 5 }
  },
  required: ['foo']
})

API

mergeSchemas(schemas, options)

Builds a logical conjunction (AND) of multiple JSON schemas.

  • schemas \<objects[]> - list of JSON schemas to merge.
  • options \<object> - optional options.
    • resolvers \<object> - custom resolvers for JSON schema keywords. Each key is the name of a JSON schema keyword. Each value is a resolver function. See keywordResolver.
    • defaultResolver \<function> - custom default resolver for JSON schema keywords. See keywordResolver.
    • onConflict \<string> - action to take when a conflict is found. Used by the default defaultResolver. Default is throw. Possible values are:
      • throw - throws an error if found a multiple different schemas for the same keyword.
      • ignore - do nothing if found a multiple different schemas for the same keyword.
      • first - use the value of the first schema if found a multiple different schemas for the same keyword.

resolvers

A list of default resolvers that merge-json-schema uses to merge JSON schemas. You can override the default resolvers by passing a list of custom resolvers in the options argument of mergeSchemas. See keywordResolver.

defaultResolver

A default resolver that merge-json-schema uses to merge JSON schemas. Default resolver is used when no custom resolver is defined for a JSON schema keyword. By default, the default resolver works as follows:

  • If only one schema contains the keyword, the value of the keyword is used as the merged value.
  • If multiple schemas contain the exact same value for the keyword, the value of the keyword is used as the merged value.
  • If multiple schemas contain different values for the keyword, it throws an error.

keywordResolver (keyword, values, mergedSchema, parentSchemas, options)

merge-json-schema uses a set of resolvers to merge JSON schemas. Each resolver is associated with a JSON schema keyword. The resolver is called when the keyword is found in the schemas to merge. The resolver is called with the following arguments:

  • keyword \<string> - the name of the keyword to merge.
  • values \<any[]> - the values of the keyword to merge. The length of the array is equal to the number of schemas to merge. If a schema does not contain the keyword, the value is undefined.
  • mergedSchema \<object> - an instance of the merged schema.
  • parentSchemas \<object[]> - the list of parent schemas.
  • options \<object> - the options passed to mergeSchemas.

The resolver must set the merged value of the keyword in the mergedSchema object.

Example: resolver for the minNumber keyword.

function minNumberResolver (keyword, values, mergedSchema) {
  mergedSchema[keyword] = Math.min(...values)
}

License

MIT

consoleUnderscorejasminecolumnwafgesturesFunction.prototype.nameglobStreamsassertionformatflagsarraysfolderoutputjson-schemacircularreadloggingshelllockfileimportidentifiersRxJSsameValueZeroreducerflagtrimEndsqsmochagenericsquotequeueesspawnprocessimportexportwhatwgcore-jsavaobjectES2016ajaxomitvalidatorawesomesauceexectyped arraylistenerscjkchinesesyntaxglobalsselffrompuredynamodbcolorscloudsearchisTypeScriptArrayBuffer#slicefullwidthes5schemenopehttpes-shimssubprocesseslint-pluginbyteOffsetkeytrimRightstringsettertermutilsasciibrowserslistexpressionECMAScript 2018regular expressionsclonematchAllArray.prototype.flatES2022sharedarraybufferglobal this valuechildPushcontainsistanbulstableform-validationdependenciesESnextArray.prototype.containswriteObject.assignwgethelpersconcatscheme-validationspringequal-0settingstslibvarsfulltoSorteddescriptionqueryfindshimtrimLefttraversebeanstalkECMAScript 3rulestypanionPromiseclassnamesnamegetPrototypeOf256figletstreamsideverypackage managertestingimmutableasyncUint32ArrayvestweakmapObservableweaksetpatchmkdirserrorinentriesmomentES6pushmulti-packagebytesuperagentownparserserializationsharedlengthproptypeassertsStyleSheetjsonschemabddTypedArraycopyansireverseddateECMAScript 2022Seteslintconfigagenteast-asian-widthstyleguidewindowrm.gitignorebind[[Prototype]]Streaminspectguidruntimei18nfast-deep-copyappESWebSockethardlinksposehashRFC-6455intrinsic$.extendcollection.es6BigInt64ArrayUint16Arraymake dirapollotypedstylesnativefull-widthjestreal-timebrowserBigUint64ArrayprefixqueueMicrotaskfast-clonedeep-copyArray.prototype.includesdescriptorRxutilargspropertieses2018snsgettransportSystem.globalurlecmascriptkeysReflect.getPrototypeOfrangeerrorglacierArrayBufferInt32Arrayutilitiescompareinternal slotspeedautoscalingFloat32ArrayacornhtmllinkObject.valuesjson-schema-validatorsinatrafinduptranspileeventsnamesrssjsES20203dviewES8global objectnpmclientec2airbnbbufferschemaeffect-tsES2017checkslotgetintrinsics3tsflatworkerhasobjstreamcolumnsiamperformantReactiveXinstrumentationrgbthreereadablecss-in-jsconstArrayfilearrayproxydefinePropertyformcoerciblevalidateajvdropformattingFloat64Array0lookjsxdifffpcloudtrailJSON-Schemaes2017progresszxclass-validatorcoverageECMAScript 7redacttypescriptloadingcurlpropertyinternalcryptoECMAScript 2016colourtypedarrayemojiArray.prototype.findLastIndexastnpmignoreisConcatSpreadablemanagernumberdataredux-toolkitsimpledbfilterframerSymbol.toStringTagrmdirstructuredCloneclikoreanvaliditeratoreslintpluginchannelpreprocessordebuggerglobalThisrdstc39matchuser-streamslast__proto__estreeECMAScript 5JSONsetECMAScript 2021postcss-pluginhigher-ordergroupfindLastresolvehelperequalityinstalllibphonenumberdeterministictranspilerconcatMaprestfulslicemovestringifyfile systemhas-ownasteriskscommandermanipulationlanguagecurriedSymboltypedarraysObject.entrieswalkoptimizeres6valueshasOwnPropertywalkingdeepqscollectionYAMLwaitroute53valuereact animationUint8ClampedArraytapeObject.getPrototypeOffses2016superstructharmonyoptimistponyfillfunction.lengthaccessibilitygroupByprivatereact-hooksexecuteapiredirectbufferselasticachetextgdprserializeryupwaapiaws.envprototypeECMAScript 2023deep-cloneArray.prototype.flattenboundcssformsemitphonetimedayjsregularjQueryjshinttoStringTagsessetPrototypeOfnegativeoffseteslintpnpm9censorgraphqlcloudformationcall-bindtapmergebinMicrosoftnodevar
5.12.93

11 months ago

5.12.91

11 months ago

5.12.92

11 months ago

5.12.90

11 months ago

5.12.89

11 months ago

5.12.88

11 months ago

5.12.87

11 months ago

4.12.87

11 months ago

4.12.86

12 months ago

4.12.85

12 months ago

4.12.84

12 months ago

4.12.83

12 months ago

4.12.82

12 months ago

4.12.81

12 months ago

4.12.80

12 months ago

4.12.79

12 months ago

4.12.78

12 months ago

4.12.77

12 months ago

4.12.76

12 months ago

4.12.75

12 months ago

3.12.75

12 months ago

3.11.75

12 months ago

3.11.74

12 months ago

3.11.73

12 months ago

3.11.72

12 months ago

3.11.71

12 months ago

3.11.70

12 months ago

3.11.69

12 months ago

3.11.68

1 year ago

3.11.67

1 year ago

3.11.66

1 year ago

3.11.65

1 year ago

3.11.64

1 year ago

3.11.63

1 year ago

3.11.62

1 year ago

3.11.61

1 year ago

3.10.61

1 year ago

3.10.60

1 year ago

3.10.59

1 year ago

3.10.58

1 year ago

3.10.57

1 year ago

3.10.56

1 year ago

3.10.55

1 year ago

3.9.55

1 year ago

3.9.54

1 year ago

3.9.53

1 year ago

3.9.52

1 year ago

3.9.51

1 year ago

3.9.50

1 year ago

3.9.49

1 year ago

3.9.48

1 year ago

3.9.47

1 year ago

3.9.46

1 year ago

3.9.45

1 year ago

3.9.44

1 year ago

2.9.44

1 year ago

2.9.43

1 year ago

2.8.43

1 year ago

2.8.42

1 year ago

2.8.41

1 year ago

2.8.40

1 year ago

2.8.39

1 year ago

2.8.38

1 year ago

2.7.38

1 year ago

2.7.37

1 year ago

2.7.36

1 year ago

2.7.35

1 year ago

2.7.34

1 year ago

2.7.33

1 year ago

2.7.32

1 year ago

2.7.31

1 year ago

2.7.30

1 year ago

2.7.29

1 year ago

2.7.28

1 year ago

2.6.28

1 year ago

2.6.27

1 year ago

2.6.26

1 year ago

2.5.26

1 year ago

2.5.25

1 year ago

2.5.24

1 year ago

2.5.23

1 year ago

2.5.22

1 year ago

2.5.21

1 year ago

2.5.20

1 year ago

2.4.20

1 year ago

2.4.19

1 year ago

2.3.19

1 year ago

2.3.18

1 year ago

2.3.17

1 year ago

2.3.16

1 year ago

2.3.15

1 year ago

2.3.14

1 year ago

2.3.13

1 year ago

2.3.12

1 year ago

2.3.11

1 year ago

2.3.10

1 year ago

2.3.9

1 year ago

2.3.8

1 year ago

2.3.7

1 year ago

2.3.6

1 year ago

2.3.5

1 year ago

2.3.4

1 year ago

2.2.4

1 year ago

1.2.4

1 year ago

1.1.4

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago