From 8ebe9343896f9118c43d7b371cb21e338c5eadeb Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Tue, 8 Jan 2019 15:10:05 +0100 Subject: [PATCH 1/2] feat: add OAS3 support --- lib/parse.js | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/parse.js b/lib/parse.js index df99d57..6bf7838 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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); diff --git a/package.json b/package.json index 3222c70..08de775 100644 --- a/package.json +++ b/package.json @@ -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" }, From 0b555f84ed6245c9a867820487bac1eb7bb13c24 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Tue, 8 Jan 2019 20:35:46 +0100 Subject: [PATCH 2/2] test: try to compile transactions from OpenAPI 3 --- test/fixtures/index.js | 7 ++ test/fixtures/openapi3/proof-of-concept.yml | 109 ++++++++++++++++++++ test/integration/compile-openapi3-test.js | 24 +++++ 3 files changed, 140 insertions(+) create mode 100644 test/fixtures/openapi3/proof-of-concept.yml create mode 100644 test/integration/compile-openapi3-test.js diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 394a340..f2e26af 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -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 @@ -62,6 +63,7 @@ const fixtures = { empty: fixture({ apib: '', openapi2: '', + openapi3: '', }), ordinary: fixture({ apib: fromFile('./apib/ordinary.apib'), @@ -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; diff --git a/test/fixtures/openapi3/proof-of-concept.yml b/test/fixtures/openapi3/proof-of-concept.yml new file mode 100644 index 0000000..f47e438 --- /dev/null +++ b/test/fixtures/openapi3/proof-of-concept.yml @@ -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 diff --git a/test/integration/compile-openapi3-test.js b/test/integration/compile-openapi3-test.js new file mode 100644 index 0000000..6bf94bf --- /dev/null +++ b/test/integration/compile-openapi3-test.js @@ -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], + })); + }); + }); +});