Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Schema type: "object" fails on generate #61

Closed
samburgers opened this issue Oct 1, 2018 · 4 comments
Closed

Schema type: "object" fails on generate #61

samburgers opened this issue Oct 1, 2018 · 4 comments

Comments

@samburgers
Copy link

samburgers commented Oct 1, 2018

Have been attempting some of the json-schema validations here:
https://code.tutsplus.com/tutorials/validating-data-with-json-schema-part-1--cms-25343

Appears to fail whenever using type: 'object' for example:

let schema = {
  properties: {
    address: {
      type: 'object',
      additionalProperties: { type: 'string' },
      maxProperties: 6,
      required: ['street', 'postcode', 'city', 'country']
    },
  }
};

Fails with this console error when running feathers-plus generate all:

events.js:183
      throw er; // Unhandled 'error' event
      ^

TypeError: subTypes.map is not a function

Is this a known/acceptable behaviour?

@eddyystop
Copy link
Member

How are you running that fragment to cause the error?

Could you provide the full path of the module which is throwing? Its not part of the generator, nor of ajv, the module validateSchema uses. So I have no idea which dependency is throwing.

@samburgers
Copy link
Author

samburgers commented Oct 1, 2018

Thanks for the reply, here are the steps to reproduce

Generate App

feathers-plus generate app

? Project name fpcli
? Description Project fpcli
? What folder should the source files live in? src
? Which package manager are you using
  (has to be installed globally)? Yarn
? What type of API are you making?
 REST, Realtime via Socket.io
? Data mutating tests and seeding may run when NODE_ENV is one of (optional) test
? Seed data records on startup when command line includes --seed? Yes

Generate Service

feathers-plus generate service

? What is the name of the service? posts
? What would you call one row in the posts database? post
? What kind of service is it? Mongoose
? Place service code in which nested folder, e.g. `v1/blog`? (optional) 
? Which path should the service be registered on? /posts
? Should this be served by GraphQL? Yes

Add Object with properties to schema:

/src/services/posts/posts.schema.js

properties: {
  // !code: schema_properties

  address: {
      type: 'object',
      additionalProperties: { type: 'string' },
      maxProperties: 6,
      required: ['street', 'postcode', 'city', 'country']
    },
  // !end
}

Rerun service generate:

feathers-plus generate service

? What is the name of the service? posts
? What would you call one row in the posts database? post
? What kind of service is it? Mongoose
? Place service code in which nested folder, e.g. `v1/blog`? (optional)
? Which path should the service be registered on? /posts
? Should this be served by GraphQL? Yes
events.js:183
      throw er; // Unhandled 'error' event
      ^

TypeError: subTypes.map is not a function
    at Object.keys.forEach.name (/Users/me/.config/yarn/global/node_modules/@feathers-plus/generator-feathers-plus/lib/service-specs-to-typescript.js:24:32)
    at Array.forEach (<anonymous>)
    at serviceSpecsToTypescript (/Users/me/.config/yarn/global/node_modules/@feathers-plus/generator-feathers-plus/lib/service-specs-to-typescript.js:16:27)
    at service (/Users/me/.config/yarn/global/node_modules/@feathers-plus/generator-feathers-plus/generators/writing/index.js:583:7)
    at generatorWriting (/Users/me/.config/yarn/global/node_modules/@feathers-plus/generator-feathers-plus/generators/writing/index.js:253:7)
    at ServiceGenerator.writing (/Users/me/.config/yarn/global/node_modules/@feathers-plus/generator-feathers-plus/generators/service/index.js:246:5)
    at Object.<anonymous> (/Users/me/.config/yarn/global/node_modules/yeoman-generator/lib/index.js:424:27)
    at /Users/me/.config/yarn/global/node_modules/run-async/index.js:25:25
    at new Promise (<anonymous>)
    at /Users/me/.config/yarn/global/node_modules/run-async/index.js:24:19
    at self.env.runLoop.add.completed (/Users/me/.config/yarn/global/node_modules/yeoman-generator/lib/index.js:425:13)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

@eddyystop
Copy link
Member

I misunderstood you when you mentioned "json-schema validations". I understood that as you trying to validate record contents using some of the exports from src/services/name/name.validate.?s.

The name.schema.?s expects type: 'object' to contain a poperties property which contains at least one field.

So, from the example, instead of

    "address": {
      "type": "object",
      "additionalProperties": { "type": "string" },
      "maxProperties": 6,
      "required": ["street", "postcode", "city", "country"]
    },

rather like the following

    "personal": {
      "type": "object",
      "properties": {
        "DOB": { "type": "string", "format": "date" },
        "age": { "type": "integer", "minimum": 13 },
        "gender": { "enum": ["female", "male"] }
      }
      "required": ["DOB", "age"],
      "additionalProperties": false
    },
``

@eddyystop
Copy link
Member

I added an issue to support the notation used in address #64

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants