How to pass fetched data to schema for getting response body in fastapi?

Viewed 15

This is my created Schema:

class NodeUiSchema():
    text : str
    nodes: List


class CloudUiSchema():
    id: int
    text: str
    nodes:List[NodeUiSchema]

And I need response in below format after fetching data from db using sqlalchemy so for that reason i need to pass fetched data into Schema to get below response :

const data = [
  {
    id: 1
    text: "AWS",
    nodes: [
      {
        text: "EC2",
        nodes: [
          {
            text: "EC2 Switch_on"
          },
          {
            text: "EC2 Switch_off"
          }
        ]
      },
      {
        text: "RDS"
      }
    ]
  },
  {
    id: 2
    text: "Azure",
    nodes: [
      { text: "AVM" }
    ]
  }
];

Help me out for getting this response using Fastapi......... Thanks a lot if you come up with the solution..

0 Answers
Related