Open wandergeek opened 1 year ago
can you try enabling the option useOneOfDiscriminatorLookup
(e.g. via --additional-properties in CLI) ?
Thanks, @wing328! We seem to be getting somewhere now! That said, it's introduced a new issue in another part of the client. The error and offending line is:
expected operand, found ']'
json[]WeightedCompositeSourcesInner, _ := json.Marshal(dst.ArrayOfWeightedCompositeSourcesInner)
Change is below- this is the diff before and after using useOneOfDiscriminatorLookup
:
--- a/generated/slo/model_composite_slo_response_sources.go
+++ b/generated/slo/model_composite_slo_response_sources.go
@@ -27,15 +27,16 @@ func ArrayOfWeightedCompositeSourcesInnerAsCompositeSloResponseSources(v *[]Weig
}
}
+
// Unmarshal JSON data into one of the pointers in the struct
func (dst *CompositeSloResponseSources) UnmarshalJSON(data []byte) error {
var err error
match := 0
// try to unmarshal data into ArrayOfWeightedCompositeSourcesInner
- err = newStrictDecoder(data).Decode(&dst.ArrayOfWeightedCompositeSourcesInner)
+ err = json.Unmarshal(data, &dst.ArrayOfWeightedCompositeSourcesInner)
if err == nil {
- jsonArrayOfWeightedCompositeSourcesInner, _ := json.Marshal(dst.ArrayOfWeightedCompositeSourcesInner)
- if string(jsonArrayOfWeightedCompositeSourcesInner) == "{}" { // empty struct
+ json[]WeightedCompositeSourcesInner, _ := json.Marshal(dst.ArrayOfWeightedCompositeSourcesInner)
+ if string(json[]WeightedCompositeSourcesInner) == "{}" { // empty struct
dst.ArrayOfWeightedCompositeSourcesInner = nil
} else {
match++
@@ -66,7 +67,7 @@ func (src CompositeSloResponseSources) MarshalJSON() ([]byte, error) {
}
// Get the actual instance
-func (obj *CompositeSloResponseSources) GetActualInstance() interface{} {
+func (obj *CompositeSloResponseSources) GetActualInstance() (interface{}) {
if obj == nil {
return nil
}
@@ -113,3 +114,5 @@ func (v *NullableCompositeSloResponseSources) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
Relevant parts of the schema are here: https://github.com/wandergeek/busted-slo-parsing/blob/master/bundled.yaml#L816-L848.
I suspect it's confused because there's only one element in oneOf
? I think we expect this part of the API to have different types, but don't yet.
I removed the oneOf with the single element and got it all to work. Do you want me to create an issue for this or just leave it be?
Bug Report Checklist
Description
I've added a discriminator to our openAPI spec, and I can't seem to get the generated client to unmarshal the response properly.
I would expect some code in this file to check the
type
field and unmarshal it appropriately.openapi-generator version
OpenAPI declaration file content or url
https://github.com/wandergeek/busted-slo-parsing/blob/master/bundled.yaml#L1341-L1353
Generation Details
Steps to reproduce
Have I just specified this incorrectly? Any help much appreciated!