interagent / heroics

Ruby HTTP client for APIs represented with JSON schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate response object class

ota42y opened this issue · comments

The heroics generated code return JSON text.
(Please ignore this issue if I made a mistake, because I checked my JSON Schema only)

I think if targetSchema define in JSON Schema, generate target schema class and return as Object.

When the user define this schema.

{
  "href":"/resource",
  "method":"GET",
  "targetSchema": {
    "$ref": "#/definitions/res"
  },
}

And there is this definition.

"res": {
  "id": "schema/res",
  "type": [
    "object"
  ],
  "definitions": {
    "id": {
      "example": 10,
      "type": [
        "integer"
      ]
    },
  },
}

We should generate this class and convert JSON to this object

class Res
  attr_accessor :id
end

Twitter client library, Github client library are also working in the same way.
Of course I know that there are restrictions because thease libraries written by hand and this gem generate code from JSON.

But, the product becomes more complicated, so it's good idea we don't convert JSON to keep it in a thin library.

What do you think

Hmm. It would make the library a bit more complicated, but I can certainly see how it would make things more usable. As you suggest, I think it begs the question if it belongs here or if it could be a layer on top. At the very least I would be concerned about changing directly to this as the default, as it would be a surprising/breaking change to suddenly start getting back objects instead of more raw data. So, maybe if we could figure out a good way to make this an option/possibility. What do you think?

Certainly compatibility is important.

I think, we can do it.
In this case, we generate two code the one return json text and the other return parsed object, and the user set option to decide using which code.

However, as behavior changes greatly depending on options, I think that it tends to be a hotbed of bugs.
So, it seems better to stop putting it in ... 😢

Alright, let's maybe pass for now, but we should keep this in mind for future major versions (where we could make breaking changes) or in case anything changes. Thanks for taking the time to discuss it with me.