loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

getModelSchemaRef return base model json instead of extended one

Open ivanvaccari opened this issue 3 years ago • 0 comments

Steps to reproduce

  • Create a model aModel with property "a"
  • Create a model bModel by extending aModel , add property "b" to it
  • Create a controller with a POST endpoint which uses bModel as body input model
  • Open swagger and check the input model definition for your POST endopint

Current Behavior

  • Swagger declares it expect a aModel instance, throwing error if the propery "b" is passed

Expected Behavior

  • Swagger should declare it expects a bModel instance.

Additional information

A very strange behavior i've found is this one:

@model()
export class EncodedDataWithParentId extends InputModel{
    @property({
        type:'string',
        required: true
    })
    parentId: typeof Asset.prototype.id;
}

// note: this variable is passed as spec in API definition
export const uploadRequestBodySpec = {
    content: {
        'application/json': {
            schema: getModelSchemaRef(EncodedDataWithParentId),
        },
    },
};

With this code i'm expecting swagger to show the EncodedDataWithParentId model as input in the relative API, but InputModel is shown instead.

If i change the line

schema: getModelSchemaRef(EncodedDataWithParentId),

adding the apparently unrelated exclude property

schema: getModelSchemaRef(EncodedDataWithParentId, {exclude:[]}),

swagger will propose EncodedDataWithParentId as input model for the POST body

Any suggestion?

ivanvaccari avatar Nov 08 '21 11:11 ivanvaccari