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

Collect meta attributes from XSD files #83

Merged
merged 6 commits into from
Jun 4, 2024

Conversation

veewee
Copy link
Contributor

@veewee veewee commented May 28, 2024

Hello,

In WSDLs, it is possible that additional arguments are being added to the XSD configurations.
This information gets lost currently.

This PR introduces a system to collect this kind of information.
Currently it is only added for attributes, but it could as well be added for other types as well.

Example:

    <complexType name="testType">
        <complexContent>
            <restriction base="SOAP-ENC:Array">
        <attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="int[]"/>
        </restriction>
    </complexContent>
    </complexType>

Currently the wsdl:arrayType="int[]" information gets lost.
When this PR is merged, you will be able to read this additional (non standard XSD) information by doing:

$meta = $attr->getMeta();
$arrayType = $meta[0]; // or rather find by name + schema targetnamespace

This will return:

^ array:1 [
  0 => GoetasWebservices\XML\XSDReader\Schema\MetaInformation^ {#1514
    -contextSchema: GoetasWebservices\XML\XSDReader\Schema\Schema^ {#554
      #targetNamespace: "http://www.w3.org/2001/XMLSchema"
      ....
    }
    -namespaceURI: "http://schemas.xmlsoap.org/wsdl/"
    -name: "arrayType"
    -value: "int[]"
  }
]

src/SchemaReader.php Outdated Show resolved Hide resolved
@@ -1088,6 +1108,19 @@ private function findType(Schema $schema, \DOMElement $node, string $typeName):
throw new TypeException(sprintf("Can't find %s named {%s}#%s, at line %d in %s ", 'type', $namespace, $name, $node->getLineNo(), $node->ownerDocument->documentURI));
}

public function findSchemaForNamespace(Schema $currentSchema, string $namespace): Schema
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There currently was no way to get a schema based on a namespace URI.
Not sure if this is the best way, but couldn't really find a different way.

@veewee veewee force-pushed the collect-meta-info branch 6 times, most recently from 77c4552 to f88e21e Compare May 31, 2024 07:04
@veewee veewee marked this pull request as draft May 31, 2024 10:31
@veewee veewee marked this pull request as ready for review May 31, 2024 12:50
@goetas
Copy link
Member

goetas commented Jun 3, 2024

I think that there are way too many possibilities here (nodes, attributes) to fit them in the "metadata", have you considered exposing the underlying DOM Node and let the consumer parse as it prefers?

Having just something as $type->getNode()?

@veewee
Copy link
Contributor Author

veewee commented Jun 3, 2024

I agree that metadata might not be the best name for the data. Maybe rather something like ExtensionAttributes.

I was trying to build code in line of what there is in the package today. However, it could make sense to introduce the link to the node so that people can collect whatever they want from the XML directly.

Let me know what you all prefer, I can take a look at creating an alternative PR for the node implementation.

@veewee
Copy link
Contributor Author

veewee commented Jun 3, 2024

Just took an additional look and found a "con" argument for the node approach: having the node only is a bit harder because of the difference between reference and definition schema items.

When it is pre-parsed, the information gets proxies instantly.

@goetas
Copy link
Member

goetas commented Jun 3, 2024

By looking at https://www.w3schools.com/xml/el_complextype.asp it seems that XMLSchema allows only attributes to be used as extensions, while nodes are reserved to XSD... that would simplify a lot things... do you anything about it?

src/SchemaReader.php Show resolved Hide resolved
src/Schema/MetaInformation.php Outdated Show resolved Hide resolved
@veewee veewee requested a review from goetas June 4, 2024 06:25
@veewee
Copy link
Contributor Author

veewee commented Jun 4, 2024

By looking at https://www.w3schools.com/xml/el_complextype.asp it seems that XMLSchema allows only attributes to be used as extensions, while nodes are reserved to XSD... that would simplify a lot things... do you anything about it?

That is correct indeed. I changed the naming to CustomAttribute - which better indicates what the information is being used for.

@goetas goetas merged commit f4bdcbb into goetas-webservices:master Jun 4, 2024
@goetas
Copy link
Member

goetas commented Jun 4, 2024

looks good, thank you

@goetas
Copy link
Member

goetas commented Jun 4, 2024

Released as https://github.com/goetas-webservices/xsd-reader/releases/tag/0.4.5

@Guite
Copy link
Collaborator

Guite commented Jun 4, 2024

Thank you @veewee

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 this pull request may close these issues.

3 participants