Skip to content

Commit

Permalink
Merge pull request #15 from dylibso/bring-back-required
Browse files Browse the repository at this point in the history
Adding back required property
  • Loading branch information
bhelx authored Oct 23, 2024
2 parents b1dfc3b + 4faa371 commit b9634db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
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';
}
}

0 comments on commit b9634db

Please sign in to comment.