Skip to content

Commit

Permalink
improve object and array parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Dec 28, 2024
1 parent 908d17e commit 1d36cad
Show file tree
Hide file tree
Showing 8 changed files with 1,566 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ndc-http-schema/openapi/internal/oas3_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (oc *oas3SchemaBuilder) buildUnionSchemaType(baseSchema *base.Schema, schem
}, nil
}

if len(oasTypes) == 1 && baseSchema.Type[0] == "object" {
if len(oasTypes) == 1 && (baseSchema.Type[0] == "object" || (baseSchema.Properties != nil && baseSchema.Properties.Len() > 0)) {
schemaResult, err := oc.evalObjectType(baseSchema, fieldPaths)
if err != nil {
return nil, err
Expand Down
11 changes: 5 additions & 6 deletions ndc-http-schema/openapi/internal/oas_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ func evalSchemaProxiesSlice(schemaProxies []*base.SchemaProxy, location rest.Par
continue
}
sc := proxy.Schema()
if sc == nil || (len(sc.Type) == 0 && len(sc.AllOf) == 0 && len(sc.AnyOf) == 0 && len(sc.OneOf) == 0) {
if sc == nil || (len(sc.Type) == 0 && len(sc.AllOf) == 0 && len(sc.AnyOf) == 0 && len(sc.OneOf) == 0 &&
(sc.Properties == nil || sc.Properties.Len() == 0) &&
(sc.Items == nil || sc.Items.A != nil)) {
continue
}

Expand All @@ -332,13 +334,10 @@ func evalSchemaProxiesSlice(schemaProxies []*base.SchemaProxy, location rest.Par
}

results = append(results, proxy)
if len(sc.Type) == 0 {
typeNames = append(typeNames, "any")
} else if !slices.Contains(typeNames, sc.Type[0]) {
typeNames = append(typeNames, sc.Type[0])
}
typeNames = append(typeNames, sc.Type...)
}

typeNames = utils.SliceUnique(typeNames)
if len(typeNames) == 1 && len(results) > 1 && typeNames[0] == "string" {
// if the anyOf array contains both string and enum
// we can cast them to string
Expand Down
312 changes: 310 additions & 2 deletions ndc-http-schema/openapi/testdata/onesignal/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@
"type": {
"type": "nullable",
"underlying_type": {
"name": "DeliveryData",
"name": "PlatformDeliveryDataEmail",
"type": "named"
}
},
Expand Down Expand Up @@ -1281,7 +1281,7 @@
"type": {
"type": "nullable",
"underlying_type": {
"name": "DeliveryData",
"name": "PlatformDeliveryDataSms",
"type": "named"
}
},
Expand All @@ -1293,6 +1293,314 @@
}
}
},
"PlatformDeliveryDataEmail": {
"fields": {
"bounced": {
"description": "Number of recipients who registered as a hard or soft bounce and didn't receive your email.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"clicks": {
"description": "Number of clicked links from your email. This can include the recipient clicking email links multiple times.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"converted": {
"description": "Number of messages that were clicked.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"errored": {
"description": "Number of errors reported.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"failed": {
"description": "Number of messages sent to unsubscribed devices.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"opened": {
"description": "Number of times an email has been opened.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"received": {
"description": "Number of devices that received the message.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"reported_spam": {
"description": "Number of recipients who reported this email as spam.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"successful": {
"description": "Number of messages delivered to push servers, mobile carriers, or email service providers.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"unique_clicks": {
"description": "Number of unique clicks that your recipients have made on links from your email.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"unique_opens": {
"description": "Number of unique recipients who have opened your email.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"unsubscribed": {
"description": "Number of recipients who opted out of your emails using the unsubscribe link in this email.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
}
}
},
"PlatformDeliveryDataSms": {
"fields": {
"converted": {
"description": "Number of messages that were clicked.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"errored": {
"description": "Number of errors reported.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"failed": {
"description": "Number of messages sent to unsubscribed devices.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"provider_errored": {
"description": "Number of errors reported by the SMS service provider.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"provider_failed": {
"description": "Number of recipients who didn't receive your message as reported by the SMS service provider.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"provider_successful": {
"description": "Number of messages reported as delivered successfully by the SMS service provider.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"received": {
"description": "Number of devices that received the message.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
},
"successful": {
"description": "Number of messages delivered to push servers, mobile carriers, or email service providers.",
"type": {
"type": "nullable",
"underlying_type": {
"name": "Int32",
"type": "named"
}
},
"http": {
"type": [
"integer"
]
}
}
}
},
"StringMap": {
"fields": {
"en": {
Expand Down
Loading

0 comments on commit 1d36cad

Please sign in to comment.