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

Adding back required property #15

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ xtp plugin init \
--schema myschema.yaml \
--template @dylibso/xtp-typescript-bindgen \
--path ./myplugin \
--feature-flags none
--feature none
```

You can point to a bindgen template on github or directly to a bindgen bundle.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dylibso/xtp-bindgen",
"version": "1.0.0-rc.10",
"version": "1.0.0-rc.11",
"description": "XTP bindgen helper library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 5 additions & 4 deletions src/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface XtpItemType extends Omit<parser.XtpItemType, '$ref'> {
export interface Property extends Omit<parser.Property, '$ref'> {
'$ref': Schema | null;
nullable: boolean;
required: boolean;
items?: XtpItemType;
name: string;
}
Expand Down Expand Up @@ -158,8 +159,7 @@ function normalizeV1Schema(parsed: parser.V1Schema): XtpSchema {
if (s.additionalProperties) {
if (s.additionalProperties.$ref) {
const refSchema = querySchemaRef(schemas, s.additionalProperties.$ref, `#/components/schemas/${schemaName}/additionalProperties`);

normalizedSchema.additionalProperties = s as Property;
normalizedSchema.additionalProperties = (s as unknown) as Property;
normalizeProp(normalizedSchema.additionalProperties, refSchema, `#/components/schemas/${schemaName}/additionalProperties`);
} else {
normalizedSchema.additionalProperties = s.additionalProperties as Property;
Expand Down Expand Up @@ -237,8 +237,9 @@ function normalizeV1Schema(parsed: parser.V1Schema): XtpSchema {
validateTypeAndFormat(p.type, p.format, propPath);
validateArrayItems(p.items, `${propPath}/items`);

// coerce to false by default
// coerce to false by default for nullable and required
p.nullable = p.nullable || false
p.required = !!s.required?.includes(p.name)
})
}

Expand Down Expand Up @@ -396,4 +397,4 @@ function detectCircularReference(schema: Schema, visited: Set<string> = new Set(
}

return null;
}
}
5 changes: 3 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface Schema {
enum?: string[];
properties?: { [name: string]: Property };
additionalProperties?: Property;
required?: string[];
}

export type XtpSchemaType = 'object' | 'enum' | 'map'
Expand Down Expand Up @@ -88,7 +89,7 @@ export function parseJson(encoded: string): VUnknownSchema {
} catch (e) {
throw new ValidationError("Invalid JSON", "#");
}

if (!parsed.version) throw new ValidationError("version property missing", "#");
switch (parsed.version) {
case 'v0':
Expand All @@ -106,4 +107,4 @@ export function isV0Schema(schema: VUnknownSchema): schema is V0Schema {

export function isV1Schema(schema: VUnknownSchema): schema is V1Schema {
return schema.version === 'v1-draft';
}
}
Loading