-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Issue with XML Attribute Handling for Nested Objects #317
Comments
Thank you for the report! I don't know where this bug can come from. We use the stdlib |
Hello @EwenQuim , I uploaded the example code to testapi. I used customOpenAPI and customBaseRoute in api/oapi/custom.go to overwrite fuego.OpenAPI and fuego.BaseRoute. This way I was able to insert a custome made
but it worked only in parent structure, on childs it didn't work:
results in attribute only in Health and not in MyInput and MyValue:
This is just a proof of concept to understand the extent of changes required before attempting to implement them in 'fuego'. |
Hmm, I looked into this some. The output seems correct. At least it aligns with this playground. I believed you'd need something like this to get the structure you desire. package main
import (
"encoding/xml"
"fmt"
"os"
)
type MyInput struct {
Message string `xml:",chardata"`
Name string `xml:"name,attr"`
}
type MyOutput struct {
Message myInput `json:"message" xml:"message"`
}
func main() {
x := &MyOutput{Message: myInput{Name: "Hello, Carmack"}}
enc := xml.NewEncoder(os.Stdout)
enc.Indent("", " ")
if err := enc.Encode(x); err != nil {
fmt.Printf("error: %v\n", err)
}
} output: <MyOutput>
<message name="Hello, Carmack"></message>
</MyOutput> |
The problem is not encoding to XML, but on the generated OpenAPI documentation. I think I found the problem, editing openapi.go and adding:
just after:
The XML attributes are defined as attributes in OpenAPI documentation. I will try to check other edge situations before a PR. |
OIC. You may want to base off of #319 |
@dylanhitt, I updated However, the bug persists—the XML information is still not being handled properly. Here is the current output:
I noticed that commit cfe0e19 addresses nested struct tags for JSON, but |
PR #328 provides foundational support for XML schema definitions in OpenAPI documentation, aligning with the use cases where XML-based APIs require precise schema representation. |
To Reproduce
Steps to reproduce the behavior:
Example code:
Output XML example in /user/{user} endpoint:
Here, "name" appears as a child tag instead of being an attribute.
Expected behavior
Expected output in XML (from /user/{user} endpoint):
Framework version:
github.com/go-fuego/fuego v0.17.0
Go version:
v1.23.4
Additional context
The issue seems to stem from the way the XML struct tags are being handled for nested objects. The expected behavior aligns with how the struct is defined:
Relevant schemas from the generated OpenAPI:
The generated OpenAPI does not reflect the attribute correctly in the message field.
For more details, you can refer to the attached
openapi.json
The text was updated successfully, but these errors were encountered: