-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(avro-schema): logical type support #19607
feat(avro-schema): logical type support #19607
Conversation
@@ -0,0 +1 @@ | |||
{{#useLogicalTypes}}{{#isDate}}{ "type": "int", "logicalType": "date" }{{/isDate}}{{#isDateTime}}{ "type": "long", "logicalType": "timestamp-{{{logicalTypeTimeQuantifier}}}" }{{/isDateTime}}{{^isDate}}{{^isDateTime}}"{{{dataType}}}"{{/isDateTime}}{{/isDate}}{{/useLogicalTypes}}{{^useLogicalTypes}}"{{{dataType}}}"{{/useLogicalTypes}} |
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.
would be great to format this better; if there is a way to use whitespace in the template and then make it collapse in the result, please let me know.
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.
are you looking for something like following?
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Javascript/libraries/javascript/api.mustache#L3
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Javascript/libraries/javascript/api.mustache#L118
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.
no, that's changing the template operator, right? I basically wish I could change the string in this template to:
{{#useLogicalTypes}}{{#isDate}}{ "type": "int", "logicalType": "date" }{{/isDate}}{{#isDateTime}}{ "type": "long", "logicalType": "timestamp-{{{logicalTypeTimeQuantifier}}}" }{{/isDateTime}}{{^isDate}}{{^isDateTime}}"{{{dataType}}}"{{/isDateTime}}{{/isDate}}{{/useLogicalTypes}}{{^useLogicalTypes}}"{{{dataType}}}"{{/useLogicalTypes}} | |
{{#useLogicalTypes}} | |
{{#isDate}} | |
{ | |
"type": "int", | |
"logicalType": "date" | |
} | |
{{/isDate}} | |
{{#isDateTime}} | |
{ | |
"type": "long", | |
"logicalType": "timestamp-{{{logicalTypeTimeQuantifier}}}" | |
} | |
{{/isDateTime}} | |
{{^isDate}} | |
{{^isDateTime}} | |
"{{{dataType}}}" | |
{{/isDateTime}} | |
{{/isDate}} | |
{{/useLogicalTypes}} | |
{{^useLogicalTypes}} | |
"{{{dataType}}}" | |
{{/useLogicalTypes}} |
and still have well-spaced output in the resulting schema. Something like a {{#collapseWhitespace}}...{{/collapseWhitespace}}
operator that takes anything in its body and reduces all \w+
to
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.
nope. i don't think mustache comes with anything to do that
looks like avsc file are just JSON file so users can use a linter to auto format the auto-generated output as they do with other generators
This implements logical type support for:
timestamp
date
for the OpenAPI built-in
string
formats:date-time
date
The change is backwards compatible by allowing to opt-in to the behaviour via a new property
useLogicalTypes
.Avro's support for
timestamp
fields includes the definition which timescale they are represented in (milliseconds, microseconds or nanoseconds). This can be controlled via a new propertylogicalTypeTimeQuantifier
.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.There is no committee for this one, as it's a schema transformer, thus: @sgadouar or @wing328 please?