Katarina
This gem generates type definition files for TypeScript from a OpenAPI Documentation generated by rspec-openapi
.
Installation
Add this line to your application's Gemfile:
gem 'katarina', group: :development
And then execute:
$ bundle install
Usage
Execute below command
$ bin/rails katarina:generate
Example
#{Katarina.config.input_path}
contents is below:
---
openapi: 3.0.3
info:
title: sample
paths:
"/v1/users/{user_id}/posts":
get:
summary: 'api/v1/users/posts #index'
parameters:
- name: user_id
in: path
required: true
schema:
type: integer
responses:
'200':
description: HTTP status is 200
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
comments:
type: array
items:
type: object
properties:
id:
type: integer
deleted:
type: boolan
# ...
And then it will generate #{Katarina.config.output_dir}/api/users/posts.d.ts
like the following contents:
type TApiUsersPostsIndex200 = {
id: number
name: string
comments: {
id: number
deleted: boolean
}[]
}
Configuration
The following configurations are optional.
Katarina.configure do |config|
# Change the input path to generate types from RSpec::OpenAPI.path
config.input_path = 'doc/schema.yaml'
# Change the output directory to generate types from #{RSpec::OpenAPI.path}/types
config.output_dir = 'doc/types'
# Sets the paths to be excluded from type naming and generating type definition file path
config.exclude_paths = %w[api v1]
# Disable type name prefix
config.prefix = false
end
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment. If you want to check it with an old version of Ruby, run bin/build
and transpile it.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/sanfrecce-osaka/katarina. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Katarina project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.