1

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?

fiedl
  • 5,667
  • 4
  • 44
  • 57

1 Answers1

0

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.

  • Hi and welcome to stackoverflow! I‘m not sure I understand your suggestion. The line that raises the exception is ˋreturns array_of: Stringˋ. Sending the json response does work. – fiedl Feb 28 '22 at 11:25
  • Have you tried changing `array_of: String` for `:array_of => String`? – Micaela Wolman Mar 02 '22 at 15:30