-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor Bindgen to simpler form #18
Changes from 5 commits
cfc35d7
000bc0d
40082b9
0e08154
63f8453
c065934
13879c4
9a1e0ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export class ValidationError extends Error { | ||
constructor(public message: string, public path: string) { | ||
super(message); | ||
Object.setPrototypeOf(this, ValidationError.prototype); | ||
} | ||
export class ValidationError { | ||
constructor(public message: string, public path: string) { | ||
this.message = message | ||
this.path = path | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ import { | |
XtpSchema, | ||
} from "./normalizer"; | ||
import { CodeSample } from "./parser"; | ||
import { XtpNormalizedType } from "./types"; | ||
export * from "./normalizer"; | ||
export * from "./types"; | ||
export { ValidationError } from "./common"; | ||
|
||
export function parse(schema: string) { | ||
|
@@ -104,9 +106,43 @@ function isPrimitive(p: Property | Parameter): boolean { | |
return !!p.$ref.enum || !p.$ref.properties; | ||
} | ||
|
||
function isDateTime(p: Property | Parameter | null): boolean { | ||
if (!p) return false; | ||
return p.type === "string" && p.format === "date-time"; | ||
export type XtpTyped = { xtpType: XtpNormalizedType }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an external convenience type for any node in the doc that should have an xtp type. think schema, property, parameter, items, additionalProperties, etc. |
||
|
||
function isDateTime(p: XtpTyped): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are helpers to quickly check the type of a node without drilling into the xtpType.kind. Will work on any XtpTyped object. |
||
return p?.xtpType?.kind === 'date-time' | ||
} | ||
function isBuffer(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "buffer" | ||
} | ||
function isObject(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "object" | ||
} | ||
function isArray(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "array" | ||
} | ||
function isEnum(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "enum" | ||
} | ||
function isString(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "string" | ||
} | ||
function isInt32(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "int32" | ||
} | ||
function isInt64(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "int64" | ||
} | ||
function isFloat(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "float" | ||
} | ||
function isDouble(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "double" | ||
} | ||
function isBoolean(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "boolean" | ||
} | ||
function isMap(p: XtpTyped): boolean { | ||
return p?.xtpType?.kind === "map" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I had something like:
Would that be a (Edit: I get into semi-structured objects a little later in the review at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be caught in the validation step as these two concepts should not be mixable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, currently we don't support that. |
||
} | ||
|
||
function capitalize(s: string) { | ||
|
@@ -135,6 +171,17 @@ export const helpers = { | |
codeSamples, | ||
isDateTime, | ||
isPrimitive, | ||
isBuffer, | ||
isObject, | ||
isEnum, | ||
isArray, | ||
isString, | ||
isInt32, | ||
isInt64, | ||
isFloat, | ||
isDouble, | ||
isMap, | ||
isBoolean, | ||
isJsonEncoded, | ||
isUtf8Encoded, | ||
capitalize, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to throw exceptions and stop the process, we want to collect all validation errors giving the user the chance to address them all in one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love this!