Skip to content
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

Maintain original keys/fields ordering #2456

Open
bangbaew opened this issue Dec 18, 2023 · 1 comment
Open

Maintain original keys/fields ordering #2456

bangbaew opened this issue Dec 18, 2023 · 1 comment

Comments

@bangbaew
Copy link

I'm trying to convert ISO20022 schemas to C#, Go and Rust code, which ordering of fields is important, but the code generator seems to generate the fields in alphabetical order, it should be in the original order.

This is a portion of my schema:

"GroupHeader32": {
      "type": "object",
      "properties": {
        "MsgId": {
          "$ref": "#/definitions/Max35Text"
        },
        "CreDtTm": {
          "$ref": "#/definitions/ISODateTime"
        },
        "Authstn": {
          "maxItems": 2,
          "type": "array",
          "items": {
            "$ref": "#/definitions/Authorisation1Choice"
          }
        },
        "NbOfTxs": {
          "$ref": "#/definitions/Max15NumericText"
        },
        "CtrlSum": {
          "$ref": "#/definitions/DecimalNumber"
        },
        "InitgPty": {
          "$ref": "#/definitions/PartyIdentification32"
        },
        "FwdgAgt": {
          "$ref": "#/definitions/BranchAndFinancialInstitutionIdentification4"
        }
      },
      "required": ["MsgId", "CreDtTm", "NbOfTxs", "InitgPty"],
      "additionalProperties": false
    },

This is the generated C# code:

public partial class GroupHeader32
    {
        public Authorisation1Choice[] Authstn { get; set; }
        public DateTimeOffset CreDtTm { get; set; }
        public double? CtrlSum { get; set; }
        public BranchAndFinancialInstitutionIdentification4 FwdgAgt { get; set; }
        public PartyIdentification32 InitgPty { get; set; }
        public string MsgId { get; set; }
        public string NbOfTxs { get; set; }
    }

This is the generated Go code:

type GroupHeader32 struct {
	Authstn  []Authorisation1Choice                        `json:"Authstn,omitempty"`
	CreDtTm  string                                        `json:"CreDtTm"`
	CtrlSum  *float64                                      `json:"CtrlSum,omitempty"`
	FwdgAgt  *BranchAndFinancialInstitutionIdentification4 `json:"FwdgAgt,omitempty"`
	InitgPty PartyIdentification32                         `json:"InitgPty"`
	MsgID    string                                        `json:"MsgId"`
	NbOfTxs  string                                        `json:"NbOfTxs"`
}

This is the generated Rust code:

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GroupHeader32 {
    authstn: Option<Vec<Authorisation1Choice>>,
    cre_dt_tm: String,
    ctrl_sum: Option<f64>,
    fwdg_agt: Option<BranchAndFinancialInstitutionIdentification4>,
    initg_pty: PartyIdentification32,
    msg_id: String,
    nb_of_txs: String,
}

Is there any option to maintain the properties in original order?

@sschuberth
Copy link

Looks like this duplicates #898 / #336.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants