xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate structs in namespaces.

simenandre opened this issue Β· comments

Description

Hello πŸ‘‹
First of all, thank you for this library!

I'm new to XSD files. I'm having issues using xgen to generate for NORID's EPP .xsd files.

They are available here:
https://teknisk.norid.no/en/registrar/system/dokumentasjon/epp-grensesnitt/

The issue I'm having is that the structs have the same name (being already defined).
I can see there is a targetNamespace and other schema data that probably could fix this?

Or, maybe I'm doing something wrong?

Steps to reproduce the issue:

  1. Run xgen on EPP-XML-Schemas v1.0.2

Describe the results you received:

E.g.

// File: contact-1.0.xsd.go
type CreateType struct {
	XMLName    xml.Name          `xml:"createType"`
	...
	Email      string            `xml:"email"`
	AuthInfo   *AuthInfoType     `xml:"authInfo"`
	Disclose   *DiscloseType     `xml:"disclose"`
}
// File: domain-1.0.xsd.go
type CreateType struct {
	XMLName    xml.Name       `xml:"createType"`
	...
	Registrant string         `xml:"registrant"`
	Contact    []*ContactType `xml:"contact"`
	AuthInfo   *AuthInfoType  `xml:"authInfo"`
}

Describe the results you expected:

Maybe something like this:

// File: contact-1.0.xsd.go
type ContactCreateType struct {
	XMLName    xml.Name          `xml:"createType"`
	...
	Email      string            `xml:"email"`
	AuthInfo   *AuthInfoType     `xml:"authInfo"`
	Disclose   *DiscloseType     `xml:"disclose"`
}
// File: domain-1.0.xsd.go
type DomainCreateType struct {
	XMLName    xml.Name       `xml:"createType"`
	...
	Registrant string         `xml:"registrant"`
	Contact    []*ContactType `xml:"contact"`
	AuthInfo   *AuthInfoType  `xml:"authInfo"`
}

Output of go version:

go version go1.14.5 darwin/amd64

Environment details (OS, physical, etc.):

Mac OSX 10.15.6

Prefixing each type name with the namespace is nice. I'd also like the option of having one go package generated per namespace, with a targetNamespace constant defined in the package. Currently if I set the package name via the '-p' option and generate Go code, it only sets the package name for the go source file that corresponds to the named file. Additional schema files that have been xsd:import'ed still use the default package name 'schema'.