a-chacon / oas_rails

Generate Automatic Interactive Documentation for Your Rails API
GNU General Public License v3.0
69 stars 4 forks source link

Schema for non-ActiveRecords class #63

Open lucasteles opened 1 month ago

lucasteles commented 1 month ago

Is there any way or plan to define the schema for any class?

Something like:

# @schema [Hash{name: String, age: Integer}]
Person = Data.define(:name, :age)
a-chacon commented 1 month ago

Hi! You are the first asking that.

If I understand, you want to define these schemas for reuse in @request_body or @response and don't to have to repeat the description every time you document an endpoint. I am right? It sounds perfect to me, but I am currently without time for developing a new feature. However, I will be happy to review/discuss a proposal.

In that case should be something like:

# @schema Data [Hash{name: String, age: Integer}]
class Data
  attrs_accesor :name, :age
end

Then use in the controller as

# @request_body A Person [Data]
def create
  ...
end

Is that what you mean?