-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to define a model @property that allows any scalar value? #4255
Comments
Try |
Nope, if I use any, loopback says that is not a valid type for the openapi spec:
|
Perhaps it needs to be as following:
This is what |
Yep, thats what I've tried. And get that error. |
I see sorry, I had assumed it the |
Yeah, kinda odd. |
@freakpol @dougal83, thanks for reporting this issue and analyzing it. |
We have |
@freakpol You could for now, define the property type as 'object'... ie: @property({
type: 'object'
})
data: anyObjectType
} // end of model
// custom type that's just an object with any value.
type anyObjectType = {
value: any;
}; Ofc this results in your data being |
Created PR #4930 Define the property in model as: import {AnyType} from '@loopback/repository';
@property({
// `@loopback/repository-json-schema` recognizes it
type: 'any'
})
// specify `AnyType` for it
arbitraryProp: AnyType Generated json schema would be arbitraryProp: {
$ref: '#/definitions/AnyType'
} Generated openapi spec would be "components": {
"schemas": {
"Todo": {
"title": "Todo",
"properties": {
"id": {
"type": "number"
},
// ...other properties
// The schema will be generated as a reference
// TODO: to completely support this feature, we can provide schema for
// swagger AnyType out-of-the-box
// see link https://swagger.io/docs/specification/data-models/data-types/#any
"arbitraryProp": {
"$ref": "#/components/schemas/AnyType"
}
},
"required": [
"title"
],
"additionalProperties": false
},
},
} A follow-up PR is coming for adding the openapi shema for any. components: {
schemas: {
AnyValue: {}
}
} |
Update: now you can define the property as @property({
// use type name 'any'
type: 'any'
})
// specify type as `any`
anyProperty: any Feel free to reopen the issue if you still have questions. Thanks. |
I'm want to store any type on a property, for example:
The idea, is that, when I POST to that entity I can send the following examples, and all work the same
Note: Database is a mongo db, so it shouldn't be a problem.
Acceptance Criteria
any
inlb4 model
cli should not result in "Unsupported type" error.References:
The text was updated successfully, but these errors were encountered: