epiphone / routing-controllers-openapi

Runtime OpenAPI v3 schema generation for routing-controllers.
MIT License
304 stars 56 forks source link

Not able to parse @QueryParams() #17

Open lgabeskiria opened 5 years ago

lgabeskiria commented 5 years ago
class SortOrder {
  [index: string]: 'ASC' | 'DESC'
}

class Query {
  @IsNumber()
  readonly offset: number = 0;

  @IsNumber()
  readonly limit: number = 10;

  @ValidateNested()
  readonly order: SortOrder;
}

class Controller {
  getAll(@QueryParams() query: Query) {

  }
}

This example creates one field called query and displays it as json field.

Expected behavior is to have 3 query parameters: offset, limit and order. Order parameter should be of deepObject style.

Example query string:

?limit=10&offset=0&order[firstName]=DESC&order[lastName]=ASC

More info https://swagger.io/docs/specification/serialization/

epiphone commented 5 years ago

Hi, that's bit of a tricky one. So we need to pass a style: "deepObject" property to your Parameter object, and the library is currently lacking this feature, right? One option would be to add a global configuration parameter for defining query parameter style and explode, how'd that work out for you? Or can you think of a way of setting them per-parameter?

Also your SortOrder class might be a problem since I'm not sure whether class-validator can handle index signatures like [index: string]: ....

Thanks for taking the time to open up an issue!

gstamac commented 5 years ago

This should actually be the default behavior. QueryParams should be expanded because it represents the whole query object (or at least part of it) not just one query parameter. I'll take a look and maybe create a PR.

gstamac commented 5 years ago

This is not possible now because routing-controllers-openapi doesn't have information about schemas.

lokeshmohanty commented 3 years ago

Do any work arounds exist for this at the moment?

gstamac commented 3 years ago

I regenerate the parameters after the spec is generated. In short go through the whole spec and if I find a "query" parameter that has "$ref" set I lookup the schema and replace the parameter.

lokeshmohanty commented 3 years ago

I regenerate the parameters after the spec is generated. In short go through the whole spec and if I find a "query" parameter that has "$ref" set I lookup the schema and replace the parameter.

Well that's the best option for now I guess. Thanks a lot.