typeStorageを確実に参照するようにする#1230
Conversation
|
To make it easier to understand could you translate this to English and explain why do you need this change? Also, if it is possible please cover changes with the tests. |
|
From deepl: """ Tentatively solved the problem that xmlToObject for ltea does not convert array types as arrays. Not sure if that helps 🤷 but I was curious :) |
| type = splitQName(type); | ||
| const typeStorage = this.$type ? definitions.descriptions.types : definitions.descriptions.elements; | ||
| const typeName: string = type.name; | ||
| if(typeName in typeStorage){// typeにtypeNameが入ってしまった場合の対応、本来はこのようなことが起きないように対処すべきかもしれない。 |
There was a problem hiding this comment.
"// typeName in type, perhaps this should be handled to prevent this from happening in the first place."
| const typeName: string = type.name; | ||
| if(typeName in typeStorage){// typeにtypeNameが入ってしまった場合の対応、本来はこのようなことが起きないように対処すべきかもしれない。 | ||
| if (this.$ref) { | ||
| element = typeStorage[typeName]; |
There was a problem hiding this comment.
Probably, need to check that typeStorage[typeName] has a value, could be undefined, null ... anything
There was a problem hiding this comment.
The current code guarantees this that typeStorage[cacheKey] (formerly typeStorage[typeName]) is set.
if (!(cacheKey in typeStorage)) {
let elem: any = {};
typeStorage[cacheKey] = elem;
if (isMany && 'maxOccurs' in typeElement) {
typeElement.maxOccurs = this.$maxOccurs;
}
if (Boolean(this.$minOccurs) && 'minOccurs' in typeElement) {
typeElement.minOccurs = this.$minOccurs;
}
const description = typeElement.description(definitions, xmlns);
if (typeof description === 'string') {
elem = description;
} else {
Object.keys(description).forEach((key) => {
elem[key] = description[key];
});
const $attributes = description[AttributeElement.Symbol];
if ($attributes) {
elem[AttributeElement.Symbol] = $attributes;
}
}
if (this.$ref) {
element = elem;
} else {
element[name] = elem;
}
if (typeof elem === 'object') {
elem.targetNSAlias = type.prefix;
elem.targetNamespace = ns;
}
typeStorage[cacheKey] = elem;
} else {
if (this.$ref) {
// Differentiate between a ref for an array of elements and a ref for a single element
if (isMany) {
const refTypeName = typeName + '[]';
const refCacheKey = ns ? `${ns}::${refTypeName}` : refTypeName;
typeStorage[refCacheKey] = typeStorage[cacheKey];
element[refTypeName] = typeStorage[refCacheKey];
} else {
element = typeStorage[cacheKey];
}
} else {
element[name] = typeStorage[cacheKey];
}
}
w666
left a comment
There was a problem hiding this comment.
Needs a test. While code makes sense, implementation should be locked, so other changes do not break this,
|
Upon reading further, unless I don't understand something, I believe actually the existing code already covers what the PR proposes just further down a few lines. Specifically the check's if() and the else() and the value is set properly. node-soap/src/wsdl/elements.ts Line 261 in 9c6ad01 node-soap/src/wsdl/elements.ts Line 292 in 9c6ad01 If my understanding is correct, I think this PR can simply be closed. |
|
@w666 -- per my earlier reasoning the current code I think covers what was proposed here due to another PR that got merged and covers element values in different configurations; I think it was min/maxOccurs PR that refactored that code. Please review if you agree with me and simply close this PR if you do. I don't think there is much else to do here. |
|
I was trying to see if this PR still has any merit and can be salvaged, but the current code covers everything. In fact the PR has reduced basically to a single line move:
|
alteaに対するxmlToObjectで配列型を配列として変換してくれない問題を暫定的に解消。
node-soap的に望ましい実装ではなさそうだが...。