Skip to content

Commit 9df9a7a

Browse files
author
Ifeora Okechukwu
committed
signed-off: ensure schema title represents graphql scalar type name or provide default
Signed-off-by: Ifeora Okechukwu <[email protected]>
1 parent 7fb06b5 commit 9df9a7a

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

packages/openapi-to-graphql/lib/schema_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/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/utils.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export declare function isEmail(s: string): boolean;
6565
*
6666
*/
6767
export declare function isUUIDOrGUID(s: string): boolean;
68+
/**
69+
*
70+
*/
71+
export declare function ucFirst(s: string): string;
6872
/**
6973
* get the correct type of a variable
7074
*/

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

+11-1
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/schema_builder.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import debug from 'debug'
5454
import {
5555
handleWarning,
5656
sortObject,
57+
ucFirst,
5758
isSafeInteger,
5859
isSafeLong,
5960
isSafeFloat,
@@ -568,8 +569,13 @@ function getScalarType({
568569
const title = schema.title || ''
569570

570571
options.name =
571-
title.split(' ').join('') ||
572-
'StrictScalarType' +
572+
title
573+
.split(/\s+/)
574+
.map(ucFirst)
575+
.join('') ||
576+
'StrictScalar' +
577+
ucFirst(type) +
578+
'Type' +
573579
(Math.random() * Date.now()).toString(16).replace('.', '')
574580

575581
if (type === 'string') {

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function isSafeLong(n: unknown): boolean {
8383
*/
8484

8585
export function isSafeFloat(n: unknown): boolean {
86-
return false
86+
return typeof n === 'number' && n % 1 !== 0
8787
}
8888

8989
/**
@@ -163,6 +163,18 @@ export function isUUIDOrGUID(s: string): boolean {
163163
return uuidRegExp.test(s) || guidRegExp.test(s)
164164
}
165165

166+
/**
167+
*
168+
*/
169+
170+
export function ucFirst(s: string): string {
171+
if (typeof s !== 'string') {
172+
return ''
173+
}
174+
175+
return s.replace(/^./, c => c.toUpperCase())
176+
}
177+
166178
/**
167179
* check if a literal is falsy or not
168180
*/

0 commit comments

Comments
 (0)