Skip to content

How to define a model @property that allows any scalar value? #4255

@freakpol

Description

@freakpol

I'm want to store any type on a property, for example:

@model()
class MyModel extends Entity{
    @property({id: true})
    id: number;

    @property({
        type: 'I DONT KNOW WHT TO PUT HERE TO ALLOW ANY VALUE'
    })
    value: any;
}

The idea, is that, when I POST to that entity I can send the following examples, and all work the same

POST /mymodels 
{
  "id": 1,
  "value": 1
}
---
POST /mymodels 
{
  "id": 2,
  "value": "1"
}
---
POST /mymodels 
{
  "id": 3,
  "value": true
}
---
POST /mymodels 
{
  "id": 4,
  "value": null
}
---
POST /mymodels 
{
  "id": 5,
  "value": {"a":"b" }
}

Note: Database is a mongo db, so it shouldn't be a problem.

Acceptance Criteria

  • Specify type any in lb4 model cli should not result in "Unsupported type" error.
  • Add test to make sure the type can be converted to OpenAPI spec correctly

References:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions