question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema isn't being recognised

See original GitHub issue

I’m trying to create a plugin and so far it’s working great apart from the schema part.

I have the following manifest.js file:

module.exports = {
  version: '1.0.0',
  init: function (pluginContext) {
    pluginContext.registerPolicy(require('./policies/blacklist.js'))
  }
}

And the following policies/blacklist.js file:

module.exports = {
  name: 'blacklist',

  schema: {
    $id: 'http://express-gateway.io/schemas/policy/blacklist.json',
    type: 'object',
    required: ['urls'],
    properties: {
      urls: {
        type: 'array',
        items: {
          properties: {
            method: {
              type: 'string'
            },
            path: {
              type: ['string', 'null']
            }
          }
        }
      }
    }
  },

  policy: (actionParams) => {
...

The policy works as expected but it’s not validating the schema.

I get the following output from my console:

[EG:config] info: Registered schema for users model.
[EG:config] info: Registered schema for credentials model.
[EG:config] info: Registered schema for applications model.
[EG:config] debug: ConfigPath:
[EG:config] debug: ConfigPath:
[EG:plugins] debug: Loading plugins. Plugin engine version:
[EG:plugins] debug: Loading plugin
[EG:gateway] warn: express-gateway-plugin-bts-blacklist plugin hasn't provided a schema. Validation for this plugin will be skipped.
[EG:plugins] info: Loaded plugin
[EG:gateway] debug: registering policy

Note the specific part:

[EG:gateway] warn: express-gateway-plugin-bts-blacklist plugin hasn't provided a schema. Validation for this plugin will be skipped.

I am confused as I have specified the schema. It’s just ignoring it.

I’m using Express Gateway 1.10.1.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
XVincentXcommented, Jul 5, 2018

Hey @markwylde

this is not an Express Gateway issue. By default, the JSON Schema are permissive — which means that foreign properties are allowed.

You can fix this in two ways:

  • Make the method element required, so if you spell it incorrectly, you get an error:
{
    $id: 'http://express-gateway.io/schemas/policy/blacklist.json',
    type: 'object',
    required: ['urls'],
    properties: {
      urls: {
        type: 'array',
        items: {
          required: ['method'],
          properties: {
            method: {
              type: 'string'
            },
            path: {
              type: ['string', 'null']
            }
          }
        }
      }
    }
  }
  • Set the additionalProperties to false, so that provided objects MUST have only the declared properties:
{
    $id: 'http://express-gateway.io/schemas/policy/blacklist.json',
    type: 'object',
    required: ['urls'],
    properties: {
      urls: {
        type: 'array',
        items: {
          additionalProperties: false,
          properties: {
            method: {
              type: 'string'
            },
            path: {
              type: ['string', 'null']
            }
          }
        }
      }
    }
  }

Note: the second one, if I recall correctlu is an ajv specific feature.

0reactions
XVincentXcommented, Jul 5, 2018

This is fine, it happens to everybody. In case you need any further help you can jump in our Gitter Channel too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 reasons why your structured data is not showing in search
The schema should describe original content that your organization created. Must not cover inappropriate subjects like sexual violence or hate ...
Read more >
'.schema' is not recognized as an internal or external ...
I got as far as creating and syncing a DB, but when I type .schema into my command prompt, I get: '.schema' is...
Read more >
schema has not been registered for model error showing
it start to show error schema has not been registered. code of my model / Blog.js const mongoose = require('mongoose'); const Schema ......
Read more >
kubernetes_manifest resource warns OpenAPI schema not ...
kubernetes_manifest resource warns OpenAPI schema not recognised ... No warning - and for the OpenApi schema defined in CRD to be recognised ......
Read more >
How Do I Know If My Schema Markup Is Working?
First, the tool often caches versions of your page. This means that if you are actively making changes to your markup, the latest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found