mongoose-to-swagger icon indicating copy to clipboard operation
mongoose-to-swagger copied to clipboard

Conversion fails if my model has a property named "description"

Open helio-durable opened this issue 3 years ago • 0 comments

It looks like the algorithm can't differentiate a field named description from the attribute description.

I have a model like this:

//... more properties before here
date: { type: Date, default: Date.now },
    servicesRendered: [{
        _id: false,
        Service: { type: mongoose.Schema.Types.ObjectId, ref: 'Service' },
        description: String,
        quantity: Number,
        price: Number
    }],
    paymentTerms: String,
//more properties after...

the property "description" is not the description of the model but a property with type String. When converting it to swagger it generates as follows:

"date": {
            "type": "string",
            "format": "date-time"
          },
          "servicesRendered": {
            "type": "array",
            "items": {
              "type": "object",
              "description": function String() { [native code] },
              "properties": {
                "Service": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "quantity": {
                  "type": "number"
                },
                "price": {
                  "type": "number"
                }
              },
              "required": []
            }
          },
          "paymentTerms": {
            "type": "string"
          },

As you can see, it generates a description "description": function String() { [native code] }, and if failed to load the Swagger UI.

helio-durable avatar Nov 12 '21 17:11 helio-durable