Giter Site home page Giter Site logo

elmassimo / types_from_serializers Goto Github PK

View Code? Open in Web Editor NEW
77.0 3.0 7.0 405 KB

✅ Generate TypeScript interfaces from your JSON serializers

License: MIT License

JavaScript 11.20% Shell 0.41% Ruby 60.75% TypeScript 12.20% Vue 8.67% HTML 6.53% Logos 0.24%
codegen ruby typescript activemodelserializers oj serializers

types_from_serializers's Introduction

Projects 🛠

My current focus is development experience, and how it can help us achieve increased productivity.

Vite.js

Vite.js with Ruby

Vue.js

  • vuex-stores: 🗄 Store objects for Vuex, a simple and more fluid API for state-management.

Rails

  • js_from_routes: 🛣️ Generate path helpers and API methods from your Rails routes
  • oj_serializers: ⚡️ Faster JSON serialization for Ruby on Rails. Easily migrate away from Active Model Serializers
  • types_from_serializers: ✅ Generate TypeScript interfaces from your JSON serializers
  • presenter_rails: 🔭 Expose your view models in a convenient way
  • queryable: ❔ Gives your queries a home and avoid tucking scopes inside your models
  • resourcerer: ✨ Works like magic to dry up your controllers
  • request_store_rails: 📦 Per-request global storage for Rails prepared for multi-threaded apps

Ruby

  • better_settings: ⚙ Settings for Ruby apps – fast, immutable, better
  • capybara-compose: ✅ Easily write fluent integration tests with Capybara
  • i18n_multitenant: 🌎 Provides a convenient way to use tenant-specific translations
  • pakiderm: 🐘 Pakiderm will never forget the return value

Demos / Templates / App Starters

Podcasts & Talks 📣

Writing ✍️

Here are some articles I've written:

types_from_serializers's People

Contributors

aviemet avatar elmassimo avatar petergoldstein avatar sansari avatar ventsislaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

types_from_serializers's Issues

On-demand type generation not working

  • I have tried upgrading by running bundle update types_from_serializers.
  • I have read the troubleshooting section before opening an issue.

Description 📖

On demand generation on change not working, but I found a workaround that does the job for now.

Reproduction/Logs 🐞📜

Hi Máximo, thanks for another awesome gem.

I'm struggling a bit with the autogeneration of types. It seems to be initializing properly, and indeed tracking changes too.

If I make a change to a serializer, and then check the output of running Rails.application.reloaders in my console, I get the following output:

<TypesFromSerializers::Changes:0x0000ffff9862ec68 @added=#<Set: {}>, @modified=#<Set: {"/app/app/typed_serializers/my_serializer.rb"}>, @removed=#<Set: {}>>

So the tracking does seem to be working, but it nothing is ever re-generated, unless I explicitly call TypesFromSerializers.generate_changed in the rails console, then it works.

So I then tried forcing it by adding another hook in my initializer:

  Rails.application.reloader.to_prepare do
    puts "force serializer generation"
    TypesFromSerializers.generate_changed
  end

But at this stage, it doesn't seem to be aware of file changes. Like this hook has a different context to my rails console. So nothing happens.

As a workaround for now I changed this hook to:

  Rails.application.reloader.to_prepare do
    TypesFromSerializers.generate(force: true)
  end

And it works, and it's fast enough re-generating everything that it's an acceptable workaround.

So that's my issue, and I wanted to ask you if you have an idea why this may be happening? Just to mention I have also installed the listen gem.

Cheers!

Nested Serializers

Howdy! Given this serializer (in a single file, verbatim):

class FooSerializer < BaseSerializer
  class BarSerializer < BaseSerializer
    attributes :id
  end

  belongs_to :bar, serializer: BarSerializer
end

The generated TS file is invalid:

import type FooSerializerBar from './FooSerializer/Bar'

export default interface Foo {
  bar: FooSerializerBar
}

The ./FooSerializer/Bar does not exist.

Am I doing something wrong, or is this currently unsupported?

I find this pattern of nesting serializers is very useful when you need a representation of a child resource that depends on the parent context vs. having one large serializer in the base directory with a lot of flags/conditionals.

Cannot use name_from_serializer

  • I have tried upgrading by running bundle update types_from_serializers.
  • I have read the troubleshooting section before opening an issue.

Description 📖

When using:

if Rails.env.development?
  TypesFromSerializers.config do |config|
    config.name_from_serializer = ->(name) { name }
  end
end

and then issuing the command:

bundle exec rake types_from_serializers:generate

no serializers are found

bundle exec rake types_from_serializers:generate
Generating TypeScript interfaces...completed in 0.0 seconds.
Found 0 serializers:

while, when removing the line config.name_from_serializer = ->(name) { name }, everything works as it should.

I only wanted to make sure the generated types got a prefix, which should not interfere with the finding of serializers.

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.