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

type: { type: "" } not handled

Open Cheyenne55 opened this issue 2 years ago • 1 comments

Hi there,

Just found a bug. For instance if having a schema like this :

{
  address: {
    type: { type: String },
    postalCode: String
  }
}

Your lib outputs :

{
  address: {
    type: String
  }
}

All properties are lost.

I fixed it by modifying 2 places :

https://github.com/giddyinc/mongoose-to-swagger/blob/82808a449b339f79ce79274e87a4f1a057b0b0b1/lib/index.ts#L56

if (type.type != null) {
if (type.type != null && !type.type?.type) {

https://github.com/giddyinc/mongoose-to-swagger/blob/82808a449b339f79ce79274e87a4f1a057b0b0b1/lib/index.ts#L142

const subSchema = value.type ? value.type : value;
const subSchema = value.type && !value.type?.type ? value.type : value;

I can open a PR if you want.

Cheers

Cheyenne55 avatar Sep 12 '22 15:09 Cheyenne55

Hi @Cheyenne55! Would absolutely accept a PR to fix this as well as adding a regression test. Thanks!

James1x0 avatar Nov 01 '22 16:11 James1x0