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

Expected "non-empty-string", got "string" #506

Closed
blessq12 opened this issue Apr 1, 2024 · 11 comments · Fixed by php-soap/engine#12 or #507
Closed

Expected "non-empty-string", got "string" #506

blessq12 opened this issue Apr 1, 2024 · 11 comments · Fixed by php-soap/engine#12 or #507

Comments

@blessq12
Copy link

blessq12 commented Apr 1, 2024

          i've faced with trouble on generate:classmap/types it return me an exeption with   Expected "non-empty-string", got "string".  How to fix that?

Originally posted by @blessq12 in #504 (comment)

@jfschubert
Copy link

i have the same issue.

trying to use the following WSDL,

https://tst.itserve.ch/swissdec/refapps/next/receiver/services/SalaryDeclarationService20200220?wsdl

trying to run the wizard gives me the error above mentioned

@blessq12
Copy link
Author

blessq12 commented Apr 1, 2024

i have the same issue.

trying to use the following WSDL,

https://tst.itserve.ch/swissdec/refapps/next/receiver/services/SalaryDeclarationService20200220?wsdl

trying to run the wizard gives me the error above mentioned

im disabled to type 'non-empty-string' check and wizard all done

in file NonEmptyStringType.php comment all thing that inner assert method and just return value from method. this will disable check type and wizard can go forward

@veewee
Copy link
Contributor

veewee commented Apr 1, 2024

Disabling the non-empty-string sounds like a very bad idea to be honest.

Feel free to provide more information, like WSDL. Configs,... so that it can be investigated further. It might be all separate issues as well.

One known issue that results in a non-empty-string situation is this one:
php-soap/wsdl-reader#23 (comment)

A PR that fixes that specific issue is linked and can be tested on your project as well. It might be the same.

I'm a bit busy the next days so I might not be able to provide a fast solution ATM.

@blessq12
Copy link
Author

blessq12 commented Apr 1, 2024

but in the other way if dont disable checking a non-empty-string i've give a exception and thats all. wizard stops with exception and not be able to generate separately types or classmap

@jfschubert
Copy link

One known issue that results in a non-empty-string situation is this one: php-soap/wsdl-reader#23 (comment)

Unfortuantly that does not work either.

im using the following config

<?php

use Phpro\SoapClient\CodeGenerator\Assembler;
use Phpro\SoapClient\CodeGenerator\Rules;
use Phpro\SoapClient\CodeGenerator\Config\Config;
use Soap\ExtSoapEngine\ExtSoapOptions;
use Phpro\SoapClient\Soap\CodeGeneratorEngineFactory;

return Config::create()
    ->setEngine($engine = CodeGeneratorEngineFactory::create(
        'https://tst.itserve.ch/swissdec/refapps/next/receiver/services/SalaryDeclarationService20200220?wsdl'
    ))
    ->setTypeDestination('src/Type')
    ->setTypeNamespace('App\Type')
    ->setClientDestination('src\client')
    ->setClientName('SwissdecClient')
    ->setClientNamespace('App\Client')
    ->setClassMapDestination('src\classmap')
    ->setClassMapName('SwissdecClassmap')
    ->setClassMapNamespace('App\Classmap')
    ->addRule(new Rules\AssembleRule(new Assembler\GetterAssembler(
        (new Assembler\GetterAssemblerOptions())->withDocBlocks(true)
    )))
    ->addRule(new Rules\AssembleRule(new Assembler\ImmutableSetterAssembler(
        (new Assembler\ImmutableSetterAssemblerOptions())->withDocBlocks(true)
    )))
    ->addRule(
        new Rules\IsRequestRule(
            $engine->getMetadata(),
            new Rules\MultiRule([
                new Rules\AssembleRule(new Assembler\RequestAssembler()),
                new Rules\AssembleRule(new Assembler\ConstructorAssembler(
                    (new Assembler\ConstructorAssemblerOptions())->withDocBlocks(true)
                )),
            ])
        )
    )
    ->addRule(
        new Rules\IsResultRule(
            $engine->getMetadata(),
            new Rules\MultiRule([
                new Rules\AssembleRule(new Assembler\ResultAssembler()),
            ])
        )
    )
    ->addRule(
        new Rules\IsExtendingTypeRule(
            $engine->getMetadata(),
            new Rules\AssembleRule(new Assembler\ExtendingTypeAssembler())
        )
    )
    ->addRule(
        new Rules\IsAbstractTypeRule(
            $engine->getMetadata(),
            new Rules\AssembleRule(new Assembler\AbstractClassAssembler())
        )
    )
;

This is on an entierly new Project. (composer.json)

{
     "require": {
        "php-soap/psr18-wsse-middleware": "^2.3",
        "symfony/http-client": "^6.4",
        "nyholm/psr7": "^1.8",
        "phpro/soap-client": "^3.1"
    },
    "config": {
        "allow-plugins": {
            "php-http/discovery": true
        }
    }
}

@veewee
Copy link
Contributor

veewee commented Apr 2, 2024

@jfschubert

https://tst.itserve.ch/swissdec/refapps/next/receiver/services/SalaryDeclarationService20200220?wsdl

The problem in this WSDL is:

<xs:simpleType name="EmptySimpleType">
    <xs:restriction base="xs:string">
      <xs:enumeration value=""/>
    </xs:restriction>
  </xs:simpleType>

Whilst, our meta class says:

  /**
   * @throws CoercionException
   */
  public function withEnums(?array $enums): self
  {
      $new = clone $this;
      $new->enums = optional(vec(non_empty_string()))->coerce($enums);

      return $new;
  }

So the fix lies in reworking php-soap/engine/src/Metadata/Model/TypeMeta.php to allow simple strings() instead of non-empty-strings. When doing the change, we need to make sure that enumeration code-generation doesn't fail.

@veewee
Copy link
Contributor

veewee commented Apr 2, 2024

@blessq12 you got any wsdl to share so that I can see what is going wrong there as well?

@blessq12
Copy link
Author

blessq12 commented Apr 2, 2024

@veewee sure ive got one and so much troubles how to use it normal

http://smev3-n0.test.gosuslugi.ru:7500/smev/v1.1/ws?wsdl

when i disable check type ( when i get an exception with non-empty-string ) the wizard generate all file that i need to create

a request to smev system but not it's return an SOAP-ERROR: Encoding: object has no 'any' property

and just one another question, can your lib to sign an part of envelope? i need to create an envelope and sign one part of it

@jfschubert
Copy link

@veewee Thank you for looking into it.
Its only used in ONE of the possible Type
got that while doing a return $value."FIXMEWSDL" instead of throw. and got exactly ONE Result afterwards. so i fixed the type by hand.

@veewee
Copy link
Contributor

veewee commented Apr 2, 2024

@blessq12, I've investigated the WSDL and it's the same issue I linked above.
php-soap/wsdl-reader#24
(I've tagged this one, so an update should be available through composer)

When I apply that patch, It is able to generate the types.
It might or might not be the reason why you get the soap-error : the provided classes are not valid at that moment.

However I do see one additional issue:

Error generating Type\SenderProvidedRequestData:Type "void" cannot be nullable

This is due to:
\Phpro\SoapClient\CodeGenerator\Util\Normalizer::$normalizations contains void => void, but the XML contains a Voidtype:

Void
====

> urn://x-artefacts-smev-gov-ru/services/message-exchange/types/basic/1.1:Void

+------------+------------------------------------------------------------------+
| Meta       | Value                                                            |
+------------+------------------------------------------------------------------+
| isAbstract | false                                                            |
| docs       | Тип элемента, который передаёт информацию фактом своего наличия. |
+------------+------------------------------------------------------------------+

For signing parts of the envelope, you can use:
https://github.com/php-soap/psr18-wsse-middleware

@veewee
Copy link
Contributor

veewee commented Apr 2, 2024

@jfschubert , @blessq12

I made PRs in the various sections where things went wrong.

You should be able to generate the types now given the WSDL you provided me.


If you like the work we provide here: feel free to sponsor us.

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

Successfully merging a pull request may close this issue.

3 participants