-
Notifications
You must be signed in to change notification settings - Fork 37
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
Problems with generating enumLeafs #67
Comments
See this: This is where the |
I checked a couple of .xsd files containing enums and everything seems to work as I expected. Thanks a lot! |
Hi, unfortunately this does not solve the problem completely yet. This works for strings but other types won't work well. We need Java-side conversion between lexical and JSON representation to render enum values correctly. Best wishes, |
Hi there, I am running into a bit of an issue with this myself. I am able to get the enum values to show up in the mapping.js file, but not in the jsonschema file. Here is what I am seeing in the mapping file: {
type: 'enumInfo',
localName: 'ClassEnum',
baseTypeInfo: 'NormalizedString', //I have tried "string" as well
values: ['standard', 'steps', 'example']
} And here is the jsonschema file: "ClassEnum":{
"allOf":[
{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/normalizedString"
}
],
"typeType":"enumInfo",
"typeName":{
"localPart":"classEnum",
"namespaceURI":"http://blahblahblah"
}
} It would be awesome if the schema could have the "enum" property as well: "ClassEnum":{
"allOf":[
{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/normalizedString"
}
],
"typeType":"enumInfo",
"typeName":{
"localPart":"classEnum",
"namespaceURI":"http://blahblahblah"
},
"enum": ["standard", "steps", "example"] //this would be the same format as "values" in the mapping except with double quotes
} Is this something that can be done easily? I could take a stab at a PR if you can point me in the right direction. Thanks, |
It's not quite easy but doable. Currently, the compiler just associates XML Schema types with names of Jsonix type. That's a simple mapping. What we need to do is to replace string names with something more intelligent, something like "type descriptor". Type descriptor should be able to parse lexical representations of types and convert then in JSON structures which could then used in mappings and JSON schemas. You can help by providing sample enumerated simple types for all the simple types for test: Next, I'll implement type descriptors for a few type and you could help by implementing further type descriptors. Essentially, we have to cover all of the supported types (from |
Thank you for the quick response! I will create a PR with the enum type additions to the sample XSD, but I just want to clarify what you are asking. If I understand correctly, you want me to create a simpleType with a restriction for each of the ~40 simple types? So I would basically stamp out a bunch of these with different base types and values: <xs:element name="enum" type="enumType"/>
<xs:simpleType name="enumType">
<xs:restriction base="xs:token">
<xs:enumeration value="Male"/>
<xs:enumeration value="Female"/>
</xs:restriction>
</xs:simpleType> If that is correct then I can start right away, I was just concerned about the file size blowing up. |
Right, that would help. Please name them |
Absolutely, I'll have that done shortly. |
Sorry about the duplicate commit, I didn't have my repo configured correctly and it used my work user by mistake. The second one is correct and the corresponding PR is #70. |
#67 added enumerable types for all built-in types
Thanks a lot! |
No problem, let me know if there is anything else I can do. |
Seems like we can only support:
|
I've started the work. It seems like can only generate enum types for a small subset of base types (listed above). This means that if you have an enumeration of dates, this won't be an "enum" type. But it's still possible to analyze the schema and extract the possible lexical values. Could you please tell me about your use case a little bit more? This would help to get the right design. How would you use enum values? |
Sure, we currently have two use cases for enums and they are very similar. Our XSD defines the structure of our web content, and we use a templating engine to parse the XML and generate very basic HTML. The HTML contains hooks like dataset attributes and CSS classes based on certain fields in the XML. In one case, we have a field that defines one of three CSS classes (shown in my first comment above) that is applied to a text blob, and in the other case it is a dataset attribute on a div that defines the layout of a pseudo-table. Our legacy content management system can read the XSDs and XMLs and generate HTML forms on the fly so that our content entry teams do not have to write any code. We are in the process of replacing that CMS with our own in-house system and we are using JSONIX to convert the XSDs to JSON Schema, and using Angular Schema Form to generate the HTML forms on the fly. We have had to do some minor alterations to the JSON Schema output because of the way that ASF reads the schemas (it doesn't handle "allOf", "anyOf" or "oneOf", and it does not follow "ref"s) but it does have the ability to read the "enum" property which results in either a HTML select, radio buttons, or checkboxes depending on some settings. I was actually able to pull the "values" array out of the mapping.js file and attach it as an "enum" property in the schema after the schema generation, but I think it would be really helpful if JSONIX would do it while it parsed the XSD. |
Hi @benmarch, could you please give it a try? It's not 100% done yet, but I have to wrap up for today. Enum generation in mappings is complete. In JSON schema it generates
For:
I'd appreciate your feedback before finalizing this. |
Hey @highsource, I think that sounds good, but I would like to test it on my schema if possible. I just tried building the jar but there appears to be a compilation error in master:
Maybe something wasn't checked in? Please let me know if there is a way I can test your changes. Thanks, |
Sorry, missed a few files. Should be in right now. |
Hey @highsource, it is working perfectly for me. I am able to generate an enum of strings, and it appears in the correct place in the JSON Schema. Thank you!! |
Hey @highsource, any news on when this might be released? |
Coming this week. There's one small problem to be solved with hierarchican |
I've decided to leave hierarchical |
Thanks, @highsource! Works perfectly for me in 2.3.9. |
I'm using this schema file
`
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://foo.bar.EnumLeafSchema"
targetNamespace="http://foo.bar.EnumLeafSchema"
elementFormDefault="qualified">
<xsd:element name="UsesEnumLeaf">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="personTitle" type="PersonTitleCodesEnumeration"></xsd:element>
<xsd:element name="personName" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="PersonTitleCodesEnumeration">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="mr" />
<xsd:enumeration value="ms" />
<xsd:enumeration value="mrs" />
<xsd:enumeration value="miss" />
<xsd:enumeration value="dr" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
`
This is generated by the compiler:
But I expected:
Is this a bug? My failure?
Kind regards,
Tom
The text was updated successfully, but these errors were encountered: