-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588f382
commit 512e3ad
Showing
15 changed files
with
447 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ gem 'solargraph' | |
|
||
gem 'rake' | ||
gem 'rubocop' | ||
|
||
gem 'pry' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module CoreAPI | ||
module ArgumentSets | ||
class ObjectLookup < Apia::LookupArgumentSet | ||
|
||
name 'Object Lookup' | ||
description 'Provides for objects to be looked up' | ||
|
||
argument :id, type: :string | ||
argument :permalink, type: :string | ||
|
||
potential_error 'ObjectNotFound' do | ||
code :object_not_found | ||
description 'No object was found matching any of the criteria provided in the arguments' | ||
http_status 404 | ||
end | ||
|
||
resolver do |set, request, scope| | ||
objects = [{id: "123", permalink: "perma-123"}] | ||
object = objects.find { |o| o[:id] == set[:id] || o[:permalink] == set[:permalink] } | ||
raise_error 'ObjectNotFound' if object.nil? | ||
|
||
object | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'core_api/argument_sets/object_lookup' | ||
|
||
module CoreAPI | ||
module Endpoints | ||
class TestEndpoint < Apia::Endpoint | ||
|
||
description 'Returns the current time' | ||
argument :object, type: ArgumentSets::ObjectLookup, required: true | ||
field :time, type: Objects::Time, include: 'unix,day_of_week' | ||
scope 'time' | ||
|
||
def call | ||
object = request.arguments[:object].resolve | ||
response.add_field :time, get_time_now | ||
end | ||
|
||
private | ||
|
||
def get_time_now | ||
Time.now | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module CoreAPI | ||
module Objects | ||
class TimeZone < Apia::Enum | ||
|
||
value 'Europe/London' | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'apia-openapi/rack' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'apia-openapi/schema' | ||
|
||
module Apia | ||
module OpenAPI | ||
class Rack | ||
|
||
def initialize(app, api, path, **options) | ||
@app = app | ||
@api = api | ||
@path = "/#{path.sub(/\A\/+/, '').sub(/\/+\z/, '')}" | ||
Check failure Code scanning / CodeQL Polynomial regular expression used on uncontrolled data High
This
regular expression Error loading related location Loading library input Error loading related location Loading |
||
@options = options | ||
end | ||
|
||
def development? | ||
env_is_dev = ENV['RACK_ENV'] == 'development' | ||
return true if env_is_dev && @options[:development].nil? | ||
|
||
@options[:development] == true | ||
end | ||
|
||
def api | ||
return Object.const_get(@api) if @api.is_a?(String) && development? | ||
return @cached_api ||= Object.const_get(@api) if @api.is_a?(String) | ||
|
||
@api | ||
end | ||
|
||
def base_url | ||
@options[:base_url] || 'https://api.example.com/api/v1' | ||
end | ||
|
||
def call(env) | ||
# if @options[:hosts]&.none? { |host| host == env['HTTP_HOST'] } | ||
# return @app.call(env) | ||
# end | ||
|
||
unless env['PATH_INFO'] == @path | ||
return @app.call(env) | ||
end | ||
|
||
schema = Schema.new(api, base_url) | ||
body = schema.json | ||
|
||
[200, { 'Content-Type' => 'application/json', 'Content-Length' => body.bytesize.to_s }, [body]] | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.