Skip to content

Required Validators On Nested Objects was not working properly#39

Open
simonjoom wants to merge 13 commits into
simonguest:masterfrom
simonjoom:master
Open

Required Validators On Nested Objects was not working properly#39
simonjoom wants to merge 13 commits into
simonguest:masterfrom
simonjoom:master

Conversation

@simonjoom

@simonjoom simonjoom commented May 13, 2017

Copy link
Copy Markdown

-> Required Validators On Nested Objects fixed
with required on nested object i had a error from mongoose:: /Cannot.*'required'/ As well i could enter any object when i create the validation of schema is not working.

See http://mongoosejs.com/docs/validation.html
Chapitre:
« Required Validators On Nested Objects »

The return getSchema isn't a full fledged path , need to use a single nested schema else the user can enter any schema object the validation will pass (mongoose will comporte as a type Mixed.
Solution:
Fixed properly validation check with nested object process ref should to return a type to a Object mongoose.schema and not a simple javascript object.

there is as well different bug fixed
Was tested with last swagger.

simon added 13 commits May 13, 2017 19:10
fixed bug for additional-properties with array of items (line 407-410)

-> Required Validators On Nested Objects fixed
with required on nested object i had a error from mongoose:: /Cannot.*'required'/ As well i could enter any object when i create the validation of schema is not working.

See http://mongoosejs.com/docs/validation.html
Chapitre:
« Required Validators On Nested Objects »

The return getSchema isn't a full fledged path , need to use a single nested schema else the user can enter any schema object the validation will pass (mongoose will comporte as a type Mixed.
Solution:
Fixed properly validation check with nested object process ref should to return a type to a Object mongoose.schema and not a simple javascript object.

Added support of array of enum with multiple values (line 257)
props[key] = [{type: String, enum: property.items.enum}];

Here a sample of definitions i work with: (you can see required attribute for nested schema latlng and bounds
definitions=
{
  latlng: {
    "type":"object",
    "required": [
      "lat",
      "lng"
    ],
    "properties": {
      "lat": {
        "type": "number",
        "format": "long",
        "description": "latitude"
      },
      "lng": {
        "type": "number",
        "format": "long",
        "description": "longitude"
      }
    },
    "x-swagger-mongoose": {
      "schema-options": {
        "_id": false
      }
    }
  },
  bounds: {
    "type":"object",
    "required": [
      "_southWest",
      "_northEast"
    ],
    "description": "The boundary object",
    "properties": {
      "_southWest": {
        "$ref": "#/definitions/latlng"
      },
      "_northEast": {
        "$ref": "#/definitions/latlng"
      }
    },
    "x-swagger-mongoose": {
      "schema-options": {
        "_id": false
      }
    }
  },
boundary: {
    "type":"object",
    "required": [
      "name",
      "bounds"
    ],
    "properties": {
      "name": {
        "type": "string",
        "description": "name"
      },
      "color": {
        "type": "string",
        "description": "color"
      },
      "bounds": {
        "$ref": "#/definitions/bounds"
      },
      "createdBy": {
        "type": "string",
        "description": "createdBy"
      },
    },
    "x-swagger-mongoose": {
      "additional-properties": {
        "boundaries": {
          "items": {
            "x-swagger-mongoose": {
              "$ref": "#/definitions/boundaryRects"
            },
          },
        },
      },
      "schema-options": {
        "timestamps": "true"
      }
    }
  }
 }
with required on nested object i had a error from mongoose:: /Cannot.*'required'/ As well i could enter any object when i create the validation of schema is not working.

See http://mongoosejs.com/docs/validation.html
Chapitre:
« Required Validators On Nested Objects »

The return getSchema isn't a full fledged path , need to use a single nested schema else the user can enter any schema object the validation will pass (mongoose will comporte as a type Mixed.
Solution:
Fixed properly validation check with nested object process ref should to return a type to a Object mongoose.schema and not a simple javascript object.

Added support of array of enum with multiple values (line 257)
props[key] = [{type: String, enum: property.items.enum}];

fixed bug for additional-properties with array of items (line 407-410)

Here a sample of definitions i work with: (you can see required attribute for nested schema latlng and bounds
definitions=
{
latlng: {
"type":"object",
"required": [
"lat",
"lng"
],
"properties": {
"lat": {
"type": "number",
"format": "long",
"description": "latitude"
},
"lng": {
"type": "number",
"format": "long",
"description": "longitude"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
bounds: {
"type":"object",
"required": [
"_southWest",
"_northEast"
],
"description": "The boundary object",
"properties": {
"_southWest": {
"$ref": "#/definitions/latlng"
},
"_northEast": {
"$ref": "#/definitions/latlng"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
boundary: {
"type":"object",
"required": [
"name",
"bounds"
],
"properties": {
"name": {
"type": "string",
"description": "name"
},
"color": {
"type": "string",
"description": "color"
},
"bounds": {
"$ref": "#/definitions/bounds"
},
"createdBy": {
"type": "string",
"description": "createdBy"
},
},
"x-swagger-mongoose": {
"additional-properties": {
"boundaries": {
"items": {
"x-swagger-mongoose": {
"$ref": "#/definitions/boundaryRects"
},
},
},
},
"schema-options": {
"timestamps": "true"
}
}
}
}
with required on nested object i had a error from mongoose:: /Cannot.*'required'/ As well i could enter any object when i create the validation of schema is not working.

See http://mongoosejs.com/docs/validation.html
Chapitre:
« Required Validators On Nested Objects »

The return getSchema isn't a full fledged path , need to use a single nested schema else the user can enter any schema object the validation will pass (mongoose will comporte as a type Mixed.
Solution:
Fixed properly validation check with nested object process ref should to return a type to a Object mongoose.schema and not a simple javascript object.

Added support of array of enum with multiple values (line 257)
props[key] = [{type: String, enum: property.items.enum}];

fixed bug for additional-properties with array of items (line 407-410)

Here a sample of definitions i work with: (you can see required attribute for nested schema latlng and bounds
definitions=
{
latlng: {
"type":"object",
"required": [
"lat",
"lng"
],
"properties": {
"lat": {
"type": "number",
"format": "long",
"description": "latitude"
},
"lng": {
"type": "number",
"format": "long",
"description": "longitude"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
bounds: {
"type":"object",
"required": [
"_southWest",
"_northEast"
],
"description": "The boundary object",
"properties": {
"_southWest": {
"$ref": "#/definitions/latlng"
},
"_northEast": {
"$ref": "#/definitions/latlng"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
boundary: {
"type":"object",
"required": [
"name",
"bounds"
],
"properties": {
"name": {
"type": "string",
"description": "name"
},
"color": {
"type": "string",
"description": "color"
},
"bounds": {
"$ref": "#/definitions/bounds"
},
"createdBy": {
"type": "string",
"description": "createdBy"
},
},
"x-swagger-mongoose": {
"additional-properties": {
"boundaries": {
"items": {
"x-swagger-mongoose": {
"$ref": "#/definitions/boundaryRects"
},
},
},
},
"schema-options": {
"timestamps": "true"
}
}
}
}
with required on nested object i had a error from mongoose:: /Cannot.*'required'/ As well i could enter any object when i create the validation of schema is not working.

See http://mongoosejs.com/docs/validation.html
Chapitre:
« Required Validators On Nested Objects »

The return getSchema isn't a full fledged path , need to use a single nested schema else the user can enter any schema object the validation will pass (mongoose will comporte as a type Mixed.
Solution:
Fixed properly validation check with nested object process ref should to return a type to a Object mongoose.schema and not a simple javascript object.

Added support of array of enum with multiple values (line 257)
props[key] = [{type: String, enum: property.items.enum}];

fixed bug for additional-properties with array of items (line 407-410)

Here a sample of definitions i work with: (you can see required attribute for nested schema latlng and bounds
definitions=
{
latlng: {
"type":"object",
"required": [
"lat",
"lng"
],
"properties": {
"lat": {
"type": "number",
"format": "long",
"description": "latitude"
},
"lng": {
"type": "number",
"format": "long",
"description": "longitude"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
bounds: {
"type":"object",
"required": [
"_southWest",
"_northEast"
],
"description": "The boundary object",
"properties": {
"_southWest": {
"$ref": "#/definitions/latlng"
},
"_northEast": {
"$ref": "#/definitions/latlng"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
boundary: {
"type":"object",
"required": [
"name",
"bounds"
],
"properties": {
"name": {
"type": "string",
"description": "name"
},
"color": {
"type": "string",
"description": "color"
},
"bounds": {
"$ref": "#/definitions/bounds"
},
"createdBy": {
"type": "string",
"description": "createdBy"
},
},
"x-swagger-mongoose": {
"additional-properties": {
"boundaries": {
"items": {
"x-swagger-mongoose": {
"$ref": "#/definitions/boundaryRects"
},
},
},
},
"schema-options": {
"timestamps": "true"
}
}
}
}
with required on nested object i had a error from mongoose:: /Cannot.*'required'/ As well i could enter any object when i create the validation of schema is not working.

See http://mongoosejs.com/docs/validation.html
Chapitre:
« Required Validators On Nested Objects »

The return getSchema isn't a full fledged path , need to use a single nested schema else the user can enter any schema object the validation will pass (mongoose will comporte as a type Mixed.
Solution:
Fixed properly validation check with nested object process ref should to return a type to a Object mongoose.schema and not a simple javascript object.

Added support of array of enum with multiple values (line 257)
props[key] = [{type: String, enum: property.items.enum}];

fixed bug for additional-properties with array of items (line 407-410)

Here a sample of definitions i work with: (you can see required attribute for nested schema latlng and bounds
definitions=
{
latlng: {
"type":"object",
"required": [
"lat",
"lng"
],
"properties": {
"lat": {
"type": "number",
"format": "long",
"description": "latitude"
},
"lng": {
"type": "number",
"format": "long",
"description": "longitude"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
bounds: {
"type":"object",
"required": [
"_southWest",
"_northEast"
],
"description": "The boundary object",
"properties": {
"_southWest": {
"$ref": "#/definitions/latlng"
},
"_northEast": {
"$ref": "#/definitions/latlng"
}
},
"x-swagger-mongoose": {
"schema-options": {
"_id": false
}
}
},
boundary: {
"type":"object",
"required": [
"name",
"bounds"
],
"properties": {
"name": {
"type": "string",
"description": "name"
},
"color": {
"type": "string",
"description": "color"
},
"bounds": {
"$ref": "#/definitions/bounds"
},
"createdBy": {
"type": "string",
"description": "createdBy"
},
},
"x-swagger-mongoose": {
"additional-properties": {
"boundaries": {
"items": {
"x-swagger-mongoose": {
"$ref": "#/definitions/boundaryRects"
},
},
},
},
"schema-options": {
"timestamps": "true"
}
}
}
}
Debug in case of unrecognized schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant