Conversation
|
IIRC, it was @raymondfeng's intention to design the metadata used by Please note that it's the responsibility of legacy-juggler-bridge to convert model & property definitions from LB4 format to whatever is required by juggler. See To be honest, I don't know how to proceed with this pull request. Ideally, I'd like to hear from @raymondfeng on the array property format. On the other hand, he is away until next week and I don't want to block fixing #1562 because of that. Is there a way how to fix the issue while preserving the current format for defining array properties? |
| export function stringTypeToWrapper(type: string | Function): Function { | ||
| if (typeof type === 'function') { | ||
| return type; | ||
| } else { |
There was a problem hiding this comment.
Please remove this else block to reduce indentation level and keep the changeset smaller.
if (typeof type === 'function') {
return type;
}
type = type.toLowerCase();
let wrapper;
switch(type) {
// ...| describe('build-schema', () => { | ||
| describe('stringTypeToWrapper', () => { | ||
| it('returns respective wrapper of number, string and boolean', () => { | ||
| it('returns respective wrapper of number, string, boolean, array, buffer, date and object', () => { |
There was a problem hiding this comment.
One (logical) assert per test - please refactor this test into a series of small test cases.
it('returns String for "string"', () => {
expect(stringTypeToWrapper('string')).to.eql(String);
});
// ...| }).to.throw(/type is defined as an array/); | ||
| }); | ||
|
|
||
| it('errors out if "@property.array" is given "Array" as parameter', () => { |
There was a problem hiding this comment.
Why are all these tests removed?
There was a problem hiding this comment.
These tests have been moved above for better organization, I'll quickly check if I actually removed any of the tests
EDIT: I see what you mean. The @property.array exception path has been removed so that, unless specified in the decorator, the metadata will just equate to {type: Array} without any information on what type array it is. It kind of is a decision I made on my own though. Should we still maintain the strictness of array types being specified (throwing an error when type is Array/'array' without itemType being set to something)?
| Object.entries(definition.properties).forEach(([key, value]) => { | ||
| if (value.type === 'array' || value.type === Array) { | ||
| value = Object.assign({}, value, {type: [value.itemType]}); | ||
| delete value.itemType; |
There was a problem hiding this comment.
Do we need to delete value.itemType? This will get deleted from the actual definition.properties Object IIRC -- in case it needs to be referenced again.
There was a problem hiding this comment.
Would it? I did want to avoid the manipulation of actual definition.properties by reassigning the variable value to what is a modified clone of value in line 120. Did I miss a step? This test case should cover it: https://github.com/strongloop/loopback-next/pull/1570/files#diff-328c8e879ea3a53d7fb50599f1c6a77eR121
Should I use a new variable for the modified cloned value to avoid the confusion?
There was a problem hiding this comment.
nvm, the Object.assign creates a new reference. This is fine.
| val.tsType = 'Buffer[]'; | ||
| } else { | ||
| val.tsType = `string[]`; | ||
| val.tsType = 'string[]'; |
There was a problem hiding this comment.
'string[]' ---> 'String[]' ?
There was a problem hiding this comment.
I know string[] works but does String[] work as well?
There was a problem hiding this comment.
sorry never mind :( I mixed it with the array type in juggler. string[] is correct.
There was a problem hiding this comment.
found a String[] on line https://github.com/strongloop/loopback-next/pull/1570/files#diff-328c8e879ea3a53d7fb50599f1c6a77eR98...I feel confused again 🤔
There was a problem hiding this comment.
I think they both work 🤷♂️
| let result: JSONSchema; | ||
| let propertyType = meta.type as string | Function; | ||
|
|
||
| if (isArrayType(propertyType) && meta.itemType) { |
There was a problem hiding this comment.
hmm...any reason why using two different ways to assert the array type?
isArrayType vs Array.isArray
There was a problem hiding this comment.
isArrayType essentially asserts whether given data corresponds to the Wrapper Array or the string 'array'
a088aed to
cad6c02
Compare
virkt25
left a comment
There was a problem hiding this comment.
Clean up the commit history before merging but LGTM 🚢
The property definition for arrays used to be defined this way:
This does not match with the property definition of an array as the legacy juggler would define it. The property definition created by the
@property.array(String)decorator can now look like this:Related to #1508
Fixes #1562
Checklist
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated