OpenAPITools / OpenAPITools/openapi-generator
[BUG] [GOLANG] XML support not fully implemented
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generated golang structs do not have required XML tags to marshal/unmarshal correctly. For the given OpenAPI spec below the follow structs are generated:
...
// Document struct for Document
type Document struct {
Name string `json:"name"`
Item DocumentItem `json:"item"`
}
...
// DocumentItem struct for DocumentItem
type DocumentItem struct {
Type string `json:"type"`
Value string `json:"value"`
}
...
Which have no XML tags at all. So the features detailed here https://swagger.io/docs/specification/data-models/representing-xml/ don't work.
The expected generated code looks something like:
...
// Document struct for Document
type Document struct {
XMLName xml.Name `xml:"document"`
Name string `json:"name" xml:"name"`
Item DocumentItem `json:"item" xml:"item"`
}
...
// DocumentItem struct for DocumentItem
type DocumentItem struct {
Type string `json:"type" xml:"type,attr"`
Value string `json:"value" xml:"value"`
}
...
openapi-generator version
5.3.0
OpenAPI declaration file content or URL
openapi: 3.0.3
info:
version: 1.0.0
title: test-api
paths:
/foo:
get:
responses:
200:
description: OK
content:
application/xml:
schema:
$ref: "#/components/schemas/document"
components:
schemas:
document:
type: object
required:
- name
- item
properties:
name:
type: string
item:
type: object
required:
- type
- value
properties:
type:
type: string
xml:
attribute: true
value:
type: string
Generation Details
Steps to reproduce
openapi-generator generate -i testapi.yaml -g go
Related issues/PRs
Suggest a fix
Add appropriate xml tags when generating structs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running openapi-generator generate -i testapi.yaml -g go with the OpenAPI declaration in the issue and inspect the generated Document and DocumentItem structs. Trace the Go generator's model and XML handling from that output, then verify that generated structs include the expected XMLName, element, and attribute tags and marshal/unmarshal correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100