Skip to content

Representing a list at the root of the output #1260

Open
@SimeonYovchev

Description

@SimeonYovchev

I am encountering an issue with representing a list at the root of the output. I have an API endpoint that returns an array of users like this:
[{ id: 1, name: 'A' }, { id: 2, name: 'B' }]
I am trying to build a model to handle this scenario
I have the following model:

@restJson1
service MyService {
    version: "1.0.0"
    operations: [
        GetUsersList
    ]
}

@readonly
@http(method: "GET", uri: "/api/users", code: 200)
operation GetUsersList {
    input := {
        @httpQuery("permissions")
        permissions: String
        @httpQuery("show_inactive")
        show_inactive: Boolean
    }
    output := {
        @httpPayload
        content: UserListContent
    }
}

structure UserListContent {
    list: UserList
}

list UserList {
    member: User
}

structure User {
    id: String
    name: String
}

When I try to call getUsersList operation I get the following error:
TypeError: Expected object, got array

How can I solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions