4.3.1 • Published 2 years ago

axway-schema v4.3.1

Weekly downloads
340
License
SEE LICENCE IN LI...
Repository
-
Last release
2 years ago

axway-schema

A singleton module for loading custom schemas and resolving them to json-schema docs

API Reference

Example (Quick start)

 const schemas = require('axway-schema');
 schemas.add('./schemas/foo.json')
	  .add('./schemas/bar.json', 'schema://myproject/bar')
	  .add('./schemas/swagger-v2.0.json')
	  .loadSync();
 schemas.get('schema:///foo');
 schemas.validate('schema:///foo', foo);
 schemas.get('schema:///foo/myproject/bar');
 schemas.validate('schema:///foo/myproject/bar', bar);
 schemas.get('http://swagger.io/v2/schema.json#');
 schemas.validate('http://swagger.io/v2/schema.json#', swagger);
 schemas.dereference(swagger);
 schemas.dereference(swagger, { target: '#/definitions' });
 schemas.dereference(swagger, { target: '#/definitions', rename: (id) => { return 'foo'; } });

axway-schema~AxwaySchema

A schema manager.

Kind: inner class of axway-schema
Access: public

new AxwaySchema()

Constructs a schema manager. The instance is a singleton.

axwaySchema.setLogger(logger)

Sets the Logger

Kind: instance method of AxwaySchema
Access: public

ParamTypeDescription
loggerLoggerA logger.

axwaySchema.add(item, defaultId) ⇒ AxwaySchema

Adds an item to be loaded later by calling loadSync. The item can be a string, in which case it is a schema file, and an optional defaultId will be used for the id if the file does not have an id. If the file does not have an id and no defaultId is supplied, the function will throw.

If the item is an object, it is a valid schema that has an id defined so that it can be referenced later. In this case, defaultId is ignored.

Kind: instance method of AxwaySchema
Returns: AxwaySchema - The AxwaySchema object.
Access: public

ParamTypeDescription
itemstring | objectThe item to add (a filename or schema).
defaultIdstringThe item id if one not supplied.

Example (Add a schema)

 const schemas = new AxwaySchema();
 schemas.add('./schema1.json');
 schemas.add('./schema2.json', 'schema://project/myapp/schema2.json');
 schemas.add({id: 'http://axway.com/schemas/user.json'});

axwaySchema.register(schema) ⇒ AxwaySchema

Registers a global schema that will persist across calls to clear operations. Schemas registered with the same id will generate a warning but will be ignored.

Kind: instance method of AxwaySchema
Returns: AxwaySchema - The AxwaySchema object.

ParamTypeDescription
schemaobjectThe schema.

axwaySchema.loadSync() ⇒ AxwaySchema

Loads all schemas previously added with calls to add.

Kind: instance method of AxwaySchema
Returns: AxwaySchema - The AxwaySchema object.
Access: public
Example (Load schemas)

 const schemas = new AxwaySchema();
 schemas
	  .add('./schema1.json');
	  .add('./schema2.json', 'project');
	  .loadSync());

axwaySchema.clear() ⇒ AxwaySchema

Clears all schemas and resets state. All registered schema will be automatically re-added on next load.

Kind: instance method of AxwaySchema
Returns: AxwaySchema - The AxwaySchema object.
Access: public

axwaySchema.exists(id) ⇒ boolean

Tests whether or not a schema is loaded, identified by id.

Kind: instance method of AxwaySchema
Returns: boolean - True if the schema exists.
Access: public

ParamTypeDescription
idstringThe schema identifier to test.

axwaySchema.get(id) ⇒ object

Gets a schema by id. If id is not supplied, all schemas are returned.

Kind: instance method of AxwaySchema
Returns: object - Returns a schema identified by id.
Access: public

ParamTypeDescription
idstringThe schema identifier.

axwaySchema.validate(id, obj) ⇒ string

Validates an object obj against a schema identified by id.

Kind: instance method of AxwaySchema
Returns: string - Returns an error string when not valid, undefined otherwise.
Access: public

ParamTypeDescription
idstringThe schema identifier.
objobjectThe object to validate.

axwaySchema.dereference(doc, options) ⇒ object

Dereferences non-local references in the supplied document. The supplied document is not modified. All non-local references (e.g schema://) will be replaced with the corresponding loaded schema. If schema are not found, an error will be thrown.

If options.target is not supplied, then references are expanded inline. If options.target is supplied, then references are expanded in the location specified by options.target and any existing reference updated to point to the new target. For example, if the options.target is #/definitions, then the schema will be expanded to $.definitions with the name of the schema the trailing component (basename) of its id, or if options.rename is supplied, the name returned by that.

Kind: instance method of AxwaySchema
Returns: object - Returns a document with schema:// references expanded.
Access: public

ParamTypeDescription
docobjectA document
optionsobjectOptions
options.targetstringA target
options.renametargetRenameCallbackA callback to rename schema

axwaySchema.getErrorString(errors, objectType) ⇒ string

The ajv.errorsText is actually not very good.

Kind: instance method of AxwaySchema
Returns: string - A formatted error string.
Access: public

ParamTypeDescription
errorsarrayajv errors object
objectTypestringThe name of the object type that was validated

axway-schema~targetRenameCallback ⇒ string

Callback function to rename a target when used as a dereference target. For example, if your id is "schema://svc.foo/bar", then bar will be written to the dereference target as bar. If you want to rename bar, then use this function.

Kind: inner typedef of axway-schema
Returns: string - Return the renamed target.
Access: public

ParamTypeDescription
ididThe schema id.

Building

npm run build

Author

Axway support@axway.com https://axway.com

License

This code is closed source and Confidential and Proprietary to Axway, Inc. All Rights Reserved. This code MUST not be modified, copied or otherwise redistributed without express written permission of Axway. This file is licensed as part of the Axway Platform and governed under the terms of the Axway license agreement. Your right to use this software terminates when you terminate your Axway subscription.

4.2.7

3 years ago

4.2.8

2 years ago

4.3.1

2 years ago

4.3.0

2 years ago

4.2.6

3 years ago

4.2.5

3 years ago

4.2.4

4 years ago

4.2.3

4 years ago

4.2.2

4 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.8

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

2.2.3

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

2.2.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.1

6 years ago

3.0.0-5

6 years ago

3.0.0-4

6 years ago

3.0.0-3

6 years ago

3.0.0-2

6 years ago

3.0.0-1

6 years ago

2.1.1-1

6 years ago

2.1.1-0

6 years ago

2.1.0

6 years ago

2.0.5-103

6 years ago

2.0.5-102

6 years ago

2.0.5-101

6 years ago

2.0.4

7 years ago

2.0.2

7 years ago