Skip to content

provision made to add Xml namespace in swagger from Data Contract att…#218

Open
kapiljxanthus wants to merge 1 commit intoabelsilva:masterfrom
kapiljxanthus:fix-xml-namespace-from-datacontract
Open

provision made to add Xml namespace in swagger from Data Contract att…#218
kapiljxanthus wants to merge 1 commit intoabelsilva:masterfrom
kapiljxanthus:fix-xml-namespace-from-datacontract

Conversation

@kapiljxanthus
Copy link

Problem:

In scenarios where API Request object in HTTP body needs to have a namespace defined in its data contract ,
the swagger example does not have the namespace included as an attribute, So we need to manually add the namespace every time to make an actual request.

Solution:

For the definition types in swagger json generated,
We can add the xml root property with namespace sub property.

"Request": {
			"properties": {
				"Someproperty": {
					"type": "string",
					"uniqueItems": false
				}
			},
			"xml": {
				"namespace": "http://www.comanyname.com/entity"
			},//Newly added
			"type": "object",
			"format": "Request"
		}		

This namespace will be read from the DataContract attribute Namespace property in C#

namespace App.Contracts
{
    [SwaggerWcfDefinition(ModelName = "Request")]
    [Serializable]
    [DataContract(Name = "Request", Namespace = "http://www.comanyname.com/entity")]
    public class Request
    {
        [DataMember]
        public string Someproperty
        {
            get;
            set;
        }

In swagger UI, the example for API will now include the namespace like below which also gets copied on click, so no need to edit the namespace manually.

<?xml version="1.0"?>
<Request xmlns="http://www.comanyname.com/entity">
  <Someproperty>string</Someproperty>

Testing: I verified the ouput in swagger UI after making the changes done above.

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

Successfully merging this pull request may close these issues.

1 participant