Forum Discussion

gerardsoley's avatar
gerardsoley
New Contributor
3 years ago

How to display a list of objects

Hi! I am doing a controller that has to receive an object. This object has a list of objects of type < ShippingAddressDTO>.
My problem is that swagger does not show the object type of the list. Even knowing the object type and introducing the fields in swagger, it arrives as null in the controller.

5 Replies

  • Hi gerardsoley 

     

    Could you expand a little on what libs you're using? I see you've mentioned Swagger Core does that mean you're using JAX-RS to annotate your code? 

    The goal is to figure out if the OpenAPI definition is missing info (aka: swagger file), in which case there might be an issue with the Annotations -> OpenAPI. Or if the OpenAPI definition is correct, then there might be an issue rendering it in SwaggerUI.

     

    SwaggerUI looks to be working with the following...

    openapi: 3.0.0
    info:
     version: 1.1.1
     title: Multipart with list of Objects in request body.
     
    paths:
      /foo:
        post:
          description: ok
          requestBody:
            content:
              multipart/formdata:
                schema:
                  type: object
                  properties:
                    one:
                      type: string
                      format: binary
                    two:
                      type: array
                      items:
                        type: object
                        properties:
                          alpha: 
                            type: string
                            example: Alpha
                          bravo:
                            type: string
                            example: Bravo
          responses:
            default:
              description: ok
    

     

     

    • gerardsoley's avatar
      gerardsoley
      New Contributor

      Hi ponelat 

      I use the following libraries for the code:

      Swashbuckle.AspNetCore.Annotations Version="5.6.3"
      Swashbuckle.AspNetCore.SwaggerGen Version="5.6.3"
      Swashbuckle.AspNetCore.SwaggerUI Version="5.6.3"

      Swashbuckle.AspNetCore.Filters Version="6.0.0"
      Microsoft.AspNetCore.Authorization;
      Microsoft.AspNetCore.Mvc;
      Microsoft.AspNetCore.Mvc.ModelBinding;

       

      We don't use swagger files. The definition is made in the controllers, not in a swagger file.

      • ponelat's avatar
        ponelat
        Staff

        Thanks for the supplied libraries.

        Those libraries will, under the hood, create and read an OpenAPI definition file (ie: Swagger file).

         

        Something like the following...

         

        In order to figure out what's going wrong, we'd need that Swagger file.

        If you can see Swagger UI, then you may be able to download the Swagger file, it can be found in the top text box and as a link under the APIs title, as shown here...

        If the API is private, it may make sense to redact or copy out only the relevant info to see what the issue is.

         

        Hope that helps! Alternatively, you can reach out to the maintainers of the Swashbuckle library (I believe this is the one: https://github.com/domaindrivendev/Swashbuckle.AspNetCore )