-
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
Model Schemas Not Generated Properly When Using Type Alases For Property Types #3863
Comments
I am afraid this is a limitation of TypeScript. Here is the code emitted for your let UserLogin = class UserLogin extends __1.Model {
};
__decorate([
__1.property(),
__metadata("design:type", Object)
], UserLogin.prototype, "email", void 0);
__decorate([
__1.property(),
__metadata("design:type", String)
], UserLogin.prototype, "password", void 0);
UserLogin = __decorate([
__1.model()
], UserLogin); As you can see on the line 3, TypeScript is providing the following Feel free to search TypeScript issue tracker to see if this is a known problem and perhaps open a new issue if it's not. As for LoopBack, I think our best option is to improve the documentation to make this fact easier to find by users. Do you have any suggestions where would you look for such information yourself? Would you like to contribute the doc changes yourself? See our Contributing guide and Submitting a pull request to LoopBack 4 to get started. |
Ah. I'm relatively new to LB4 - I assumed the OpenAPI spec was getting generated via TS API by parsing the AST rather than reflection metadata, that makes sense. Also interesting that the injected metadata doesn't handle this situation on the TypeScript side, definitely seems like a gap in the compiler. In any case, @bajtos thanks for the quick reply and breakdown. My best guess to provide footnote/warning/caveat would be in |
Changes Model.md to reflect a known issue with property reflection when dealing with type aliases and extracted types. See loopbackio#3863. No code changes.
Changes Model.md to reflect a known issue with property reflection when dealing with type aliases and extracted types. Edit - adds example suggested by @raymondfeng. See loopbackio#3863. No code changes.
Changes Model.md to reflect a known issue with property reflection when dealing with type aliases and extracted types. Edit - adds example suggested by @raymondfeng. See loopbackio#3863. No code changes.
Changes Model.md to reflect a known issue with property reflection when dealing with type aliases and extracted types. Edit - adds example suggested by @raymondfeng. See loopbackio#3863. No code changes.
Changes Model.md to reflect a known issue with property reflection when dealing with type aliases and extracted types. Edit - adds example suggested by @raymondfeng. See #3863. No code changes.
Closing this as #3871 has been merged. |
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/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── [email protected]
Related Issues
None found upon basic search.
The text was updated successfully, but these errors were encountered: