Steps to reproduce
A common pattern in TypeScript is to pull types from properties of other objects ensuring type safety and reducing redundancy...
- Create a Model or Entity:
@model({})
export class User extends Model {
@property()
public email : string;
@property()
public name : string;
@property()
public streetAddress : string;
@property()
public passwordHashedWithAPinchOfSalt : string;
}
- Create another with only a subset properties (maybe for use as a basic DTO for another endpoint):
@model({})
export class UserLogin extends Model {
@property()
public email : User["email"]; // --> When JSONSchema is generated this will resolve to an empty object type instead of string.
@property()
public password : string;
}
Current Behavior
As shown in the repro steps above, when pulling property types from other object types an incorrect JSON Schema is formed and validation on that property is no longer enforced due to the type not being inferred correctly.
Expected Behavior
In the example above, since User.email is of type string, it would be expected that the resolved type of UserLogin.email should be the same e.g. type string.
Sidenote. A "workaround" for this is to manually specify the type in the @property decorator options but this is less than ideal, defeats the purpose of eliminating redundancy, and I would argue unexpected.
Additional information
├── @loopback/authentication@2.1.8
├── @loopback/boot@1.4.3
├── @loopback/context@1.20.1
├── @loopback/core@1.9.0
├── @loopback/openapi-v3@1.6.4
├── @loopback/repository@1.10.1
├── @loopback/rest@1.16.2
├── @loopback/rest-explorer@1.2.4
├── @loopback/service-proxy@1.2.4
├── loopback-connector-mongodb@4.2.0
Related Issues
None found upon basic search.
Steps to reproduce
A common pattern in TypeScript is to pull types from properties of other objects ensuring type safety and reducing redundancy...
Current Behavior
As shown in the repro steps above, when pulling property types from other object types an incorrect JSON Schema is formed and validation on that property is no longer enforced due to the type not being inferred correctly.
Expected Behavior
In the example above, since User.email is of type
string, it would be expected that the resolved type of UserLogin.email should be the same e.g. typestring.Additional information
├── @loopback/authentication@2.1.8
├── @loopback/boot@1.4.3
├── @loopback/context@1.20.1
├── @loopback/core@1.9.0
├── @loopback/openapi-v3@1.6.4
├── @loopback/repository@1.10.1
├── @loopback/rest@1.16.2
├── @loopback/rest-explorer@1.2.4
├── @loopback/service-proxy@1.2.4
├── loopback-connector-mongodb@4.2.0
Related Issues
None found upon basic search.