Merge pull request #552 from postmanlabs/feature/oneOfAnyOfAndNotTests30

Adding tests to 3.0
This commit is contained in:
Carlos-Veloz
2022-06-15 08:48:32 -05:00
committed by GitHub
12 changed files with 458 additions and 1 deletions

View File

@@ -0,0 +1,81 @@
{
"openapi": "3.0.0",
"info": {
"title": "Sample API",
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
"version": "0.1.9"
},
"servers": [
{
"url": "http://api.example.com/v1",
"description": "Optional server description, e.g. Main (production) server"
},
{
"url": "http://staging-api.example.com",
"description": "Optional server description, e.g. Internal staging server for testing"
}
],
"paths": {
"/users/{userId}": {
"get": {
"summary": "Get a user by ID",
"responses": {
"200": {
"description": "A single user.",
"content": {
"application/json": {
"schema": {
"anyOf": [
{
"$ref": "#/components/schemas/_schemas_pet.yaml"
},
{
"type": "object",
"properties": {
"testString": {
"type": "string"
},
"testNumber": {
"type": "integer"
}
}
},
{
"$ref": "#/components/schemas/_schemas_user.yaml"
}
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"_schemas_pet.yaml": {
"type": "object",
"properties": {
"petId": {
"type": "integer"
},
"petName": {
"type": "string"
}
}
},
"_schemas_user.yaml": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"userName": {
"type": "string"
}
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
openapi: 3.0.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 0.1.9
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/users/{userId}:
get:
summary: Get a user by ID
responses:
200:
description: A single user.
content:
application/json:
schema:
anyOf:
- $ref: "./schemas/pet.yaml"
- type: object
properties:
testString:
type: string
testNumber:
type: integer
- $ref: "./schemas/user.yaml"

View File

@@ -0,0 +1,6 @@
type: object
properties:
petId:
type: integer
petName:
type: string

View File

@@ -0,0 +1,6 @@
type: object
properties:
id:
type: integer
userName:
type: string

View File

@@ -0,0 +1,63 @@
{
"openapi": "3.0.0",
"info": {
"title": "Sample API",
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
"version": "0.1.9"
},
"servers": [
{
"url": "http://api.example.com/v1",
"description": "Optional server description, e.g. Main (production) server"
},
{
"url": "http://staging-api.example.com",
"description": "Optional server description, e.g. Internal staging server for testing"
}
],
"paths": {
"/users/{userId}": {
"get": {
"summary": "Get a user by ID",
"responses": {
"200": {
"description": "A single user.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"client": {
"type": "object",
"not": {
"$ref": "#/components/schemas/_schemas_user.yaml"
}
}
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"_schemas_user.yaml": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"userName": {
"type": "string"
}
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
openapi: 3.0.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 0.1.9
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/users/{userId}:
get:
summary: Get a user by ID
responses:
200:
description: A single user.
content:
application/json:
schema:
type: object
properties:
id:
type: integer
client:
type: object
not:
$ref: "./schemas/user.yaml"

View File

@@ -0,0 +1,6 @@
type: object
properties:
id:
type: integer
userName:
type: string

View File

@@ -0,0 +1,81 @@
{
"openapi": "3.0.0",
"info": {
"title": "Sample API",
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
"version": "0.1.9"
},
"servers": [
{
"url": "http://api.example.com/v1",
"description": "Optional server description, e.g. Main (production) server"
},
{
"url": "http://staging-api.example.com",
"description": "Optional server description, e.g. Internal staging server for testing"
}
],
"paths": {
"/users/{userId}": {
"get": {
"summary": "Get a user by ID",
"responses": {
"200": {
"description": "A single user.",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/_schemas_pet.yaml"
},
{
"type": "object",
"properties": {
"testString": {
"type": "string"
},
"testNumber": {
"type": "integer"
}
}
},
{
"$ref": "#/components/schemas/_schemas_user.yaml"
}
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"_schemas_pet.yaml": {
"type": "object",
"properties": {
"petId": {
"type": "integer"
},
"petName": {
"type": "string"
}
}
},
"_schemas_user.yaml": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"userName": {
"type": "string"
}
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
openapi: 3.0.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 0.1.9
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/users/{userId}:
get:
summary: Get a user by ID
responses:
200:
description: A single user.
content:
application/json:
schema:
oneOf:
- $ref: "./schemas/pet.yaml"
- type: object
properties:
testString:
type: string
testNumber:
type: integer
- $ref: "./schemas/user.yaml"

View File

@@ -0,0 +1,6 @@
type: object
properties:
petId:
type: integer
petName:
type: string

View File

@@ -0,0 +1,6 @@
type: object
properties:
id:
type: integer
userName:
type: string

View File

@@ -34,7 +34,10 @@ let expect = require('chai').expect,
referencedLink = path.join(__dirname, BUNDLES_FOLDER + '/referenced_link'),
referencedCallback = path.join(__dirname, BUNDLES_FOLDER + '/referenced_callback'),
referencedSecuritySchemes = path.join(__dirname, BUNDLES_FOLDER + '/referenced_security_schemes'),
additionalProperties = path.join(__dirname, BUNDLES_FOLDER + '/additionalProperties');
additionalProperties = path.join(__dirname, BUNDLES_FOLDER + '/additionalProperties'),
compositeOneOf = path.join(__dirname, BUNDLES_FOLDER + '/composite_oneOf'),
compositeNot = path.join(__dirname, BUNDLES_FOLDER + '/composite_not'),
compositeAnyOf = path.join(__dirname, BUNDLES_FOLDER + '/composite_anyOf');
describe('bundle files method - 3.0', function () {
@@ -1789,6 +1792,112 @@ describe('bundle files method - 3.0', function () {
expect(res.result).to.be.true;
expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected);
});
it('Should bundle composite file with oneOf - composite_oneOf', async function() {
let contentRoot = fs.readFileSync(compositeOneOf + '/root.yaml', 'utf8'),
pet = fs.readFileSync(compositeOneOf + '/schemas/pet.yaml', 'utf8'),
user = fs.readFileSync(compositeOneOf + '/schemas/user.yaml', 'utf8'),
expected = fs.readFileSync(compositeOneOf + '/expected.json', 'utf8'),
input = {
type: 'multiFile',
specificationVersion: '3.0',
rootFiles: [
{
path: '/root.yaml'
}
],
data: [
{
path: '/root.yaml',
content: contentRoot
},
{
path: '/schemas/pet.yaml',
content: pet
},
{
path: '/schemas/user.yaml',
content: user
}
],
options: {},
bundleFormat: 'JSON'
};
const res = await Converter.bundle(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected);
});
it('Should bundle composite file with anyOf - composite_anyOf', async function() {
let contentRoot = fs.readFileSync(compositeAnyOf + '/root.yaml', 'utf8'),
pet = fs.readFileSync(compositeAnyOf + '/schemas/pet.yaml', 'utf8'),
user = fs.readFileSync(compositeAnyOf + '/schemas/user.yaml', 'utf8'),
expected = fs.readFileSync(compositeAnyOf + '/expected.json', 'utf8'),
input = {
type: 'multiFile',
specificationVersion: '3.0',
rootFiles: [
{
path: '/root.yaml'
}
],
data: [
{
path: '/root.yaml',
content: contentRoot
},
{
path: '/schemas/pet.yaml',
content: pet
},
{
path: '/schemas/user.yaml',
content: user
}
],
options: {},
bundleFormat: 'JSON'
};
const res = await Converter.bundle(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected);
});
it('Should bundle composite file with not - composite_not', async function() {
let contentRoot = fs.readFileSync(compositeNot + '/root.yaml', 'utf8'),
user = fs.readFileSync(compositeNot + '/schemas/user.yaml', 'utf8'),
expected = fs.readFileSync(compositeNot + '/expected.json', 'utf8'),
input = {
type: 'multiFile',
specificationVersion: '3.0',
rootFiles: [
{
path: '/root.yaml'
}
],
data: [
{
path: '/root.yaml',
content: contentRoot
},
{
path: '/schemas/user.yaml',
content: user
}
],
options: {},
bundleFormat: 'JSON'
};
const res = await Converter.bundle(input);
expect(res).to.not.be.empty;
expect(res.result).to.be.true;
expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected);
});
});