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

Swashbuckle Example Data Type not showing correct markup #1440

Open
kbrow20 opened this issue Jun 6, 2023 · 1 comment
Open

Swashbuckle Example Data Type not showing correct markup #1440

kbrow20 opened this issue Jun 6, 2023 · 1 comment

Comments

@kbrow20
Copy link

kbrow20 commented Jun 6, 2023

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>
@kbrow20
Copy link
Author

kbrow20 commented Jun 13, 2023

@domaindrivendev I have figured out how to set the out layer of Somes and Some. I can't figure out the correct way to set the inner class object being renamed from SomeClasses and SomeClass to Classes and Class. I am setting it in the SchemaFilter.

Public Sub Apply(schema As Schema, registry As SchemaRegistry, type As Type) Implements ISchemaFilter.Apply

I am setting the name of the XML item like:

schema.xml = New Xml With
                {
                    .name = XmlRootAttribute.ElementName
                }

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

1 participant