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

Generic type in ApiResponse #245

Open
pixime opened this issue May 16, 2021 · 1 comment
Open

Generic type in ApiResponse #245

pixime opened this issue May 16, 2021 · 1 comment
Labels

Comments

@pixime
Copy link

pixime commented May 16, 2021

I have a generic based HttpService

class DataSourceService[T <: TimeSeries, D <: DataSource[T]]
  (implicit val system: ActorSystem[_], implicit val jsonFormat: RootJsonFormat[D]) extends HttpService {

I would like to do something like:

  @Operation(summary = "Get the data source",
    description = "Get the data source",
    responses = Array(
      new ApiResponse(responseCode = "200", description = "The data source",
        content = Array(new Content(schema = new Schema(implementation = classOf[D])))
      ),

where D is my generic type.
Unfortunately, as (I suppose) I do this within an annotation, the compiler returns:

class type required but D found
[error]         content = Array(new Content(schema = new Schema(implementation = classOf[D])))
[error]                                                                                  ^

I am looking for a workaround, any idea ?

@pjfanning
Copy link
Collaborator

how about classOf[DataSource[TimeSeries]]?

You might be better off writing the Open API spec by hand or using the Swagger Editor - it is normally better to write the API spec explicitly than to generate it.

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

No branches or pull requests

2 participants