Skip to content

Commit d5a6106

Browse files
authored
Merge pull request #369 from ahx/fix-loading-numeric-status-yaml
Deeply stringify keys, because of YAML
2 parents 57ec649 + cd1a52d commit d5a6106

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Accept loading OAD documents with numeric status codes. Fixes "Unknown reference" error. https://github.com/ahx/openapi_first/issues/367
6+
57
- Support QUERY request method
68
OpenAPI 3.0, 3.1 does not support that, but this does
79

lib/openapi_first.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ def self.load(filepath_or_definition, only: nil, &)
6464

6565
# Parse a dereferenced Hash
6666
# @return [Definition]
67+
# TODO: This needs to work with unresolved contents as well
6768
def self.parse(contents, only: nil, filepath: nil, &)
68-
# TODO: This needs to work with unresolved contents as well
69+
contents = JSON.parse(JSON.generate(contents)) # Deeply stringify keys, because of YAML. See https://github.com/ahx/openapi_first/issues/367
6970
contents['paths'].filter!(&->(key, _) { only.call(key) }) if only
7071
Definition.new(contents, filepath, &)
7172
end

lib/openapi_first/file_loader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'json'
34
require 'yaml'
45

56
module OpenapiFirst

spec/data/numeric-status.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
openapi: 3.0.2
2+
info:
3+
title: Acme Control API
4+
version: 0.0.1
5+
paths:
6+
/roles:
7+
get:
8+
responses:
9+
200:
10+
content:
11+
application/json:
12+
schema:
13+
type: object
14+
/roles/query:
15+
post:
16+
requestBody:
17+
required: true
18+
content:
19+
application/json:
20+
schema:
21+
type: object
22+
responses:
23+
200:
24+
content:
25+
application/json:
26+
schema:
27+
$ref: '#/paths/~1roles/get/responses/200/content/application~1json/schema'

spec/openapi_first_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
expect(definition.paths).to include('/foo')
4848
end
4949

50+
it 'works with numeric statuses' do
51+
definition = OpenapiFirst.load('./spec/data/numeric-status.yaml')
52+
expect(definition.paths).to include('/roles')
53+
end
54+
5055
it 'works with YAML' do
5156
definition = OpenapiFirst.load('./spec/data/petstore.yaml')
5257
expect(definition.paths).to include('/pets')

0 commit comments

Comments
 (0)