frankframework / frank-doc

Frank!Doc
https://frankdoc.frankframework.org
Apache License 2.0
4 stars 5 forks source link

Refer to attributes in schema, instead of repeating their definition #116

Closed gvanbrakel closed 2 years ago

gvanbrakel commented 2 years ago

Each time a an attribute is redefined in the schemas, it is included with the full documentation. I can imagine the schemas can become a lot smaller when there would be just a referal to a globally defined attribute

mhdirkse commented 2 years ago

This is not so difficult. I see two possible approaches:

First, we can define each attrbute globally.

Second, we can keep attributes that appear only once in-place. Only attributes that are repeated are done as references. Doing this is a bit more complicated, but it is not too difficult. It can be done as follows. For each attribute that should appear in the XSDs, I instantiate an object, say of class AttributeCreator. These attributes are searched by a key that is the name of the attribute, whether it is mandatory and the documentation (nullable). When the algorithm that browses the FrankElements needs an attribute, it looks up the AttributeCreator or instantiates one. The AttributeCreator keeps a list of XmlBuilder objets to which the attribute is to be attached.

After browsing the Frank elements, DocWriterNew should iterate the list of AttributeCreator-s. Each creator that has only one attribute should result in an in-place attribute. Each creator that has multiple XmlBuilder-s results in a referenced attribute. I can take care that the referenced attributes appear after the type definitions for elements and before the simple types like frankBoolean. I can do this by keeping a list of XmlBuilder-s for them, in addition to the list of simple element type definitions and the list of reusable element type definitions.

@gvanbrakel, what approach do you prefer?

mhdirkse commented 2 years ago

I discussed this issue with @gvanbrakel in a phone call. We choose the second approach. A readable XSD is more important than having simple Java code.

mhdirkse commented 2 years ago

In theory, there can be different attributes that share the same name. It would be nice if referenced attributes could be referenced by a unique id. An <xs:attribute> can have an id attribute next to its name attribute. Alas, there is no way to reference an attribute by its id. I tried to do this in an example XSD, but I see errors in VSCode. Using a ref attribute with the id as value fails. And attribute idref is not allowed in attribute definitions.

gvanbrakel commented 2 years ago

If there are duplicate attributes, i.e. attributes that share the name of another attribute, and it is not possible to reference them by something other than the name, then we should select one of them (preferably the most referenced) to be the referenceable attribute, and define the others in-line.