loopbackio / loopbackio/loopback-next
getModelSchemaRef return base model json instead of extended one
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing getModelSchemaRef with an extended model such as EncodedDataWithParentId and compare the generated Swagger schema with the same call using exclude: []. Reproduce the POST body case with a child model that adds property b to aModel. Done means Swagger references the extended model and accepts its added property without requiring the workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100