https://github.com/sanfrecce-osaka/katarina
This gem generates type definition files for TypeScript from a OpenAPI Documentation generated by rspec-openapi.
https://github.com/sanfrecce-osaka/katarina
katarina rspec-openapi ruby ruby-gem typescript
Last synced: about 1 year ago
JSON representation
This gem generates type definition files for TypeScript from a OpenAPI Documentation generated by rspec-openapi.
- Host: GitHub
- URL: https://github.com/sanfrecce-osaka/katarina
- Owner: sanfrecce-osaka
- License: mit
- Created: 2020-07-22T18:34:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-20T13:06:32.000Z (over 5 years ago)
- Last Synced: 2024-04-25T23:04:03.425Z (about 2 years ago)
- Topics: katarina, rspec-openapi, ruby, ruby-gem, typescript
- Language: Ruby
- Homepage:
- Size: 28.3 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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:
```ruby
gem 'katarina', group: :development
```
And then execute:
$ bundle install
## Usage
Execute below command
```shell script
$ bin/rails katarina:generate
```
### Example
`#{Katarina.config.input_path}` contents is below:
```yaml
---
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:
```ts
type TApiUsersPostsIndex200 = {
id: number
name: string
comments: {
id: number
deleted: boolean
}[]
}
```
### Configuration
The following configurations are optional.
```ruby
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](https://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](https://github.com/[USERNAME]/katarina/blob/master/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## 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](https://github.com/sanfrecce-osaka/katarina/blob/master/CODE_OF_CONDUCT.md).