Giter Site home page Giter Site logo

switchdreams / rest-api-generator Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 242 KB

Build a Ruby on Rails REST API faster

Home Page: https://rest-api-generator.switchdreams.com.br/

License: MIT License

Ruby 92.39% Shell 0.16% JavaScript 0.08% CSS 0.88% HTML 6.50%
rails rest-api rest-api-framework rest-api-helper ruby

rest-api-generator's People

Contributors

davidsongm avatar lordefelipe avatar lucasazuma avatar pedroaugustoramalhoduarte avatar waliffcordeiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rest-api-generator's Issues

Filtering/Search

Goal

Filter some resource by parameters

/projects?archived=true

Inspirations

# From https://hspazio.github.io/2018/rails-filterable-concern/
module Filterable
  extend ActiveSupport::Concern

  included do
    @search_scopes ||= []
  end

  module ClassMethods
    attr_reader :search_scopes

    def search_scope(name, *args)
      scope name, *args
      @search_scopes << name.to_s.gsub('filter_by_', '').to_sym
    end

    def filter(params)
      results = where(nil)
      params.each do |key, value|
        results = results.public_send("filter_by_#{key}", value) if value.present?
      end
      results
    end
  end
end

Serialization

Goal

Support serialization by default

Options

  • For AMS: Just use the default generator for creating a serializer object
  • Panko Serializer: More perfomatic serializer

Needs

  • Config option for choosing another serializer gem

Wrong params when created with references

When we run:
rails g rest_api_generator:resource Task student:references

The generated controller params is;

def task_params
  params.require(:task).permit(:student)
end

its is expected to be:

def task_params
  params.require(:task).permit(:student_id)
end

Improves filter resource api

The goals is to reduce when use filter resource function:

Project.filter_resource(params.slice(*Project.filter_scopes)

Most of the time the filter resource argument is params.slice(*Project.filter_scopes), we can setup the default value of filter resource to that

callbacks for set resource

When we are trying to setup authorization, regularly we need to run a method with the resource as params.

Example with action policy

before_action -> { authorize! @power_plant, with: PowerPlantChildrenPolicy }

i think a good API is:

after_set_resource ->(resource) { authorize! resource, with: PowerPlantChildrenPolicy }

and

after_set_parent_resource ->(resource) { authorize! resource, with: PowerPlantChildrenPolicy }

Use params types on RSwag specs generation

When creating a rswag spec for a resource with rails g rest_api_generator:spec:rswag Car name:string color:string year:integer, it currently ignores fields types and sets everything as string on params (for post and patch requests).

New docs

Readme.md docs is hard to read and understand, normally in SwitchDreams we use vitepress

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.