File tree Expand file tree Collapse file tree
spec/lib/openapi3_parser/validators Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33require "openapi3_parser/node_factory/object"
44require "openapi3_parser/validation/input_validator"
55require "openapi3_parser/validators/email"
6- require "openapi3_parser/validators/url "
6+ require "openapi3_parser/validators/uri "
77
88module Openapi3Parser
99 module NodeFactory
@@ -13,7 +13,7 @@ class Contact < NodeFactory::Object
1313 field "name" , input_type : String
1414 field "url" ,
1515 input_type : String ,
16- validate : Validation ::InputValidator . new ( Validators ::Url )
16+ validate : Validation ::InputValidator . new ( Validators ::Uri )
1717 field "email" ,
1818 input_type : String ,
1919 validate : Validation ::InputValidator . new ( Validators ::Email )
Original file line number Diff line number Diff line change 22
33require "openapi3_parser/node_factory/object"
44require "openapi3_parser/validation/input_validator"
5- require "openapi3_parser/validators/url "
5+ require "openapi3_parser/validators/uri "
66
77module Openapi3Parser
88 module NodeFactory
@@ -14,7 +14,7 @@ class Example < NodeFactory::Object
1414 field "value"
1515 field "externalValue" ,
1616 input_type : String ,
17- validate : Validation ::InputValidator . new ( Validators ::Url )
17+ validate : Validation ::InputValidator . new ( Validators ::Uri )
1818
1919 mutually_exclusive "value" , "externalValue"
2020
Original file line number Diff line number Diff line change 22
33require "openapi3_parser/node_factory/object"
44require "openapi3_parser/validation/input_validator"
5- require "openapi3_parser/validators/url "
5+ require "openapi3_parser/validators/uri "
66
77module Openapi3Parser
88 module NodeFactory
@@ -13,7 +13,7 @@ class ExternalDocumentation < NodeFactory::Object
1313 field "url" ,
1414 required : true ,
1515 input_type : String ,
16- validate : Validation ::InputValidator . new ( Validators ::Url )
16+ validate : Validation ::InputValidator . new ( Validators ::Uri )
1717
1818 def build_node ( data , node_context )
1919 Node ::ExternalDocumentation . new ( data , node_context )
Original file line number Diff line number Diff line change 44require "openapi3_parser/node_factory/license"
55require "openapi3_parser/node_factory/object"
66require "openapi3_parser/validation/input_validator"
7- require "openapi3_parser/validators/url "
7+ require "openapi3_parser/validators/uri "
88
99module Openapi3Parser
1010 module NodeFactory
@@ -17,7 +17,7 @@ class Info < NodeFactory::Object
1717 field "description" , input_type : String
1818 field "termsOfService" ,
1919 input_type : String ,
20- validate : Validation ::InputValidator . new ( Validators ::Url )
20+ validate : Validation ::InputValidator . new ( Validators ::Uri )
2121 field "contact" , factory : NodeFactory ::Contact
2222 field "license" , factory : NodeFactory ::License
2323 field "version" , input_type : String , required : true
Original file line number Diff line number Diff line change 22
33require "openapi3_parser/node_factory/object"
44require "openapi3_parser/validation/input_validator"
5- require "openapi3_parser/validators/url "
5+ require "openapi3_parser/validators/uri "
66
77module Openapi3Parser
88 module NodeFactory
@@ -14,7 +14,7 @@ class License < NodeFactory::Object
1414 allowed : -> ( context ) { context . openapi_version >= "3.1" }
1515 field "url" ,
1616 input_type : String ,
17- validate : Validation ::InputValidator . new ( Validators ::Url )
17+ validate : Validation ::InputValidator . new ( Validators ::Uri )
1818 mutually_exclusive "identifier" , "url"
1919
2020 def build_node ( data , node_context )
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ class Openapi < NodeFactory::Object
1313
1414 field "openapi" , input_type : String , required : true
1515 field "info" , factory : NodeFactory ::Info , required : true
16+ field "jsonSchemaDialect" ,
17+ default : "https://spec.openapis.org/oas/3.1/dialect/base" ,
18+ input_type : String ,
19+ allowed : -> ( context ) { context . openapi_version >= "3.1" }
1620 field "servers" , factory : :servers_factory
1721 field "paths" ,
1822 factory : NodeFactory ::Paths ,
Original file line number Diff line number Diff line change 22
33module Openapi3Parser
44 module Validators
5- class Url
5+ class Uri
66 def self . call ( input )
77 URI . parse ( input ) && nil
88 rescue URI ::InvalidURIError
9- %("#{ input } " is not a valid URL )
9+ %("#{ input } " is not a valid URI )
1010 end
1111 end
1212 end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . describe Openapi3Parser ::Validators ::Uri do
4+ describe ".call" do
5+ it "returns nil for a valid URI" do
6+ expect ( described_class . call ( "https://example.org/resource" ) )
7+ . to be_nil
8+ end
9+
10+ it "returns an error for an invalid URI" do
11+ expect ( described_class . call ( "not a URI" ) )
12+ . to eq %("not a URI" is not a valid URI)
13+ end
14+ end
15+ end
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments