Skip to content
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

Support type instead of interface for Queries #1743

Open
dessalines opened this issue Jan 22, 2025 · 2 comments
Open

Support type instead of interface for Queries #1743

dessalines opened this issue Jan 22, 2025 · 2 comments

Comments

@dessalines
Copy link

dessalines commented Jan 22, 2025

My project uses ts-rs to take rust objects, and generate typescript types, to be used for an API client.

While the types are nice to have, I'd also like to be able to use tsoa to build an OpenAPI spec.

All was going well until I tried to use my form in a Get :

/**
 * List all the media for your user
 *
 * `HTTP.GET /account/list_media`
 */
@Get("/account/list_media")
listMedia(
  @Queries() form: ListMedia = {},
  @Inject() options?: RequestOptions,
) {
  return this.#wrapper<ListMedia, ListMediaResponse>(
    HttpType.Get,
    "/account/list_media",
    form,
    options,
  );
}

And got this error:

GenerateMetadataError: @Queries('form') only support 'refObject' or 'nestedObjectLiteral' types. If you want only one query parameter, please use the '@Query' decorator.

Turns out, tsoa only supports interfaces, and not types, even though they are trivially the same:

// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

// Doesn't work
export type ListMedia = { page?: number; limit?: number };

// Works
export interface ListMedia {
  page?: number;
  limit?: number;
}

The strangest part about this, is that the return types (which are also all type), and @Body() seem to work perfectly fine. Only the Queries() doesn't work.

Copy link

Hello there dessalines 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@dessalines
Copy link
Author

dessalines commented Jan 22, 2025

As a (hopefully temporary) workaround, I'm doing the following to create "wrapper" interfaces so they can work with this library:

export interface ListMediaI extends ListMedia {}

Its strange that @Body() doesn't have the same limitation that @Queries() does tho, since they do similar work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant