I'm currently working on developing a REST API using Express, Mongoose, and Swagger for API documentation. To automate the process of converting my existing schema to Swagger, I utilized the mongoose-to-swagger package. However, I encountered an issue where Swagger was adding an extra "_id" field in the schema as depicted in the image.
https://i.sstatic.net/MqUQl.png
Moreover, when attempting to post a new user, I received the following error message:
ValidationError: Buyer validation failed: Buyer_Delivery_Address._id: Cast to ObjectId failed for value "1" (type number) at path "_id" due to "BSONTypeError"
reason: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
_message: 'Buyer validation failed'
How can this issue be resolved?
The App.js
`
const express = require("express");
const mongoose = require("mongoose");
const m2s = require('mongoose-to-swagger');
const swaggerjsdocs = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const bodyParser = require("body-parser")
const Buyer = require('./models/Buyer_model')
// Code continues...
`
Buyer_model.js
`
const mongoose = require("mongoose")
const buyerSchema = new mongoose.Schema({
// Schema definition
})
module.exports = mongoose.model('Buyer', buyerSchema)