{"id":16549706,"url":"https://github.com/uiur/oa","last_synced_at":"2025-09-11T02:09:30.552Z","repository":{"id":62941441,"uuid":"563859054","full_name":"uiur/oa","owner":"uiur","description":"Oa lets you write OpenAPI annotations in your API code. (Rails etc.)","archived":false,"fork":false,"pushed_at":"2022-11-10T13:28:34.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T13:46:50.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uiur.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-09T13:44:08.000Z","updated_at":"2022-11-10T11:08:06.000Z","dependencies_parsed_at":"2023-01-21T21:21:17.080Z","dependency_job_id":null,"html_url":"https://github.com/uiur/oa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uiur/oa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiur%2Foa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiur%2Foa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiur%2Foa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiur%2Foa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uiur","download_url":"https://codeload.github.com/uiur/oa/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uiur%2Foa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274564259,"owners_count":25308559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T19:30:28.984Z","updated_at":"2025-09-11T02:09:30.530Z","avatar_url":"https://github.com/uiur.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Oa ![test](https://github.com/uiur/oa/actions/workflows/main.yml/badge.svg)\n\nOa lets you write OpenAPI annotations in your API code.\n\n```ruby\nclass UsersController\n  include Oa::Annotator\n\n  openapi do\n    {\n      '/users' =\u003e {\n        get: {\n          responses: {\n            # ...\n          }\n        }\n      }\n    }\n  end\n  def index\n    # ...\n  end\n\n  openapi do\n    # You can write any code here, as long as the block returns result as hash.\n    {\n      '/users/{id}' =\u003e {\n        get: {\n          parameters: [\n            # ...\n          ],\n          responses: {\n            # ...\n          }\n        }\n      }\n    }\n  end\n  def show\n    # ...\n  end\nend\n\n# Put all annotations together and write openapi documents to files\nOa.generate_documents\n```\n\n## On DSL\n\nOa itself doesn't provide a lot of DSL to describe openapi. Instead, it allows developers to define custom DSL for each application purpose.\n\nOther libraries have lots of DSL methods but it's somewhat hard to master. In many cases, making custom DSL is a better way to write concise openapi spec in Ruby.\n\n```ruby\nmodule DSL\n  def get(path, operation)\n    {\n      path =\u003e {\n        get: operation\n      }\n    }\n  end\nend\n\nOa.configure do |config|\n  config.include DSL\n  # ...\nend\n\nclass UsersController\n  include Oa::Annotator\n\n  openapi do\n    # So you can write:\n    get('/users', {\n      # ..\n    })\n  end\n  def index\n  end\nend\n```\n\n## Usage\n\nFirst, it requires defining at least one document.\n\nIf you use Rails, in `config/initializers/oa.rb`:\n\n```ruby\nOa.configure do |config|\n  config.documents = [\n    Oa::Document.new(\n      name: :api,\n\n      # The destination of output openapi document\n      path: 'app/openapi/api.yml',\n\n      # openapi metadata. This will be merged into the output openapi document.\n      root: {\n        openapi: '3.0.0',\n        info: {\n          title: 'api',\n          version: '1.0.0'\n        },\n      }\n    )\n  ]\nend\n```\n\nSecond, write some annotations in your controllers:\n\n```ruby\nclass BaseController\n  include Oa::Annotator\n\n  # specify document name in the configuration:\n  openapi_document :api\nend\n\nclass UsersController \u003c BaseController\n  openapi do\n    {\n      '/users' =\u003e {\n        get: {\n          responses: {\n            # ...\n          }\n        }\n      }\n    }\n  end\n  def index\n    # ...\n  end\nend\n```\n\nAnd then, you can generate openapi documents:\n\n```ruby\nOa.generate_documents\n#=\u003e app/openapi/api.yml\n```\n\n## Configuration\n\n### Documents\n\n`config.documents` can have multiple documents.\n\n```ruby\nOa.configure do |config|\n  config.documents = [\n    Oa::Document.new(\n      name: :api,\n      path: 'app/openapi/api.yml',\n      root: {\n        openapi: '3.0.0',\n        info: {\n          title: 'api',\n          version: '1.0.0'\n        },\n      }\n    ),\n    Oa::Document.new(\n      name: :api2,\n      path: 'app/openapi/api2.yml',\n      root: {\n        openapi: '3.0.0',\n        info: {\n          title: 'api2',\n          version: '1.0.0'\n        },\n      }\n    )\n  ]\nend\n```\n\nSo, it can generate seperate document files for each api.\n\n```ruby\nclass Api::BaseController\n  include Oa::Annotator\n  openapi_document :api\nend\n\nclass Api::UsersController \u003c Api::BaseController\n  # ...\nend\n\nclass Api2::BaseController\n  include Oa::Annotator\n  openapi_document :api2\nend\n\nclass Api2::UsersController \u003c Api2::BaseController\n  # ...\nend\n```\n\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'oa', github: 'uiur/oa'\n```\n\nAnd then execute:\n\n    $ bundle install\n\n## Development\n\nAfter 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.\n\nTo 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/oa. 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]/oa/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Oa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/oa/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuiur%2Foa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuiur%2Foa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuiur%2Foa/lists"}