GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - wantedly/open_api_annotator: OpenAPI spec generation by bottom-up.

BranchesTags
Open more actions menu

Latest commit

 

History

91 Commits
91 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
bin
bin
 
 
gemfiles
gemfiles
 
 
lib
lib
 
 
spec
spec
 
 
.gitignore
.gitignore
 
 
.rspec
.rspec
 
 
.ruby-version
.ruby-version
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
Gemfile
Gemfile
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
open_api_annotator.gemspec
open_api_annotator.gemspec
 
 

Repository files navigation

OpenApiAnnotator Gem Version Build Status Maintainability Test Coverage

OpenApiAnnotator realizes to generate OpenAPI spec by annotating to controllers and serializers. If you use ActiveModelSerializer, this is the best way to generate OpenAPI spec.

Installation

Add this line to your application's Gemfile:

gem 'open_api_annotator'

Usage

Annotating controllers and serializers, you can generate OpenAPI spec file from these. Things you have to do are three below:

  1. Configure API meta information
  2. Annotate controllers
  3. Annotate serializers

1. Configure API meta information

You have to set API meta information like:

# config/initializers/open_api_annotator.rb
OpenApiAnnotator.configure do |config|
  config.info = OpenApi::Info.new(title: "Book API", version: "1")
  config.destination_path = Rails.root.join("api_spec.yml")
  config.path_regexp = /\Aapi\/v1\// # If you want to restrict a path to create
end

2. Annotate controller

To define an entity of an endpoint, call the method endpoint in the previous line of an action method. It takes entity expression as the first arg. Entity expression is a model class or an array that contains only one model class.

class Api::V1::BooksController
  endpoint [Book] # 👈It means an array of Book
  def index
    books = Book.limit(10)
    render json: books
  end

  endpoint Book # 👈Just a Book
  def show
    book = Book.find(params[:id])
    render json: book
  end

  endpoint Book # 👈Just a Book
  def update
     book = Book.find(params[:id])
     book.update!(book_params)
     render json: book
  end
end

3. Annotate serializer

To define an schema in components, set type, format, nullable as each field option.

class BookSerializer < ApplicationSerializer
  attribute :title, type: :string, nullable: false
  attribute :published_at, type: :string, format: :"date-time", nullable: true

  has_many :authors, type: [Author], nullable: false
  has_one :cover_image, type: CoverImage, nullable: true
  belongs_to :publisher, type: Publisher, nullable: 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.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number using bundle exec bump patch(or minor, major), 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/wantedly/open_api_annotator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant 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 OpenApiAnnotator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

OpenAPI spec generation by bottom-up.

Topics

actionpackactivemodelserializersoas3openapirails

Resources

Readme
MIT license

Code of conduct

Code of conduct
Activity
Custom properties

Stars

12 stars

Watchers

2 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.