10000 Response type is ignored: object instead of actual type · Issue #5377 · scalar/scalar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Response type is ignored: object instead of actual type #5377

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

Closed
luarvic opened this issue Apr 10, 2025 · 11 comments · Fixed by #5502 or #5661
Closed

Response type is ignored: object instead of actual type #5377

luarvic opened this issue Apr 10, 2025 · 11 comments · Fixed by #5502 or #5661
Assignees
Labels
bug Something isn't working

Comments

@luarvic
Copy link
luarvic commented Apr 10, 2025

What happens?

I generate an open API documentation and expose it via Scalar UI using the following NuGet packages:

<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
<PackageReference Include="Scalar.AspNetCore" Version="2.1.9" />

The problem is that the Scalar UI ignores the schema name in the responses (i.e. array Device[]), and shows array object[] instead. Although, the actual type presents in the generated documentation (see the OpenAPI Document below).

I tested the same file with the Swagger UI and it does show the correct schema.

Image

What did you expect to happen?

I expect to see array Device[] instead of array object[] in responses if Device is referenced in the responses definition, e.g.:

        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Device"
                  }
                }
              }
            }
          }
        }

OpenAPI Document

{
  "openapi": "3.0.1",
  "info": {
    "title": "Foo | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5555/"
    }
  ],
  "paths": {
    "/Private/Audit/ExportAllDevices": {
      "get": {
        "tags": [
          "Audit"
        ],
        "description": "Exports all devices",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Device"
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Device"
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Device"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Device": {
        "required": [
          "isActive",
          "name"
        ],
        "type": "object",
        "properties": {
          "isActive": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Audit"
    }
  ]
}
@luarvic luarvic added the bug Something isn't working label Apr 10, 2025
8000
@cyclr-adrian
Copy link

I too am having the same issue. See the discussion post I made here

If its always going to show a plain object or a plain array object[] rather than the specific model type, what is the point of all the model definitions being rendered in the UI when you can't match up which endpoint uses which model?

@luarvic
Copy link
Author
luarvic commented Apr 11, 2025

Hey @cyclr-adrian,

Exactly. I tried using ProducesResponseTypeAttribute to explicitly let it know the response type, but it didn’t work. The document is correct, but rendering in Scalar doesn’t take models into account. It just lists model in the left panel which is useless.

@antlio
Copy link
Contributor
antlio commented Apr 28, 2025

hey @luarvic @cyclr-adrian thank you both for your precious feedback! we are working on making this happen asap!

@luarvic
Copy link
Author
luarvic commented Apr 30, 2025

Hey @antlio,

Does 2.2.2 version released yesterday contain your RP 5502#?

I upgraded the package but still see object.

@antlio
Copy link
Contributor
antlio commented Apr 30, 2025

hey @luarvic, it hasn't been released yet, it is part ot #5522 which will be released soon!

@paul-datatech911
Copy link

I looked at the related issues and this repo, but can't tell if this is released or not Scalar.AspNetCore 2.3.0 nuget package. I'm still having the same/similar problem.

-- OpenApi schema

"GetIncidentsResponse": {
        "type": "object",
        "properties": {
          "incidents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Incident"
            }
          }
        }
      },

-- Rendered Api Page

Image

@antlio antlio reopened this May 15, 2025
@antlio
Copy link
Contributor
antlio commented May 15, 2025

hey @paul-datatech911, seems like there's a missing bit here! pushing an update right now

@paul-datatech911
Copy link

Cool, thanks! When do packages typically get pushed out?

@antlio
Copy link
Contributor
antlio commented May 16, 2025

packages have been released, this was part of #5627

@paul-datatech911
Copy link

packages have been released, this was part of #5627

I didn't see the new package last night, but do now - thanks. This does seem to fix the issue, much appreciated @antlio .

@antlio
Copy link
Contributor
antlio commented May 16, 2025

@paul-datatech911 of course, glad to hear it thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants
0