-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Example for object does not work #209
Comments
The intention behind // should contain inline object example
@OpenApiExample(objects = {
@OpenApiExampleProperty(name = "name", value = "Margot Robbie"),
@OpenApiExampleProperty(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
})
public @NotNull Object getInlinedExampleObject() {
return new String[] { timestamp };
} results in: "inlinedExampleObject" : {
"type" : "object",
"example" : {
"name" : "Margot Robbie",
"link" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
} And this: // should contain object example
@OpenApiExample(objects = {
@OpenApiExampleProperty(name = "Barbie", objects = {
@OpenApiExampleProperty(name = "name", value = "Margot Robbie"),
@OpenApiExampleProperty(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
}),
})
public @NotNull Object[] getExampleObjects() {
return new String[] { timestamp };
} results in: "exampleObjects" : {
"type" : "array",
"items" : {
"type" : "object"
},
"example" : {
"Barbie" : {
"name" : "Margot Robbie",
"link" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
}
}, If we know the type tho, such as your Lines 383 to 397 in 0d81c03
So in the referenced object: "foos" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/Foo"
}
}, we can see these dedicated examples: "Foo" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"property" : {
"type" : "string"
},
"link" : {
"type" : "string",
"example" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
}
}, As far as I understand, you'd like to achieve a similar result by enforcing
|
I've updated the example to cover this with cases we were talking about: Lines 343 to 370 in c86e9dc
That returns: "exampleFoo" : {
"$ref" : "#/components/schemas/Foo",
"example" : {
"name" : "Margot Robbie",
"link" : "Dedicated link"
}
},
"exampleObject" : {
"type" : "object",
"example" : {
"name" : "Margot Robbie",
"link" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
},
"exampleObjects" : {
"type" : "array",
"items" : {
"type" : "object"
},
"example" : {
"Barbie" : {
"name" : "Margot Robbie",
"link" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
}
}, and unaffected example (as expected) in the Foo scheme: "Foo" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"link" : {
"type" : "string",
"example" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
}
}, If I missed the point, just let me know. |
It is clear. Thank you for adding additional test, and explaining about the issues. |
Actual behavior (the bug)
With such configuration, at the end I do not see my examples in the OpenAPI specification
Specification which is generated is
Expected behavior
I would expect, that example should be injected to the openapi description like
So specification code generated should be more like
Additional context
Currently, when I change type to Barbie[] (the same as we have in existing example Object[]), then it is properly injected example, but it requires to change specification, what it not acceptable.
The text was updated successfully, but these errors were encountered: