Skip to content
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

wsdl generation - add ability to exclude portType name from generated classes and files #613

Closed
brunnels opened this issue Nov 10, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@brunnels
Copy link

Can you please add a generator flag to omit the portType name from generated file names and class names? Something like --omit-port_type_name or something more elegant.

    <wsdl:portType name="NetworkManagementApi">
        <wsdl:operation name="login">
            <wsdl:documentation></wsdl:documentation>
            <wsdl:input message="nas:loginRequest"/>
            <wsdl:output message="nas:loginResponse"/>
            <wsdl:fault name="error" message="nas:nasFaultMessage"/>
        </wsdl:operation>
    </wsdl:portType>

I did this with a custom Filters class and it seems to work even with reserved keywords. I didn't immediately see a way to access the wsdl portType name from the Filters class so I hardcoded it for testing but I may have missed it.

class PortTypeFilters(Filters):
    def safe_name(
            self, name: str, prefix: str, name_case: Callable, **kwargs: Any
    ) -> str:
        if name:
            name = name.replace("NetworkManagementApi_", "")
        return super().safe_name(name, prefix, name_case, **kwargs)

    def class_name(self, name: str) -> str:
        alias = self.class_aliases.get(name)
        if alias:
            return alias

        name = self.safe_name(
            name.replace("NetworkManagementApi", ""),
            self.class_safe_prefix,
            self.class_case
        )
        return name
@tefra
Copy link
Owner

tefra commented Nov 14, 2021

I would prefer something more generic like a search and replace in the class names, instead of adding something so specific to the wsdl mapper and I have been thinking this one for while now since I needed recently as well but it's not in my top priorities right now.

In the mean time, we already have the aliases config that can achieve the same, it might be a bit tedious to add one entry per operation but it's there

https://xsdata.readthedocs.io/en/latest/api/codegen.html

@tefra tefra added the enhancement New feature or request label Nov 14, 2021
@brunnels
Copy link
Author

Is there any command or debug that would output the default generator config xml for a wsdl file? Then it would be easy enough to do a search and replace on the config to customize it as required.

@tefra
Copy link
Owner

tefra commented Nov 15, 2021

I am not sure what you mean but this is how you initialize a config

$ xsdata init-config

https://xsdata.readthedocs.io/en/latest/codegen.html#initialize-config

@tefra
Copy link
Owner

tefra commented Nov 23, 2021

hey @brunnels can you check #624 and let me know what you think?

@tefra
Copy link
Owner

tefra commented Nov 25, 2021

hey @brunnels I just pushed an update for the generator config to introduce a search & replace process that completely repalces the older fixed aliases. Give it a look https://xsdata.readthedocs.io/en/latest/api/codegen.html

Maybe something like this could do the trick, you can also try to play with regex patterns the process is now based on re.sub https://docs.python.org/3/library/re.html#re.sub

  <Substitutions>
    <Substitution type="class" search="NetworkManagementApi" replace=""/>
  </Substitutions>

Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants