wsdl-tsclient icon indicating copy to clipboard operation
wsdl-tsclient copied to clipboard

All properties in the generated interfaces are set to optional even if they are required

Open dikue opened this issue 1 year ago • 2 comments

As the titel says, all properties are optional. It seems like the code is missing a check for the xml property minOccurs.

dikue avatar Sep 23 '24 07:09 dikue

I have added this feature in my fork here https://github.com/stuikomma/wsdl-tsclient. It is quite a hacky implementation, but it works on our WSDL and on e.g. the marketo.wsdl example in this repo.

Note that this only handles whether a property is marked optional. Checking whether something should be nullable could be implemented similarly, but I didn't do it, because we don't need it for our use case.

@dderevjanik If you are interested in this functionality, I'd be willing to open a PR and clean up the implementation.

stuikomma avatar Jan 06 '25 08:01 stuikomma

Hi, I will leave this here in case it helps someone else.

In your fork you have this line

const originalSchema = wsdl.definitions.schemas[inputMessage.element.targetNamespace].complexTypes[typeNameWithoutNamespace];

With the wsdl im using, originalSchema would always be undefined, because typeNameWithoutNamespace wouldn't match the case of the keys inside complexTypes. I ended up doing this, it seems to work for my case, not sure if it's correct or not!

  const originalSchema =
                                        (wsdl.definitions.schemas[inputMessage.element.targetNamespace].complexTypes[
                                            typeNameWithoutNamespace
                                        ]) || (wsdl.definitions.schemas[inputMessage.element.targetNamespace].complexTypes[
                                            inputMessage.element.$name
                                        ]);

danielb7390 avatar Feb 24 '25 13:02 danielb7390