-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add baleen xsd generator. #5
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I have a couple of comments and suggestions
minInclusive = MinInclusive(baleenType.min.toBigDecimal())) | ||
)) | ||
is OccurrencesType -> defaultTypeMapper(baleenType.memberType).copy(maxOccurs = "unbounded") | ||
is StringCoercibleToType<*> -> defaultTypeMapper(baleenType.type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at #6 , I created a abstract class CoercibleType that can help going to any types of Coercibles,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change the code when #6 is merged.
/** | ||
* Creates an XSD from a data description. | ||
*/ | ||
fun encode(dataDescription: DataDescription, outputStream: PrintStream, typeMapper: TypeMapper = ::defaultTypeMapper) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #6 , I did some encodeTo infix
patterns as a proposal. The call could look like this:
import com.shoprunner.baleen.xsd.XsdGenerator.encodeTo
// snip
dataDescription.encodeTo(File('file.xsd'))
is DataDescription -> TypeDetails(baleenType.name) | ||
is FloatType -> TypeDetails(simpleType = SimpleType( | ||
Restriction( | ||
base="xs:double", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Floats and doubles are the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it does look like xsd has both: http://infohost.nmt.edu/tcc/help/pubs/rnc/xsd.html
)) | ||
is LongType -> TypeDetails(simpleType = SimpleType( | ||
Restriction( | ||
base="xs:int", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long and Int are the same?
maxLength = MaxLength(baleenType.max), | ||
minLength = MinLength(baleenType.min)) | ||
)) | ||
else -> throw Exception("Unknown type: ${baleenType.name()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to handle timestamp information in the XSD?
interesting and inspiring work. So xsd can only handle a subset of the defined constraints, right? My understanding is, baleen is able to handle constraints on other elements based on the values of certain elements. But xsd won't be able to, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments. Can you add a README for this generator?
You haven't implemented all supported types. Can you list the missing ones in the README so others know what is and isn't supported? (Call to action for other commiters might be good as well)
maxLength = MaxLength(baleenType.max), | ||
minLength = MinLength(baleenType.min)) | ||
)) | ||
is TimestampMillisType -> TypeDetails("xs:dateTime") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might also want to map InstantType
is AllowsNull<*> -> defaultTypeMapper(baleenType.type) | ||
is BooleanType -> TypeDetails("xs:boolean") | ||
is DataDescription -> TypeDetails(baleenType.name) | ||
is FloatType -> TypeDetails(simpleType = SimpleType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does XSD have doubles?
minLength = MinLength(baleenType.min)) | ||
)) | ||
is TimestampMillisType -> TypeDetails("xs:dateTime") | ||
else -> throw Exception("Unknown type: ${baleenType.name()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Unknown type" is a bit misleading since we do know the type. Perhaps "Unsupported type" or "unable to map baleen type to XSD"
@dlisr you are correct, the generated xsd will not capture all the constraints but can still be using 3rd party tools that do code generation or validation from xsd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you for the README.
} | ||
``` | ||
|
||
### To Generate a XSD with Custom Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to allow custom types overrides!
…jupiter-junit-jupiter-api-5.4.2 Bump junit-jupiter-api from 5.0.2 to 5.4.2
Adds generation of XSD schemas from Baleen schema.