feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
226 stars 63 forks source link

Array of objects are displayed as array of string on swagger UI #223

Closed RajatKumarChahar closed 1 year ago

RajatKumarChahar commented 3 years ago

This is my doc of a service

{
    description: "Returns the Todos of a user",
    tag: "TODOs",
    definitions: {
      create_response: {
        type: "object",
        properties: {
          data: {
            type: "array",
            items: [
              {
                type: "object",
                properties: {
                  id: {
                    type: "string",
                  },
                  taskOwner: {
                    type: "object",
                    properties: {
                      id: {
                        type: "string",
                      },
                      email: {
                        type: "string",
                      },
                      image: {
                        type: "string",
                      },
                      userName: {
                        type: "string",
                      },
                    },
                    required: ["id", "email", "image", "userName"],
                  },
                },
                required: ["id", "taskOwner"],
              },
            ],
          },
          count: {
            type: "integer",
          },
        },
      },
      create_request: {
        type: "object",
        properties: {
          sortBy: {
            type: "string",
            description: "sort todos by",
          },
        },
      },
    },
    refs: {
      createRequest: "create_request",
      createResponse: "create_response",
    },
    operations: {
      create: {
        description: `
        TODOs service
        `,
        "parameters[3]": {
          description:
            "Text for search. TODOs can be searched using the article name, brief name",
          in: "query",
          name: "searchText",
          type: "string",
        },
        "parameters[2]": {
          description: "Size of the page",
          in: "query",
          name: "pageSize",
          type: "string",
        },
        "parameters[1]": {
          description: "Page number to get",
          in: "query",
          name: "page",
          type: "string",
        },
      },
    },
  }; 

On swagger UI the response body is displayed as Screenshot 2021-06-10 at 10 52 40 AM

I am not sure why it's happening. Can anyone help

Mairu commented 3 years ago

Do you perhaps have multiple usages of create_response also in another services? These names have to be unique in the whole specification.

RajatKumarChahar commented 3 years ago

Yes, it's unique. This is happening to all the API's doc. Whenever there is an array its always shows as ["string"]

RajatKumarChahar commented 3 years ago

Now I've used

return {
          [model]: modelSchema,
          [`${model}_list`]: {
            title: `${modelName} list`,
            type: "array",
            items: { $ref: `#/components/schemas/${model}` },
          },
        };

above code to generate the definitions but still in every [${model}_list] it shows [string]

Mairu commented 3 years ago

Could you post the generated swagger specification json? (You can use the docsJsonPath option, if you have not enabled it yet) (You can also test it yourself in https://editor.swagger.io/ what the problem is)