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

MarshalJson is missing fields for InterfacePropertiesFormat #14263

Closed
MirzaSikander opened this issue Feb 3, 2021 · 1 comment
Closed

MarshalJson is missing fields for InterfacePropertiesFormat #14263

MirzaSikander opened this issue Feb 3, 2021 · 1 comment
Labels
Network question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@MirzaSikander
Copy link

MirzaSikander commented Feb 3, 2021

Bug Report

  • import path of package in question, e.g. .../services/compute/mgmt/2018-06-01/compute
    /Azure/azure-sdk-for-go/services/network/mgmt/2020-07-01/network/
  • SDK version e.g. master, latest, 18.1.0
    v50.1.0
  • output of go version
    go version go1.15.6 linux/amd64
  • What happened?
    Breaking change.
    In the API version 2020-07-01, InterfacePropertiesFormat and its MarshalJSON looks like this:
// InterfacePropertiesFormat networkInterface properties.
type InterfacePropertiesFormat struct {
	// VirtualMachine - READ-ONLY; The reference to a virtual machine.
	VirtualMachine *SubResource `json:"virtualMachine,omitempty"`
	// NetworkSecurityGroup - The reference to the NetworkSecurityGroup resource.
	NetworkSecurityGroup *SecurityGroup `json:"networkSecurityGroup,omitempty"`
	// PrivateEndpoint - READ-ONLY; A reference to the private endpoint to which the network interface is linked.
	PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"`
	// IPConfigurations - A list of IPConfigurations of the network interface.
	IPConfigurations *[]InterfaceIPConfiguration `json:"ipConfigurations,omitempty"`
	// TapConfigurations - READ-ONLY; A list of TapConfigurations of the network interface.
	TapConfigurations *[]InterfaceTapConfiguration `json:"tapConfigurations,omitempty"`
	// DNSSettings - The DNS settings in network interface.
	DNSSettings *InterfaceDNSSettings `json:"dnsSettings,omitempty"`
	// MacAddress - READ-ONLY; The MAC address of the network interface.
	MacAddress *string `json:"macAddress,omitempty"`
	// Primary - READ-ONLY; Whether this is a primary network interface on a virtual machine.
	Primary *bool `json:"primary,omitempty"`
	// EnableAcceleratedNetworking - If the network interface is accelerated networking enabled.
	EnableAcceleratedNetworking *bool `json:"enableAcceleratedNetworking,omitempty"`
	// EnableIPForwarding - Indicates whether IP forwarding is enabled on this network interface.
	EnableIPForwarding *bool `json:"enableIPForwarding,omitempty"`
	// HostedWorkloads - READ-ONLY; A list of references to linked BareMetal resources.
	HostedWorkloads *[]string `json:"hostedWorkloads,omitempty"`
	// DscpConfiguration - READ-ONLY; A reference to the dscp configuration to which the network interface is linked.
	DscpConfiguration *SubResource `json:"dscpConfiguration,omitempty"`
	// ResourceGUID - READ-ONLY; The resource GUID property of the network interface resource.
	ResourceGUID *string `json:"resourceGuid,omitempty"`
	// ProvisioningState - READ-ONLY; The provisioning state of the network interface resource. Possible values include: 'Succeeded', 'Updating', 'Deleting', 'Failed'
	ProvisioningState ProvisioningState `json:"provisioningState,omitempty"`
}

// MarshalJSON is the custom marshaler for InterfacePropertiesFormat.
func (ipf InterfacePropertiesFormat) MarshalJSON() ([]byte, error) {
	objectMap := make(map[string]interface{})
	if ipf.NetworkSecurityGroup != nil {
		objectMap["networkSecurityGroup"] = ipf.NetworkSecurityGroup
	}
	if ipf.IPConfigurations != nil {
		objectMap["ipConfigurations"] = ipf.IPConfigurations
	}
	if ipf.DNSSettings != nil {
		objectMap["dnsSettings"] = ipf.DNSSettings
	}
	if ipf.EnableAcceleratedNetworking != nil {
		objectMap["enableAcceleratedNetworking"] = ipf.EnableAcceleratedNetworking
	}
	if ipf.EnableIPForwarding != nil {
		objectMap["enableIPForwarding"] = ipf.EnableIPForwarding
	}
	return json.Marshal(objectMap)
}

https://raw.githubusercontent.com/Azure/azure-sdk-for-go/master/services/network/mgmt/2020-07-01/network/models.go

If you look at an older API version such as 2019-06-01, you will notice that the MarshalJSON for InterfacePropertiesFormat has a lot more fields that are being marshalled.

// MarshalJSON is the custom marshaler for InterfacePropertiesFormat.
func (ipf InterfacePropertiesFormat) MarshalJSON() ([]byte, error) {
	objectMap := make(map[string]interface{})
	if ipf.NetworkSecurityGroup != nil {
		objectMap["networkSecurityGroup"] = ipf.NetworkSecurityGroup
	}
	if ipf.IPConfigurations != nil {
		objectMap["ipConfigurations"] = ipf.IPConfigurations
	}
	if ipf.TapConfigurations != nil {
		objectMap["tapConfigurations"] = ipf.TapConfigurations
	}
	if ipf.DNSSettings != nil {
		objectMap["dnsSettings"] = ipf.DNSSettings
	}
	if ipf.MacAddress != nil {
		objectMap["macAddress"] = ipf.MacAddress
	}
	if ipf.Primary != nil {
		objectMap["primary"] = ipf.Primary
	}
	if ipf.EnableAcceleratedNetworking != nil {
		objectMap["enableAcceleratedNetworking"] = ipf.EnableAcceleratedNetworking
	}
	if ipf.EnableIPForwarding != nil {
		objectMap["enableIPForwarding"] = ipf.EnableIPForwarding
	}
	if ipf.ResourceGUID != nil {
		objectMap["resourceGuid"] = ipf.ResourceGUID
	}
	if ipf.ProvisioningState != nil {
		objectMap["provisioningState"] = ipf.ProvisioningState
	}
	return json.Marshal(objectMap)
}

https://raw.githubusercontent.com/Azure/azure-sdk-for-go/master/services/network/mgmt/2019-06-01/network/models.go

Is this by design?

@ghost ghost added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Feb 3, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Feb 3, 2021
@ArcturusZhang ArcturusZhang added the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Feb 3, 2021
@ArcturusZhang
Copy link
Member

Hi @MirzaSikander thanks for this issue.

Unfortunately I have to say this is by design. Internally the SDK relies on the marshalling functionality to transform a go SDK struct into the JSON body in a REST API request in which we cannot have the readOnly properties. Therefore you might notice those missing parts in the marshaller all correspond to a read only property (you could find the read only note in the comment of that property).

We have received an issue discussing about this problem which is more general, and we are planning to do something to improve this, please stay tuned.
In the meantime, I will close this issue in favor of #12227

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Network question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

2 participants