Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ jobs:
test:
strategy:
matrix:
ruby: ["3.0", "3.1", "3.2"]
ruby: ["3.3", "3.4", "4.0"]
gemfile: [Gemfile]
include:
- ruby: "3.2"
- ruby: "3.3"
gemfile: "gemfiles/rails-8.0.gemfile"
- ruby: "3.3"
gemfile: "gemfiles/rails-7.2.gemfile"
- ruby: "3.3"
gemfile: "gemfiles/rails-7.1.gemfile"
- ruby: "3.3"
gemfile: "gemfiles/rails-7.0.gemfile"
- ruby: "4.0"
gemfile: "gemfiles/rails-7.0.gemfile"
- ruby: "3.2"
gemfile: "gemfiles/rails-6.1.gemfile"

env:
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
Expand All @@ -23,7 +29,3 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake
- name: Send coverage
uses: paambaati/codeclimate-action@v5
env:
CC_TEST_REPORTER_ID: 618e64226e212a5824797037cb1a71487cdbfb3aa664bddc42a7189fb027f73a
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
4.0.9
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Unreleased

## 0.6.3

- Require `forwardable` explicitly to fix `NameError: uninitialized constant OpenApi::Paths::Forwardable` when nothing has loaded it beforehand (e.g. `require "open_api"` right after `require "rails"` on Ruby 3.3+, whose psych no longer loads it) https://github.com/wantedly/open_api/pull/18
- Bump Ruby and Rails https://github.com/wantedly/open_api/pull/18
- Supported Rubies: 3.3, 3.4, 4.0
- Supported Rails: 7.0, 7.1, 7.2, 8.0, 8.1

## 0.6.2

- Reflect ownership transfer https://github.com/wantedly/open_api/pull/16
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenApi [![Gem Version](https://badge.fury.io/rb/open_api.svg)](https://badge.fury.io/rb/open_api) [![Build Status](https://travis-ci.org/wantedly/open_api.svg?branch=master)](https://travis-ci.org/wantedly/open_api) [![Maintainability](https://api.codeclimate.com/v1/badges/dc4713a3cb67f6edce65/maintainability)](https://codeclimate.com/github/wantedly/open_api/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/dc4713a3cb67f6edce65/test_coverage)](https://codeclimate.com/github/wantedly/open_api/test_coverage)
# OpenApi [![Gem Version](https://badge.fury.io/rb/open_api.svg)](https://badge.fury.io/rb/open_api) [![Build Status](https://travis-ci.org/wantedly/open_api.svg?branch=master)](https://travis-ci.org/wantedly/open_api)

`open_api` provides PORO and serializers for OpenAPI and it supports OpenAPI v3.0.1.

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-6.1.gemfile → gemfiles/rails-7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in open_api.gemspec
gemspec path: '..'

gem 'activesupport', '~> 6.1.0'
gem 'activesupport', '~> 7.1.0'
8 changes: 8 additions & 0 deletions gemfiles/rails-7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in open_api.gemspec
gemspec path: '..'

gem 'activesupport', '~> 7.2.0'
8 changes: 8 additions & 0 deletions gemfiles/rails-8.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in open_api.gemspec
gemspec path: '..'

gem 'activesupport', '~> 8.0.0'
1 change: 1 addition & 0 deletions lib/open_api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Dependant libraries
require "forwardable"
require "active_support"
require "active_support/core_ext/hash"
require "active_support/core_ext/string/inflections"
Expand Down
2 changes: 1 addition & 1 deletion lib/open_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OpenApi
VERSION = "0.6.2"
VERSION = "0.6.3"
end
3 changes: 1 addition & 2 deletions open_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "activesupport", ['>= 5.0', '< 7.2']
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_dependency "activesupport", ['>= 5.0', '< 8.2']
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "pry"
Expand Down
12 changes: 12 additions & 0 deletions spec/open_api/equatable_as_content_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RSpec.describe OpenApi::EquatableAsContent do
describe "#==" do
it "returns true for objects with the same content" do
expect(OpenApi::Info.new(title: "Awesome API", version: "1.0.0")).to eq OpenApi::Info.new(title: "Awesome API", version: "1.0.0")
end

it "returns false for objects with different content" do
expect(OpenApi::Info.new(title: "Awesome API", version: "1.0.0")).not_to eq OpenApi::Info.new(title: "Another API", version: "1.0.0")
expect(OpenApi::Info.new(title: "Awesome API", version: "1.0.0")).not_to eq OpenApi::Info.new(title: "Awesome API", version: "2.0.0")
end
end
end
148 changes: 148 additions & 0 deletions spec/open_api/serializers/yaml_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,154 @@
EOL
)
end

context "with a specification built in the same way as open_api_annotator" do
let(:specification) do
paths = OpenApi::Paths.new
paths["/books"] = OpenApi::PathItem.new.tap do |path_item|
path_item.operations["get"] = build_operation(
"Returns an array of Book",
OpenApi::Schema.new(type: "array", items: OpenApi::Reference.new(ref: "#/components/schemas/Book")),
)
end
paths["/books/{id}"] = OpenApi::PathItem.new.tap do |path_item|
path_item.operations["get"] = build_operation("Returns a Book", OpenApi::Reference.new(ref: "#/components/schemas/Book"), ["id"])
path_item.operations["patch"] = build_operation("Returns a Book", OpenApi::Reference.new(ref: "#/components/schemas/Book"), ["id"])
end
paths["/books/count"] = OpenApi::PathItem.new.tap do |path_item|
path_item.operations["get"] = build_operation("Returns a integer", OpenApi::Schema.new(type: :integer, format: :int32))
end

schema = OpenApi::Schema.new(type: "object", properties: {})
schema.properties.merge!(
id: OpenApi::Schema.new(type: :integer, format: nil, nullable: false),
title: OpenApi::Schema.new(type: :string, format: nil, nullable: false),
published_at: OpenApi::Schema.new(type: :string, format: :"date-time", nullable: true),
tags: OpenApi::Schema.new(type: "array", items: OpenApi::Schema.new(type: :string, format: nil, nullable: false)),
authors: OpenApi::Schema.new(type: "array", items: OpenApi::Reference.new(ref: "#/components/schemas/Author"), nullable: false),
cover_image: OpenApi::Reference.new(ref: "#/components/schemas/CoverImage"),
publisher: OpenApi::Schema.new(nullable: true, allOf: [OpenApi::Reference.new(ref: "#/components/schemas/Publisher")]),
)
schema.required = [:id, :title]
components = OpenApi::Components.new(schemas: {})
components.schemas["Book"] = schema

OpenApi::Specification.new(
openapi: "3.0.1",
info: OpenApi::Info.new(title: "Book API", version: "1"),
paths: paths,
components: components,
)
end

def build_operation(description, schema, path_parameter_names = [])
operation = OpenApi::Operation.new(responses: OpenApi::Responses.new)
operation.responses["200"] = OpenApi::Response.new(
description: description,
content: { "application/json" => OpenApi::MediaType.new(schema: schema) },
)
path_parameter_names.each do |name|
operation.parameters = [] unless operation.parameters
operation.parameters.push(
OpenApi::Parameter.new(name: name, in: :path, required: true, schema: OpenApi::Schema.new(type: :string))
)
end
operation
end

it "creates yaml string from specification object" do
is_expected.to eq(
<<-EOL
---
openapi: 3.0.1
info:
title: Book API
version: '1'
paths:
"/books":
get:
responses:
'200':
description: Returns an array of Book
content:
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/Book"
"/books/{id}":
get:
responses:
'200':
description: Returns a Book
content:
application/json:
schema:
"$ref": "#/components/schemas/Book"
parameters:
- name: id
in: path
required: true
schema:
type: string
patch:
responses:
'200':
description: Returns a Book
content:
application/json:
schema:
"$ref": "#/components/schemas/Book"
parameters:
- name: id
in: path
required: true
schema:
type: string
"/books/count":
get:
responses:
'200':
description: Returns a integer
content:
application/json:
schema:
type: integer
format: int32
components:
schemas:
Book:
type: object
properties:
id:
type: integer
title:
type: string
published_at:
nullable: true
type: string
format: date-time
tags:
type: array
items:
type: string
authors:
type: array
items:
"$ref": "#/components/schemas/Author"
cover_image:
"$ref": "#/components/schemas/CoverImage"
publisher:
nullable: true
allOf:
- "$ref": "#/components/schemas/Publisher"
required:
- id
- title
EOL
)
end
end
end

describe "#deserialize" do
Expand Down
8 changes: 8 additions & 0 deletions spec/open_api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
require "open3"

RSpec.describe OpenApi do
it "has a version number" do
expect(OpenApi::VERSION).not_to be nil
end

it "can be required without other libraries loaded beforehand" do
lib = File.expand_path("../lib", __dir__)
output, status = Open3.capture2e(RbConfig.ruby, "-rbundler/setup", "-I", lib, "-e", 'require "open_api"')
expect(status).to be_success, output
end

it "creates simple spec" do
spec = OpenApi::Specification.new(
openapi: "3.0.1",
Expand Down
Loading