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

Add baleen xsd generator. #5

Merged
merged 4 commits into from
Jun 21, 2018
Merged

Add baleen xsd generator. #5

merged 4 commits into from
Jun 21, 2018

Conversation

HawaiianSpork
Copy link
Contributor

Adds generation of XSD schemas from Baleen schema.

@HawaiianSpork HawaiianSpork requested a review from a team June 20, 2018 14:50
Copy link
Contributor

@kdallmeyer-sr kdallmeyer-sr left a 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)
Copy link
Contributor

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,

Copy link
Contributor Author

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) {
Copy link
Contributor

@kdallmeyer-sr kdallmeyer-sr Jun 20, 2018

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",
Copy link
Contributor

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?

Copy link
Contributor Author

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",
Copy link
Contributor

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()}")
Copy link
Contributor

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?

@dlisr
Copy link

dlisr commented Jun 20, 2018

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?

Copy link
Contributor

@kdallmeyer-sr kdallmeyer-sr left a 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")
Copy link
Contributor

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(
Copy link
Contributor

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()}")
Copy link
Contributor

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"

@HawaiianSpork
Copy link
Contributor Author

@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.

Copy link
Contributor

@kdallmeyer-sr kdallmeyer-sr left a 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
Copy link
Contributor

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!

@HawaiianSpork HawaiianSpork merged commit ed7fb97 into master Jun 21, 2018
@HawaiianSpork HawaiianSpork deleted the xsd branch June 21, 2018 04:05
HawaiianSpork added a commit that referenced this pull request May 27, 2019
…jupiter-junit-jupiter-api-5.4.2

Bump junit-jupiter-api from 5.0.2 to 5.4.2
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