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

SO-141 Problem+Json for error messages SO-141 #270

Merged
merged 29 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
590df00
chore: update deps
XVincentX May 7, 2019
f1e5b92
chore: update typescript
XVincentX May 7, 2019
6648382
feat: create problemJson constructor
XVincentX May 7, 2019
d2b3d4b
feat: create serializer for problem/json
XVincentX May 7, 2019
241653e
feat: return problem jsons for route errors
XVincentX May 7, 2019
af30af4
refactor: move problemjson to http package
XVincentX May 7, 2019
a757346
test: check with error title
XVincentX May 7, 2019
3c6a0d1
refactor: use typescript inferring and fluent reply
XVincentX May 7, 2019
9c3a801
refactor: prefer unknown
XVincentX May 7, 2019
16a934a
feat: replace 400 error for missing invalid response with problem/json
XVincentX May 7, 2019
5a0f3ca
feat: replace 400 error for missing invalid response with problem/json
XVincentX May 7, 2019
d2e8b43
refactor: from template static function
XVincentX May 7, 2019
d2bfc30
test: refactor test to use template functin
XVincentX May 7, 2019
00ea9ad
refactor: correctly type problem+json
XVincentX May 7, 2019
a1c5d2a
refactor: no any
XVincentX May 7, 2019
c7f929c
refactor: avoid casts
XVincentX May 7, 2019
c86fe43
refactor: use tsling-stoplight rules
XVincentX May 7, 2019
1dd8953
chore: graphite update
XVincentX May 7, 2019
5b0080c
chore: .x.x
XVincentX May 7, 2019
6e118b1
refactor: do not be too specific on what's wrong
XVincentX May 7, 2019
84b284b
fix: correct status code is 422
XVincentX May 7, 2019
edeed95
refactor: use template ProblemJson
chris-miaskowski May 8, 2019
aa1ad02
refactor: UNPROCESSABLE_ENTITY
XVincentX May 8, 2019
4c7760b
refactor: use https link errors
XVincentX May 8, 2019
531ff60
refactor: remove custom serialiser
XVincentX May 8, 2019
8091c09
chore: caret
XVincentX May 8, 2019
ee4cf7d
style: format
XVincentX May 8, 2019
cb18613
refactor: detail is always set
XVincentX May 8, 2019
5cced33
refactor: bring url logic in the class
XVincentX May 8, 2019
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
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@
"release": "lerna version prerelease --conventional-commit"
},
"devDependencies": {
"@stoplight/types": "4.x.x",
"@types/chance": "1.0.x",
"@types/jest": "24.x.x",
"@types/node": "11.x.x",
"chance": "1.0.x",
"jest": "24.x.x",
"lerna": "3.13.3",
"ts-jest": "24.x.x",
"tslint": "5.16.0",
"tslint-config-stoplight": "1.2.x",
XVincentX marked this conversation as resolved.
Show resolved Hide resolved
"tslint-eslint-rules": "5.4.x",
"typescript": "3.x.x"
"@stoplight/types": "^4.0.0",
"@types/chance": "^1.0.0",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"chance": "^1.0.0",
"jest": "^24.0.0",
"lerna": "^3.0.0",
"ts-jest": "^24.0.0",
"tslint": "^5.0.0",
"tslint-config-stoplight": "^1.0.0",
"typescript": "^3.0.0"
},
"prettier": {
"printWidth": 100,
Expand Down
24 changes: 12 additions & 12 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
},
"bugs": "https://github.com/stoplightio/prism/issues",
"dependencies": {
"@oclif/command": "1.x.x",
"@oclif/config": "1.12.12",
"@oclif/plugin-help": "2.x.x",
"@oclif/command": "^1.0.0",
"@oclif/config": "^1.12.12",
"@oclif/plugin-help": "^2.0.0",
"@stoplight/prism-core": "^3.0.0-pre.2",
"@stoplight/prism-http-server": "^3.0.0-pre.2",
"tslib": "1.x.x"
"tslib": "^1.0.0"
},
"devDependencies": {
"@oclif/dev-cli": "1.22.0",
"@oclif/tslint": "3.x.x",
"@types/chai": "4.x.x",
"@types/node": "11.13.4",
"globby": "9.2.0",
"ts-node": "8.1.0",
"tsconfig-paths": "^3.8.0",
"typescript": "^3.4.2"
"@oclif/dev-cli": "^1.0.0",
"@oclif/tslint": "^3.0.0",
"@types/chai": "^4.0.0",
"@types/node": "^12.0.0",
"globby": "^9.0.0",
"ts-node": "^8.0.0",
"tsconfig-paths": "^3.0.0",
"typescript": "^3.0.5"
},
"engines": {
"node": ">=8.0.0"
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/util/__tests__/createServer.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ describe('server command', () => {
test('starts filesystem server variant', async () => {
createServer('/path/to', { mock: true });

expect(createPrismServer).toHaveBeenLastCalledWith(
{ path: '/path/to' },
{ config: { mock: true } }
);
expect(createPrismServer).toHaveBeenLastCalledWith({ path: '/path/to' }, { config: { mock: true } });
});

test('starts http server variant', async () => {
createServer('http://path.to/spec.oas2.yaml', { mock: false });

expect(createPrismServer).toHaveBeenLastCalledWith(
{ url: 'http://path.to/spec.oas2.yaml' },
{ components: { loader: expect.any(HttpLoader) }, config: { mock: false } }
{ components: { loader: expect.any(HttpLoader) }, config: { mock: false } },
);
});
});
12 changes: 6 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"node": ">=8"
},
"dependencies": {
"@stoplight/graphite": "5.2.0",
"axios": "0.x.x",
"lodash": "4.x.x",
"mobx": "5.x.x",
"tslib": "1.9.x"
"@stoplight/graphite": "^6.3.1",
"axios": "^0.18.0",
"lodash": "^4.0.0",
"mobx": "^5.0.0",
"tslib": "^1.9.0"
},
"devDependencies": {
"@types/lodash": "4.14.123"
"@types/lodash": "^4.14.123"
},
"publishConfig": {
"access": "public"
Expand Down
27 changes: 13 additions & 14 deletions packages/core/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { IPrism, IPrismComponents, IPrismConfig, IPrismDiagnostic } from './type

export function factory<Resource, Input, Output, Config, LoadOpts>(
defaultConfig: PrismConfig<Config, Input>,
defaultComponents: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
defaultComponents: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>,
): (
customConfig?: PartialPrismConfig<Config, Input>,
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>,
) => IPrism<Resource, Input, Output, Config, LoadOpts> {
const prism = (
customConfig?: PartialPrismConfig<Config, Input>,
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>,
) => {
const components: Partial<
IPrismComponents<Resource, Input, Output, Config, LoadOpts>
> = Object.assign({}, defaultComponents, customComponents);
const components: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>> = Object.assign(
{},
defaultComponents,
customComponents,
);

// our loaded resources (HttpOperation objects, etc)
let resources: Resource[] = [];
Expand All @@ -39,10 +41,7 @@ export function factory<Resource, Input, Output, Config, LoadOpts>(
// find the correct resource
let resource: Resource | undefined;
if (components.router) {
resource = components.router.route(
{ resources, input, config: configObj },
defaultComponents.router
);
resource = components.router.route({ resources, input, config: configObj }, defaultComponents.router);
}

// validate input
Expand All @@ -54,7 +53,7 @@ export function factory<Resource, Input, Output, Config, LoadOpts>(
input,
config: configObj,
},
defaultComponents.validator
defaultComponents.validator,
);
}

Expand All @@ -68,7 +67,7 @@ export function factory<Resource, Input, Output, Config, LoadOpts>(
input: { validations: { input: inputValidations }, data: input },
config: configObj,
},
defaultComponents.mocker
defaultComponents.mocker,
);
} else if (components.forwarder) {
// forward request and set output from response
Expand All @@ -78,7 +77,7 @@ export function factory<Resource, Input, Output, Config, LoadOpts>(
input: { validations: { input: inputValidations }, data: input },
config: configObj,
},
defaultComponents.forwarder
defaultComponents.forwarder,
);
}

Expand All @@ -91,7 +90,7 @@ export function factory<Resource, Input, Output, Config, LoadOpts>(
output,
config: configObj,
},
defaultComponents.validator
defaultComponents.validator,
);
}

Expand Down
17 changes: 7 additions & 10 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ export interface IPrism<Resource, Input, Output, Config, LoadOpts> {

export type PartialPrismConfigFactory<C, I> = (
input: I,
defaultConfig?: PartialPrismConfig<C, I> | PrismConfig<C, I>
defaultConfig?: PartialPrismConfig<C, I> | PrismConfig<C, I>,
) => Partial<C>;
export type PartialPrismConfig<C, I> =
| Partial<C>
| PrismConfigFactory<C, I>
| PartialPrismConfigFactory<C, I>;
export type PartialPrismConfig<C, I> = Partial<C> | PrismConfigFactory<C, I> | PartialPrismConfigFactory<C, I>;

export interface IPrismConfig {
mock?: boolean | object;
Expand All @@ -42,21 +39,21 @@ export interface IHttpLoaderOpts {
export interface IRouter<Resource, Input, Config> {
route: (
opts: { resources: Resource[]; input: Input; config?: Config },
defaultRouter?: IRouter<Resource, Input, Config>
defaultRouter?: IRouter<Resource, Input, Config>,
) => Resource;
}

export interface IForwarder<Resource, Input, Config, Output> {
forward: (
opts: { resource?: Resource; input: IPrismInput<Input>; config?: Config },
defaultForwarder?: IForwarder<Resource, Input, Config, Output>
defaultForwarder?: IForwarder<Resource, Input, Config, Output>,
) => Promise<Output>;
}

export interface IMocker<Resource, Input, Config, Output> {
mock: (
opts: Partial<IMockerOpts<Resource, Input, Config>>,
defaultMocker?: IMocker<Resource, Input, Config, Output>
defaultMocker?: IMocker<Resource, Input, Config, Output>,
) => Promise<Output>;
}

Expand All @@ -69,11 +66,11 @@ export interface IMockerOpts<Resource, Input, Config> {
export interface IValidator<Resource, Input, Config, Output> {
validateInput?: (
opts: { resource: Resource; input: Input; config?: Config },
defaultValidator?: IValidator<Resource, Input, Config, Output>
defaultValidator?: IValidator<Resource, Input, Config, Output>,
) => Promise<IPrismDiagnostic[]>;
validateOutput?: (
opts: { resource: Resource; output?: Output; config?: Config },
defaultValidator?: IValidator<Resource, Input, Config, Output>
defaultValidator?: IValidator<Resource, Input, Config, Output>,
) => Promise<IPrismDiagnostic[]>;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/__tests__/configMergerFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('configMerger', () => {
x: 1,
y: 2,
},
undefined
undefined,
);

return expect(configMerger(input, defaultConfig)).toMatchSnapshot();
Expand All @@ -51,7 +51,7 @@ describe('configMerger', () => {
c: 4,
},
beta: true,
}
},
);

return expect(configMerger(input, defaultConfig)).toMatchSnapshot();
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('configMerger', () => {
},
alfa: false,
},
configFn
configFn,
);

expect(configMerger(input, defaultConfig)).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/__tests__/graphFacade.int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('graphFacade', () => {
test('httpOperations should return filtered nodes', async () => {
await graphFacade.createRawNode(
JSON.stringify(require('../../../../cli/src/samples/no-refs-petstore.oas2.json')),
{ type: FilesystemNodeType.File, language: 'json' }
{ type: FilesystemNodeType.File, language: 'json' },
);

expect(graphFacade.httpOperations.length).toBeGreaterThan(0);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/configMergerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function configMergerFactory<C, I>(
// remove falsy config props
_compact([baseConfig, ...configs])
// resolve each config (resolveConfig is async)
.map((c: C) => resolveConfig(input, c, defaultConfig))
.map((c: C) => resolveConfig(input, c, defaultConfig)),
);

if (!resolvedConfigs.length) {
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/utils/graphFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GraphFacade {
createOas2Plugin(),
createOas3Plugin(),
createOas2HttpPlugin(),
createOas3HttpPlugin()
createOas3HttpPlugin(),
);
this.fsBackend = createFileSystemBackend(graphite, fs);
}
Expand Down Expand Up @@ -59,10 +59,7 @@ export class GraphFacade {
await this.graphite.scheduler.drain();
}

public async createRawNode(
raw: string,
{ type, language }: Pick<ISourceNode, 'type' | 'language'>
) {
public async createRawNode(raw: string, { type, language }: Pick<ISourceNode, 'type' | 'language'>) {
this.graphite.graph.addNode({
category: NodeCategory.Source,
type,
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/utils/resolveConfig.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { PartialPrismConfig, PartialPrismConfigFactory } from '../types';

function isPrismConfigFactory<C, I>(
val: PartialPrismConfig<C, I>
): val is PartialPrismConfigFactory<C, I> {
function isPrismConfigFactory<C, I>(val: PartialPrismConfig<C, I>): val is PartialPrismConfigFactory<C, I> {
return typeof val === 'function';
}

export function resolveConfig<Config, Input>(
input: Input,
config: PartialPrismConfig<Config, Input>,
defaultConfig?: PartialPrismConfig<Config, Input>
defaultConfig?: PartialPrismConfig<Config, Input>,
): Partial<Config> {
if (isPrismConfigFactory<Config, Input>(config)) {
return config(input, defaultConfig);
Expand Down
4 changes: 2 additions & 2 deletions packages/http-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@stoplight/prism-core": "^3.0.0-pre.2",
"@stoplight/prism-http": "^3.0.0-pre.2",
"fastify": "2.2.x",
"tslib": "1.9.x"
"fastify": "^2.3.0",
"tslib": "^1.9.0"
}
}
Loading