apipie: describe the return of an array of strings

Viewed 29

Using apipie-rails, I would like to describe the response of an array of strings.

# GET /api/v1/some_strings.json
["Foo", "Bar"]

I was thinking of describing the response like this:

api :GET "/api/v1/some_strings.json"
returns array_of: String, code: 200
def index
  return json: ["Foo", "Bar"]
end

However, I'm getting the following runtime error:

RuntimeError:
  No param_group or self-describing class named String

From the response-description documentation it looks like this is not supported by this dsl.

I was wondering whether there is another syntax to describe the desired response.

Or is returning an array of strings considered an anti-pattern and I should instead refactor the api structure itself?

1 Answers

Taking a look at this example, I would try this:

api :GET "/api/v1/some_strings.json"
returns array_of: String
def index
  render JSON(["Foo", "Bar"])
end

By the way, if the status code that you want to return it's 200, you don't have to specify it.

Related