Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add servers #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions lib/openapi_parser/request_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class << self
# @param [OpenAPIParser::Config] config
# @param [OpenAPIParser::PathItemFinder] path_item_finder
# @return [OpenAPIParser::RequestOperation, nil]
def create(http_method, request_path, path_item_finder, config)
def create(http_method, request_path, path_item_finder, config, servers)
result = path_item_finder.operation_object(http_method, request_path)
return nil unless result

self.new(http_method, result, config)
self.new(http_method, result, config, servers)
end
end

Expand All @@ -25,18 +25,23 @@ def create(http_method, request_path, path_item_finder, config)
# @return [String]
# @!attribute [r] path_item
# @return [OpenAPIParser::Schemas::PathItem]
attr_reader :operation_object, :path_params, :config, :http_method, :original_path, :path_item
attr_reader :operation_object, :path_params, :config, :http_method, :original_path, :path_item, :servers

# @param [String] http_method
# @param [OpenAPIParser::PathItemFinder::Result] result
# @param [OpenAPIParser::Config] config
def initialize(http_method, result, config)
def initialize(http_method, result, config, servers)
@http_method = http_method.to_s
@original_path = result.original_path
@operation_object = result.operation_object
@path_params = result.path_params || {}
@path_item = result.path_item_object
@config = config
@servers = servers
end

def validate_servers(servers)
operation_object.validate_servers(servers)
end

def validate_path_params(options = nil)
Expand All @@ -50,6 +55,7 @@ def validate_path_params(options = nil)
def validate_request_body(content_type, params, options = nil)
options ||= config.request_body_options
operation_object&.validate_request_body(content_type, params, options)
validate_servers(servers)
end

# @param [OpenAPIParser::RequestOperation::ValidatableResponseBody] response_body
Expand Down
1 change: 1 addition & 0 deletions lib/openapi_parser/schemas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
require_relative 'schemas/media_type'
require_relative 'schemas/schema'
require_relative 'schemas/header'
require_relative 'schemas/servers'
1 change: 1 addition & 0 deletions lib/openapi_parser/schemas/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ class MediaType < Base; end
class Schema < Base; end
class Components < Base; end
class Header < Base; end
class Servers < Base; end
end
6 changes: 5 additions & 1 deletion lib/openapi_parser/schemas/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ def initialize(raw_schema, config, uri: nil, schema_registry: {})
# @return [Components, nil]
openapi_attr_object :components, Components, reference: false

# @!attribute [r] servers
# @return [Servers, nil]
openapi_attr_list_object :servers, Servers, reference: false

# @return [OpenAPIParser::RequestOperation, nil]
def request_operation(http_method, request_path)
OpenAPIParser::RequestOperation.create(http_method, request_path, @path_item_finder, @config)
OpenAPIParser::RequestOperation.create(http_method, request_path, @path_item_finder, @config, servers)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to pass Server Object.

The RequestOperation object for validating using Operation Object.
The Operation Object specified by path and http method so it don't care about server URL so they don't need to Server Object which define server URL.
(This object is intended to run on a server that accepts requests. This object is supposed to run on the server that accepts requests, although it can also be used on the client side.)

I think we should add validate method to Server Object and call it from OpenAPI Object.
(The client validate URL using that method before send request )

end

# load another schema with shared config and schema_registry
Expand Down
7 changes: 7 additions & 0 deletions lib/openapi_parser/schemas/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@ def validate_request_body(content_type, params, options)
def validate_response(response_body, response_validate_options)
responses&.validate(response_body, response_validate_options)
end

def validate_servers(servers)
servers.each do |server|
#puts "server url: #{server.url}"
#puts "server description: #{server.description}"
end
end
end
end
6 changes: 6 additions & 0 deletions lib/openapi_parser/schemas/servers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module OpenAPIParser::Schemas
class Servers < Base

openapi_attr_values :url, :description
end
end