codecentric / hikaku

A library that tests if the implementation of a REST-API meets its specification.
Apache License 2.0
197 stars 19 forks source link

Query Parameter based on an object #47

Open cc-jhr opened 5 years ago

cc-jhr commented 5 years ago

Is your feature request related to one or multiple existing converters? SpringConverter

Describe the solution you'd like Spring allows query parameter definitions by simply passing an object.

On extracting query parameters every controller method should be check for parameters (objects, not interfaces) without any spring annotation. The limitation to the usual spring controller method annotations is important, because the parameter could have a JSR-303 annotation or the like.

Easiest way to to get on all properties without having to do the reflection manually might be to serialize the type as json and and then extract the paths from the json. Suggestion for seriallization lib could be klaxon or moshi

Unchecked:

Additional context Simple objects

data class Params1 (
  var a: String
  var b: String
)

data class Params2 (
  var a: String
  var c: String
)

@GetMapping("/todos")
fun getAllTodos(params1: Params1, params2 Params2) {
  /*
    calling: /todos?a=val1&b=val2&c=val3

    will result in :
    Params1(a = val1, b = val2)
    Params2(a = val1, c = val3)

  */
}

Nested object

data class Params1 (
  var a: String
  var b: Params2
)

data class Params2 (
  var a: String
  var c: String
)

@GetMapping("/todos")
fun getAllTodos(params1: Params1) {
  /*
    calling: /todos?a=val1&b.c=nestedvalue&c=othervalue

    will result in:
    Params1(a = val1, b = null)
    Params2(a = null, c = nestedvalue)

  */
}

Extract query parameter names from json:

{
  "a": null,
  "b": {
      "a": null,
      "c": null
    }
}

Must result in three query parameters:

atlatosPonga commented 4 years ago

Any plans regarding this feature?

cc-jhr commented 4 years ago

Hi @atlatosPonga, thank you for your interest in the project. There are currently no concrete plans for the implementation or the timing of the implementation. Pull requests are always welcome ;)