Skip to content

Commit 80ae531

Browse files
author
Ifeora Okechukwu
committed
signed-off: added stricter scalar type checks + build
Signed-off-by: Ifeora Okechukwu <[email protected]>
1 parent 3dc3f30 commit 80ae531

File tree

8 files changed

+148
-35
lines changed

8 files changed

+148
-35
lines changed

packages/openapi-to-graphql/lib/schema_builder.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { PreprocessingData } from './types/preprocessing_data';
55
import { Operation, DataDefinition } from './types/operation';
6-
import { ParameterObject } from './types/oas3';
6+
import { SchemaObject, ParameterObject } from './types/oas3';
77
import { Args, GraphQLType } from './types/graphql';
88
declare type GetArgsParams = {
99
requestPayloadDef?: DataDefinition;
@@ -13,6 +13,7 @@ declare type GetArgsParams = {
1313
};
1414
declare type CreateOrReuseComplexTypeParams = {
1515
def: DataDefinition;
16+
schema?: SchemaObject;
1617
operation?: Operation;
1718
iteration?: number;
1819
isInputObjectType?: boolean;
@@ -21,7 +22,7 @@ declare type CreateOrReuseComplexTypeParams = {
2122
/**
2223
* Creates and returns a GraphQL type for the given JSON schema.
2324
*/
24-
export declare function getGraphQLType({ def, operation, data, iteration, isInputObjectType }: CreateOrReuseComplexTypeParams): GraphQLType;
25+
export declare function getGraphQLType({ def, schema, operation, data, iteration, isInputObjectType }: CreateOrReuseComplexTypeParams): GraphQLType;
2526
/**
2627
* Creates the arguments for resolving a field
2728
*/

packages/openapi-to-graphql/lib/schema_builder.js

+61-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/schema_builder.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/types/oas3.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ declare type ExternalDocumentationObject = {
88
export declare type SchemaObject = {
99
$ref?: string;
1010
title?: string;
11+
minimum?: number;
12+
maximum?: number;
13+
maxLength?: number;
14+
minLength?: number;
15+
pattern?: string;
1116
type?: 'string' | 'number' | 'object' | 'array' | 'boolean' | 'integer';
1217
format?: string;
1318
nullable?: boolean;

packages/openapi-to-graphql/lib/utils.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export declare const mitigations: {
3333
LIMIT_ARGUMENT_NAME_COLLISION: string;
3434
OAUTH_SECURITY_SCHEME: string;
3535
};
36+
/**
37+
* get the correct type of a variable
38+
*/
39+
export declare function strictTypeOf(value: any, type: any): boolean;
3640
/**
3741
* Utilities that are specific to OpenAPI-to-GraphQL
3842
*/

packages/openapi-to-graphql/lib/utils.js

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/utils.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/src/utils.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -55,54 +55,54 @@ export const mitigations = {
5555
* check if a literal is falsy or not
5656
*/
5757
const isLiteralFalsey = (variable): boolean => {
58-
return (variable === "" || variable === false || variable === 0)
58+
return variable === '' || variable === false || variable === 0
5959
}
6060

6161
/**
6262
* provide the name of primitive and/or reference types
6363
*/
6464
const checkTypeName = (target, type): boolean => {
65-
let typeName = ""
65+
let typeName = ''
6666

67-
if(isLiteralFalsey(target)){
68-
typeName = (typeof target)
69-
}else{
70-
typeName = ("" + (target && target.constructor.name))
67+
if (isLiteralFalsey(target)) {
68+
typeName = typeof target
69+
} else {
70+
typeName = '' + (target && target.constructor.name)
7171
}
7272
return !!(typeName.toLowerCase().indexOf(type) + 1)
7373
}
7474

7575
/**
7676
* get the correct type of a variable
7777
*/
78-
export function strictTypeOf (value, type): boolean {
78+
export function strictTypeOf(value, type): boolean {
7979
let result = false
8080

8181
type = type || []
8282

83-
if(typeof type === 'object'){
84-
if(typeof type.length !== 'number'){
85-
return result
86-
}
87-
88-
let bitPiece = 0
83+
if (typeof type === 'object') {
84+
if (typeof type.length !== 'number') {
85+
return result
86+
}
8987

90-
type = [].slice.call(type)
88+
let bitPiece = 0
9189

92-
type.forEach( _type => {
93-
if(typeof _type === 'function'){
94-
_type = (_type.name || _type.displayName).toLowerCase()
95-
}
96-
bitPiece |= Number(checkTypeName(value, _type))
97-
});
90+
type = [].slice.call(type)
9891

99-
result = Boolean(bitPiece)
100-
}else{
101-
if(typeof type === 'function'){
102-
type = (type.name || type.displayName).toLowerCase()
92+
type.forEach(_type => {
93+
if (typeof _type === 'function') {
94+
_type = (_type.name || _type.displayName).toLowerCase()
10395
}
96+
bitPiece |= Number(checkTypeName(value, _type))
97+
})
98+
99+
result = Boolean(bitPiece)
100+
} else {
101+
if (typeof type === 'function') {
102+
type = (type.name || type.displayName).toLowerCase()
103+
}
104104

105-
result = checkTypeName(value, type)
105+
result = checkTypeName(value, type)
106106
}
107107
return result
108108
}

0 commit comments

Comments
 (0)