question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generic object responses should use 'any` and not generate a type

See original GitHub issue

What are the steps to reproduce this issue?

Orval: ^6.6.1 Type: react-query

Spring Boot has a Health Check endpoint defined as below with just scheme type = Object. because its an ANY response as a health check can have different details depending on what you are monitoring like Disk Space ,or Database Health Check etc.

OpenApiV3.json

"/actuator/health": {
      "get": {
        "tags": [
          "Actuator"
        ],
        "summary": "Actuator web endpoint 'health'",
        "operationId": "health",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }

A typical response from the Health Check looks like this…

{
  "status": "UP",
  "details": {
    "diskSpace": {
      "status": "UP",
      "details": {
        "total": 250685575168,
        "free": 188298530816,
        "threshold": 10485760
      }
    }
  }
}

However Orval is generating an empty TypeScript object like this:

export type Health200 = {};

So now in my code I have to cast Health200 to any so I can get to the `status field.

if (healthCheck.isSuccess) {
    const result = healthCheck.data as any; // cast as any to get to status
    if (result.status !== "UP") {
        throw new Error('REST API is currently down.');
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
anymaniaxcommented, Feb 17, 2022

fixed with 6.6.2

1reaction
anymaniaxcommented, Feb 17, 2022

Also thanks to you and @CPatchane!

Read more comments on GitHub >

github_iconTop Results From Across the Web

generic collection type does not take any object - Stack Overflow
Let's learn about variance. Whenever you have a generic type argument, such as your T , it can be. Covariant; Contravariant.
Read more >
How To Use Generics in TypeScript - DigitalOcean
In this code, you are creating a new type called User and using an array of that type ( User[] ) as the...
Read more >
Documentation - Generics - TypeScript
Here, we will use a type variable, a special kind of variable that works on types rather than values. We've now added a...
Read more >
Generic Methods - Java™ Tutorials
Generic methods allow type parameters to be used to express dependencies among the types of one or more arguments to a method and/or...
Read more >
OpenAPI generation couldn't infer response type for generic ...
then it will not get picked up. Expected behavior. The concrete response type should be inferred and used as response schema. Actual behavior...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found