Skip to content

Commit e5ea096

Browse files
committed
Add test to check HTTP method
Signed-off-by: Alan Cha <[email protected]>
1 parent d53eb84 commit e5ea096

20 files changed

+10458
-1830
lines changed

packages/openapi-to-graphql-cli/package-lock.json

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

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

+19-7
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,20 @@ export declare type ResponseSchemaAndNames = {
2828
responseSchemaNames?: SchemaNames;
2929
statusCode?: string;
3030
};
31-
export declare const OAS_OPERATIONS: string[];
31+
export declare enum HTTP_METHODS {
32+
'get' = "get",
33+
'put' = "put",
34+
'post' = "post",
35+
'patch' = "patch",
36+
'delete' = "delete",
37+
'options' = "options",
38+
'head' = "head"
39+
}
3240
export declare const SUCCESS_STATUS_RX: RegExp;
41+
/**
42+
* Given an HTTP method, convert it to the HTTP_METHODS enum
43+
*/
44+
export declare function methodToHttpMethod(method: string): HTTP_METHODS;
3345
/**
3446
* Resolves on a validated OAS 3 for the given spec (OAS 2 or OAS 3), or rejects
3547
* if errors occur.
@@ -98,7 +110,7 @@ export declare function getRequestBodyObject(operation: OperationObject, oas: Oa
98110
* a dictionary of names from different sources (if available), and whether the
99111
* request schema is required for the operation.
100112
*/
101-
export declare function getRequestSchemaAndNames(path: string, method: string, operation: OperationObject, oas: Oas3): RequestSchemaAndNames;
113+
export declare function getRequestSchemaAndNames(path: string, method: HTTP_METHODS, operation: OperationObject, oas: Oas3): RequestSchemaAndNames;
102114
/**
103115
* Returns JSON-compatible schema produced by the given operation
104116
*/
@@ -111,21 +123,21 @@ export declare function getResponseObject(operation: OperationObject, statusCode
111123
* a successful status code, and a dictionary of names from different sources
112124
* (if available).
113125
*/
114-
export declare function getResponseSchemaAndNames<TSource, TContext, TArgs>(path: string, method: string, operation: OperationObject, oas: Oas3, data: PreprocessingData<TSource, TContext, TArgs>, options: InternalOptions<TSource, TContext, TArgs>): ResponseSchemaAndNames;
126+
export declare function getResponseSchemaAndNames<TSource, TContext, TArgs>(path: string, method: HTTP_METHODS, operation: OperationObject, oas: Oas3, data: PreprocessingData<TSource, TContext, TArgs>, options: InternalOptions<TSource, TContext, TArgs>): ResponseSchemaAndNames;
115127
/**
116128
* Returns a success status code for the given operation
117129
*/
118130
export declare function getResponseStatusCode<TSource, TContext, TArgs>(path: string, method: string, operation: OperationObject, oas: Oas3, data: PreprocessingData<TSource, TContext, TArgs>): string | void;
119131
/**
120132
* Returns a hash containing the links in the given operation.
121133
*/
122-
export declare function getLinks<TSource, TContext, TArgs>(path: string, method: string, operation: OperationObject, oas: Oas3, data: PreprocessingData<TSource, TContext, TArgs>): {
134+
export declare function getLinks<TSource, TContext, TArgs>(path: string, method: HTTP_METHODS, operation: OperationObject, oas: Oas3, data: PreprocessingData<TSource, TContext, TArgs>): {
123135
[key: string]: LinkObject;
124136
};
125137
/**
126138
* Returns the list of parameters in the given operation.
127139
*/
128-
export declare function getParameters(path: string, method: string, operation: OperationObject, pathItem: PathItemObject, oas: Oas3): ParameterObject[];
140+
export declare function getParameters(path: string, method: HTTP_METHODS, operation: OperationObject, pathItem: PathItemObject, oas: Oas3): ParameterObject[];
129141
/**
130142
* Returns an array of server objects for the operation at the given path and
131143
* method. Considers in the following order: global server definitions,
@@ -172,7 +184,7 @@ export declare function trim(str: string, length: number): string;
172184
* Determines if the given "method" is indeed an operation. Alternatively, the
173185
* method could point to other types of information (e.g., parameters, servers).
174186
*/
175-
export declare function isOperation(method: string): boolean;
187+
export declare function isHttpMethod(method: string): boolean;
176188
/**
177189
* Formats a string that describes an operation in the form:
178190
* {name of OAS} {HTTP method in ALL_CAPS} {operation path}
@@ -191,4 +203,4 @@ export declare function uncapitalize(str: string): string;
191203
/**
192204
* For operations that do not have an operationId, generate one
193205
*/
194-
export declare function generateOperationId(method: string, path: string): string;
206+
export declare function generateOperationId(method: HTTP_METHODS, path: string): string;

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

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

packages/openapi-to-graphql/lib/oas_3_tools.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/preprocessor.js

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

packages/openapi-to-graphql/lib/preprocessor.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/resolver_builder.js

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

packages/openapi-to-graphql/lib/resolver_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/schema_builder.js

+5-4
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/operation.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { Oas3, LinkObject, ParameterObject, ServerObject, SchemaObject } from './oas3';
66
import { GraphQLOperationType } from './graphql';
77
import { GraphQLScalarType, GraphQLObjectType, GraphQLInputObjectType, GraphQLList, GraphQLEnumType, GraphQLUnionType } from 'graphql';
8+
import { HTTP_METHODS } from '../oas_3_tools';
89
import * as GraphQLJSON from 'graphql-type-json';
910
export declare type DataDefinition = {
1011
preferredName: string;
@@ -65,7 +66,7 @@ export declare type Operation = {
6566
/**
6667
* HTTP method for this operation
6768
*/
68-
method: string;
69+
method: HTTP_METHODS;
6970
/**
7071
* Content-type of the request payload
7172
*/

0 commit comments

Comments
 (0)