Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Add OpenAPI 3 Support #203

Merged
merged 2 commits into from
Jan 18, 2019
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
1 change: 1 addition & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fury = require('fury');

fury.use(require('fury-adapter-apib-parser'));
fury.use(require('fury-adapter-swagger'));
fury.use(require('fury-adapter-oas3-parser'));

function createWarning(message) {
const annotationElement = new fury.minim.elements.Annotation(message);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"fury": "3.0.0-beta.8",
"fury-adapter-apib-parser": "0.12.0",
"fury-adapter-oas3-parser": "0.3.0",
"fury-adapter-swagger": "0.23.1",
"uri-template": "1.0.1"
},
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const fromFile = filename => fs.readFileSync(path.join(__dirname, filename)).toS
const FORMAT_NAMES = {
apib: 'API Blueprint',
openapi2: 'OpenAPI 2',
openapi3: 'OpenAPI 3',
};

// Fixture factory. Makes sure the fixtures are available both as an iterable
Expand Down Expand Up @@ -62,6 +63,7 @@ const fixtures = {
empty: fixture({
apib: '',
openapi2: '',
openapi3: '',
}),
ordinary: fixture({
apib: fromFile('./apib/ordinary.apib'),
Expand Down Expand Up @@ -194,6 +196,11 @@ const fixtures = {
defaultResponse: fixture({
openapi2: fromFile('./openapi2/default-response.yml'),
}),

// Specific to OpenAPI 3
proofOfConcept: fixture({
openapi3: fromFile('./openapi3/proof-of-concept.yml'),
}),
};

module.exports = fixtures;
109 changes: 109 additions & 0 deletions test/fixtures/openapi3/proof-of-concept.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
24 changes: 24 additions & 0 deletions test/integration/compile-openapi3-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const createCompilationResultSchema = require('../schemas/compilation-result');
const fixtures = require('../fixtures');

const { assert, compileFixture } = require('../utils');

describe('compile() · OpenAPI 3', () => {
describe('ordinary, valid API description', () => {
let compilationResult;

before((done) => {
compileFixture(fixtures.proofOfConcept.openapi3, (err, result) => {
compilationResult = result;
done(err);
});
});

it('produces some annotation and some transactions', () => {
assert.jsonSchema(compilationResult, createCompilationResultSchema({
annotations: [1],
transactions: [1],
}));
});
});
});