-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from moneymeets/feature/fix-reference-resolver
Feature/fix reference resolver
- Loading branch information
Showing
12 changed files
with
282 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
100 changes: 100 additions & 0 deletions
100
tests/parsers/resolver/test_data/local_references/expected_output/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"components": { | ||
"parameters": { | ||
"CommentId": { | ||
"in": "path", | ||
"name": "commentId", | ||
"required": true, | ||
"schema": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"schemas": { | ||
"Comment": { | ||
"properties": { | ||
"author": { | ||
"properties": { | ||
"email": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object", | ||
"x-schema-name": "User" | ||
}, | ||
"text": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"User": { | ||
"properties": { | ||
"email": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
} | ||
}, | ||
"info": { | ||
"title": "Example API", | ||
"version": "1.0" | ||
}, | ||
"openapi": "3.0.0", | ||
"paths": { | ||
"/comment{commentId}": { | ||
"get": { | ||
"operationId": "getComment", | ||
"parameters": [ | ||
{ | ||
"in": "path", | ||
"name": "commentId", | ||
"required": true, | ||
"schema": { | ||
"type": "integer" | ||
}, | ||
"x-schema-name": "CommentId" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"properties": { | ||
"author": { | ||
"properties": { | ||
"email": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object", | ||
"x-schema-name": "User" | ||
}, | ||
"text": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object", | ||
"x-schema-name": "Comment" | ||
} | ||
} | ||
}, | ||
"description": "Successful response" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/parsers/resolver/test_data/local_references/input/api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
openapi: 3.0.0 | ||
|
||
info: | ||
title: Example API | ||
version: '1.0' | ||
|
||
paths: | ||
/comment{commentId}: | ||
get: | ||
operationId: getComment | ||
parameters: | ||
- $ref: '#/components/parameters/CommentId' | ||
responses: | ||
'200': | ||
description: Successful response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Comment' | ||
|
||
components: | ||
parameters: | ||
CommentId: | ||
name: commentId | ||
in: path | ||
required: true | ||
schema: | ||
type: integer | ||
|
||
schemas: | ||
Comment: | ||
type: object | ||
properties: | ||
text: | ||
type: string | ||
author: | ||
$ref: '#/components/schemas/User' | ||
|
||
User: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
email: | ||
type: string |
60 changes: 60 additions & 0 deletions
60
tests/parsers/resolver/test_data/remote_references/expected_output/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"info": { | ||
"title": "Example API", | ||
"version": "1.0" | ||
}, | ||
"openapi": "3.0.0", | ||
"paths": { | ||
"/comment{commentId}": { | ||
"get": { | ||
"operationId": "getComment", | ||
"parameters": [ | ||
{ | ||
"in": "path", | ||
"name": "commentId", | ||
"required": true, | ||
"schema": { | ||
"type": "integer" | ||
}, | ||
"x-schema-name": "CommentId" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"properties": { | ||
"author": { | ||
"properties": { | ||
"city": { | ||
"maxLength": 50, | ||
"type": "string", | ||
"x-schema-name": "City" | ||
}, | ||
"email": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object", | ||
"x-schema-name": "User" | ||
}, | ||
"text": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object", | ||
"x-schema-name": "Comment" | ||
} | ||
} | ||
}, | ||
"description": "Successful response" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/parsers/resolver/test_data/remote_references/input/api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
openapi: 3.0.0 | ||
|
||
info: | ||
title: Example API | ||
version: '1.0' | ||
|
||
paths: | ||
/comment{commentId}: | ||
get: | ||
operationId: getComment | ||
parameters: | ||
- $ref: 'definitions/parameters.yml#/components/parameters/CommentId' | ||
responses: | ||
'200': | ||
description: Successful response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: 'definitions/schemas.yml#/components/schemas/Comment' |
8 changes: 8 additions & 0 deletions
8
tests/parsers/resolver/test_data/remote_references/input/definitions/parameters.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
components: | ||
parameters: | ||
CommentId: | ||
name: commentId | ||
in: path | ||
required: true | ||
schema: | ||
type: integer |
9 changes: 9 additions & 0 deletions
9
tests/parsers/resolver/test_data/remote_references/input/definitions/schemas.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
components: | ||
schemas: | ||
Comment: | ||
type: object | ||
properties: | ||
text: | ||
type: string | ||
author: | ||
$ref: 'users/user.yml#/components/schemas/User' |
5 changes: 5 additions & 0 deletions
5
tests/parsers/resolver/test_data/remote_references/input/definitions/users/location.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
components: | ||
schemas: | ||
City: | ||
type: string | ||
maxLength: 50 |
11 changes: 11 additions & 0 deletions
11
tests/parsers/resolver/test_data/remote_references/input/definitions/users/user.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
components: | ||
schemas: | ||
User: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
email: | ||
type: string | ||
city: | ||
$ref: './location.yml#/components/schemas/City' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from spec2sdk.parsers.resolver import ResolvingParser | ||
|
||
TEST_DATA_DIR = Path(__file__).parent / "test_data" | ||
|
||
|
||
@pytest.mark.parametrize("test_data_name", ("local_references", "remote_references")) | ||
def test_resolve_references(test_data_name: str): | ||
data_dir = TEST_DATA_DIR / test_data_name | ||
input_spec = data_dir / "input" / "api.yml" | ||
expected_schema = json.loads((data_dir / "expected_output" / "schema.json").read_text()) | ||
|
||
assert ( | ||
ResolvingParser(base_path=input_spec.parent).parse( | ||
relative_filepath=input_spec.relative_to(input_spec.parent), | ||
) | ||
== expected_schema | ||
) |