Module: OpenAPIParser

Defined in:
lib/openapi_parser.rb,
lib/openapi_parser/errors.rb,
lib/openapi_parser/version.rb

Defined Under Namespace

Modules: Expandable, Findable, MediaTypeSelectable, ParameterValidatable, Parser, Schemas Classes: Config, InvalidEmailFormat, InvalidPattern, InvalidUUIDFormat, LessThanExclusiveMinimum, LessThanMinItems, LessThanMinLength, LessThanMinimum, MoreThanExclusiveMaximum, MoreThanMaxItems, MoreThanMaxLength, MoreThanMaximum, NotAnyOf, NotEnumInclude, NotExistContentTypeDefinition, NotExistDiscriminatorMappedSchema, NotExistDiscriminatorPropertyName, NotExistPropertyDefinition, NotExistRequiredKey, NotExistStatusCodeDefinition, NotNullError, NotOneOf, OpenAPIError, ParameterValidator, PathItemFinder, ReferenceExpander, RequestOperation, SchemaLoader, SchemaValidator, ValidateError

Constant Summary collapse

VERSION =
'0.10.0'.freeze

Class Method Summary collapse

Class Method Details

.load(filepath, config = {}) ⇒ OpenAPIParser::Schemas::OpenAPI

Load schema in specified filepath. If file path is relative, it is resolved using working directory.



29
30
31
32
33
# File 'lib/openapi_parser.rb', line 29

def load(filepath, config = {})
  path = Pathname.new(filepath)
  path = Pathname.getwd + path if path.relative?
  load_uri(URI.join("file:///",  path.to_s), config: Config.new(config), schema_registry: {})
end

.load_uri(uri, config:, schema_registry:) ⇒ OpenAPIParser::Schemas::OpenAPI

Load schema located by the passed uri. Uri must be absolute.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/openapi_parser.rb', line 37

def load_uri(uri, config:, schema_registry:)
  # Open-uri doesn't open file scheme uri, so we try to open file path directly
  # File scheme uri which points to a remote file is not supported.
  content = if uri.scheme == 'file'
    open(uri.path, &:read)
  else
    uri.open(&:read)
  end

  extension = Pathname.new(uri.path).extname
  load_hash(parse_file(content, extension), config: config, uri: uri, schema_registry: schema_registry)
end

.parse(schema, config = {}) ⇒ OpenAPIParser::Schemas::OpenAPI

Load schema yaml object. Uri is not set for returned schema.



23
24
25
# File 'lib/openapi_parser.rb', line 23

def parse(schema, config = {})
  load_hash(schema, config: Config.new(config), uri: nil, schema_registry: {})
end