Skip to content

Swashbuckle Example Data Type not showing correct markup #1440

@kbrow20

Description

@kbrow20

I am trying to get my SwashBuckle/Swagger GUI to show the correct elements based on how I set it in code. Currently the example output looks like this:

    <?xml version="1.0"?>
    <SomesModel>
     <_Somes>
       <_SomeID>string</_SomeID>
       <_SomeName>string</_SomeName>
       <_SomeBool>true</_SomeBool>
       <_SomeClassesModel>
            <_SomeClasses>
                 <_SomeValue>0</_SomeValue>
             </_SomeClasses>
       </_SomeClassesModel>
     </_Somes>
    </SomesModel>

My current code structure looks like this:

WepApiConfig

    config.Formatters.XmlFormatter.UseXmlSerializer = True
    SwaggerConfig.Register(config)

Controller code

    <HttpPost>
    Public Function PostGeneric(some As SomesModel) As HttpResponseMessage
        Return New HttpResponseMessage(Net.HttpStatusCode.Accepted)
    End Function

Root XML object

    <Serializable()>
    <XmlRoot(ElementName:="Somes", [Namespace]:="")>
    <XmlType("Somes")>
    Public Class SomesModel
     <XmlElement(ElementName:="Some")>
     Public Property Somes As List(Of SomeModel)
    End Class

Sub XML Object

   <Serializable()>
   <XmlType("Some")>
   Public Class SomeModel
     <XmlElement>
     Public Property SomeID As String
     <XmlElement>
     Public Property SomeName As String
     <XmlElement>
     Public Property SomeBool As Boolean
     <XmlElement(ElementName:="Classes")>
     Public Property SomeClasses As New SomeClassesModel
   End Class

Sub XML Classes Object

    <Serializable()>
    <XmlType("Classes")>
    Public Class SomeClassesModel
     <XmlElement(ElementName:="Class")>
     Public Property SomeClasses As List(Of ClassModel)
    End Class

Sub XML Class Object

   <Serializable()>
   <XmlType("Class")>
   Public Class ClassModel
     <XmlElement>
     Public Property SomeValue As Integer
   End Class

I specify all the annotations that I normally do when serializing a xml.
What extra settings does SwashBuckle need to get the xml serialized correctly?

I have tried editing the xml annotations, but it seems like Swashbuckle just ignores them. Some stack overflow suggestions was to try XMLType and others suggested using XMLRoot and XmlElements. I have tried all combinations of those.

What I would expect it to look like is this as the output.

    <?xml version="1.0"?>
    <Somes>
      <_Some>
        <_SomeID>string</_SomeID>
        <_SomeName>string</_SomeName>
        <_SomeBool>true</_SomeBool>
        <Classes>
             <Class>
                  <_SomeValue>0</_SomeValue> 
             </Class>
       </Classes>
      </_Some>
    </Somes>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions