Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/sl 2029/graphite upgrade #191

Merged
merged 4 commits into from
Mar 12, 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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"node": ">=8"
},
"dependencies": {
"@stoplight/graphite": "1.7.x",
"@stoplight/graphite": "3.5.x",
"lodash": "4.x.x",
"tslib": "1.9.x"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/utils/graphFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createOas2HttpPlugin } from '@stoplight/graphite/plugins/http/oas2';
import { createOas3HttpPlugin } from '@stoplight/graphite/plugins/http/oas3';
import { createJsonPlugin } from '@stoplight/graphite/plugins/json';
import { createOas2Plugin } from '@stoplight/graphite/plugins/oas2';
import { createYamlPlugin } from '@stoplight/graphite/plugins/yaml';
import { IHttpOperation } from '@stoplight/types';
import * as fs from 'fs';
import { extname, join } from 'path';
Expand All @@ -19,18 +20,17 @@ import compact = require('lodash/compact');
export class GraphFacade {
private fsBackend: FileSystemBackend;
private graphite: IGraphite;
private cwd: string;

constructor() {
const graphite = (this.graphite = createGraphite());
graphite.registerPlugins(
createJsonPlugin(),
createYamlPlugin(),
createOas2Plugin(),
createOas2HttpPlugin(),
createOas3HttpPlugin()
);
this.cwd = process.cwd();
this.fsBackend = createFileSystemBackend(this.cwd, graphite, fs);
this.fsBackend = createFileSystemBackend(graphite, fs);
}

public async createFilesystemNode(fsPath: string | undefined) {
Expand All @@ -42,25 +42,25 @@ export class GraphFacade {
this.graphite.graph.addNode({
category: NodeCategory.Source,
type: FilesystemNodeType.Directory,
path: fsPath,
path: resourceFile,
});
this.fsBackend.readdir(fsPath);
} else if (stat.isFile()) {
this.graphite.graph.addNode({
category: NodeCategory.Source,
type: FilesystemNodeType.File,
subtype,
path: fsPath,
path: resourceFile,
});
this.fsBackend.readFile(fsPath);
this.fsBackend.readFile(resourceFile);
}
return this.graphite.scheduler.drain();
}
return null;
}

get httpOperations(): IHttpOperation[] {
const nodes = this.graphite.graph.virtualNodes.filter(node => node.type === 'http-operation');
const nodes = this.graphite.graph.virtualNodes.filter(node => node.type === 'http_operation');
return compact(nodes.map<IHttpOperation>(node => node.data as IHttpOperation));
}
}
188 changes: 188 additions & 0 deletions packages/http/src/__tests__/fixtures/petstore.oas2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
swagger: "2.0"
info:
description: "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters."
version: 1.0.0
title: Swagger Petstore
termsOfService: "http://swagger.io/terms/"
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: petstore.swagger.io
basePath: /v2
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: "http://swagger.io"
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: "http://swagger.io"
schemes:
- https
- http
paths:
/pets:
post:
tags:
- pet
summary: Add a new pet to the store
description: ""
operationId: addPet
consumes:
- application/json
- application/xml
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
$ref: "#/definitions/Pet"
responses:
"405":
description: Invalid input
security:
- petstore_auth:
- "write:pets"
- "read:pets"
get:
responses:
"200":
description: ""
schema:
type: object
properties: {}
summary: List pets
parameters:
- $ref: "#/parameters/skip"
- $ref: "#/parameters/limit"
- $ref: "#/parameters/rate-limit"
"/pet/{petId}":
parameters:
- $ref: "#/parameters/pet-id"
put:
tags:
- pet
summary: Update an existing pet
description: ""
operationId: updatePet
consumes:
- application/json
- application/xml
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
$ref: "#/definitions/Pet"
responses:
"400":
description: Invalid ID supplied
"404":
$ref: "#/responses/404"
"405":
description: Validation exception
security:
- petstore_auth:
- "write:pets"
- "read:pets"
securityDefinitions:
petstore_auth:
type: oauth2
authorizationUrl: "https://petstore.swagger.io/oauth/dialog"
flow: implicit
scopes:
"write:pets": modify pets in your account
"read:pets": read your pets
api_key:
type: apiKey
name: api_key
in: header
definitions:
Pet:
type: object
xml:
name: Pet
properties:
id:
type: integer
format: int64
category:
$ref: "#/definitions/Category"
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
required:
- name
- photoUrls
Error:
type: object
properties:
code:
type: string
message:
type: string
required:
- code
Category:
type: object
properties:
name:
type: string
required:
- name
title: Category
externalDocs:
description: Find out more about Swagger
url: "http://swagger.io"
parameters:
skip:
in: query
type: string
name: skip
rate-limit:
name: Rate-Limit
in: header
type: string
limit:
name: limit
in: query
type: string
pet-id:
name: petId
in: path
type: string
required: true
responses:
"404":
description: Our shared 404 response.
schema:
$ref: "#/definitions/Error"
11 changes: 10 additions & 1 deletion packages/http/src/__tests__/http-prism-instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('Http Prism Instance function tests', () => {
});
});

test("should forward the request correclty even if resources haven't been provided", async () => {
test("should forward the request correctly even if resources haven't been provided", async () => {
// Recreate Prism with no loaded document
prism = createInstance({ forwarder, router: undefined, mocker: undefined });

Expand All @@ -122,4 +122,13 @@ describe('Http Prism Instance function tests', () => {
output: [],
});
});

test('loads spec provided in yaml', async () => {
prism = createInstance();
await prism.load({
path: relative(process.cwd(), resolve(__dirname, 'fixtures', 'petstore.oas2.yaml')),
});

expect(prism.resources).toHaveLength(5);
});
});
Loading