uranusjr commented on code in PR #75737:
URL: https://github.com/apache/airflow/pull/75737#discussion_r4507975734


##########
go-sdk/pkg/execution/genmodels/gen/main.go:
##########
@@ -354,9 +365,210 @@ func identUseCounts(file *ast.File) map[string]int {
        return counts
 }
 
+// timeTypeName is the hand-written UTC-decoding type in the genmodels package.
+const timeTypeName = "Time"
+
+func (p schemaProp) isDateTime() bool { return p.Format == "date-time" }
+
+func (p schemaProp) isNull() bool { return p.Type == "null" }
+
+// hasDateTime reports whether p carries a date-time anywhere, so a shape
+// findNullableDateTimes does not recognise fails generation instead of being 
skipped.
+func (p schemaProp) hasDateTime() bool {
+       if p.isDateTime() || (p.Items != nil && p.Items.hasDateTime()) {
+               return true
+       }
+       for _, branch := range p.AnyOf {
+               if branch.hasDateTime() {
+                       return true
+               }
+       }
+       return false
+}
+
+// nonNullBranch returns X for an anyOf [X, null] prop.
+func (p schemaProp) nonNullBranch() (schemaProp, bool) {
+       if len(p.AnyOf) != 2 {
+               return schemaProp{}, false
+       }
+       value, null := p.AnyOf[0], p.AnyOf[1]
+       if value.isNull() {
+               value, null = null, value
+       }
+       return value, null.isNull()
+}
+
+// findNullableDateTimes returns structName -> wire tag for every
+// anyOf [date-time, null] prop. go-jsonschema renders those as interface{},
+// which the AST cannot tell apart from other nullable scalars; every other
+// date-time it renders as time.Time, which retypeDateTimes swaps by type 
alone.
+func findNullableDateTimes(
+       doc *schemaDoc,
+       structByKey map[string]string,
+) (map[string]map[string]bool, error) {
+       set := map[string]map[string]bool{}
+       for defName, def := range doc.Defs {
+               structName, ok := structByKey[strings.ToUpper(defName)]
+               if !ok {
+                       continue
+               }
+               for propName, prop := range def.Properties {
+                       if !prop.hasDateTime() {
+                               continue
+                       }
+                       value, nullable := prop.nonNullBranch()
+                       switch {
+                       case prop.isDateTime(), nullable && value.Items != nil 
&& value.Items.isDateTime():
+                               continue
+                       case nullable && value.isDateTime():
+                               if set[structName] == nil {
+                                       set[structName] = map[string]bool{}
+                               }
+                               set[structName][propName] = true
+                       default:
+                               return nil, fmt.Errorf(
+                                       "%s.%s: unsupported date-time schema 
shape",
+                                       defName,
+                                       propName,
+                               )
+                       }

Review Comment:
   A non-nullable array of date-times falls through to default, but 
`retypeDateTimes` handles `[]time.Time`. I think it should be allowed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to