Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Accept loading OAD documents with numeric status codes. Fixes "Unknown reference" error. https://github.com/ahx/openapi_first/issues/367

- Support QUERY request method
OpenAPI 3.0, 3.1 does not support that, but this does

Expand Down
3 changes: 2 additions & 1 deletion lib/openapi_first.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def self.load(filepath_or_definition, only: nil, &)

# Parse a dereferenced Hash
# @return [Definition]
# TODO: This needs to work with unresolved contents as well
def self.parse(contents, only: nil, filepath: nil, &)
# TODO: This needs to work with unresolved contents as well
contents = JSON.parse(JSON.generate(contents)) # Deeply stringify keys, because of YAML. See https://github.com/ahx/openapi_first/issues/367
contents['paths'].filter!(&->(key, _) { only.call(key) }) if only
Definition.new(contents, filepath, &)
end
Expand Down
1 change: 1 addition & 0 deletions lib/openapi_first/file_loader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'json'
require 'yaml'

module OpenapiFirst
Expand Down
27 changes: 27 additions & 0 deletions spec/data/numeric-status.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
openapi: 3.0.2
info:
title: Acme Control API
version: 0.0.1
paths:
/roles:
get:
responses:
200:
content:
application/json:
schema:
type: object
/roles/query:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
200:
content:
application/json:
schema:
$ref: '#/paths/~1roles/get/responses/200/content/application~1json/schema'
5 changes: 5 additions & 0 deletions spec/openapi_first_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
expect(definition.paths).to include('/foo')
end

it 'works with numeric statuses' do
definition = OpenapiFirst.load('./spec/data/numeric-status.yaml')
expect(definition.paths).to include('/roles')
end

it 'works with YAML' do
definition = OpenapiFirst.load('./spec/data/petstore.yaml')
expect(definition.paths).to include('/pets')
Expand Down