Skip to content

Commit

Permalink
Merge pull request #19 from dylibso/untyped-object
Browse files Browse the repository at this point in the history
Handle back-compat untyped object
  • Loading branch information
bhelx authored Nov 1, 2024
2 parents 70905c7 + 1a8975c commit 38dea85
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.0.0-rc.13",
"name": "@dylibso/xtp-bindgen",
"version": "1.0.0-rc.12",
"description": "XTP bindgen helper library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ class V1SchemaNormalizer {
if (s.xtpType) return s.xtpType // no need to recalculate

// we can assume this is an object type
if (s.properties && s.properties.length > 0) {
// if it has type = 'object' or has properties present
if ((s.type && s.type === 'object') ||
(s.properties && s.properties.length > 0)) {

const properties: XtpNormalizedType[] = []
for (const pname in s.properties!) {
const p = s.properties[pname]
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type XtpNormalizedKind =
'int32' | 'int64' | 'float' | 'double' |
'boolean' | 'date-time' | 'byte' | 'buffer'


// applies type opts to a type on construction
function cons(t: XtpNormalizedType, opts?: XtpTypeOpts): XtpNormalizedType {
// default them to false
Expand Down
2 changes: 2 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ test('parse-v1-document', () => {
expect(aType.elementType.kind).toBe('date-time')
expect(aType.elementType.nullable).toBe(true)

// untyped object
expect(isObject(properties[8])).toBe(true)

// proves we derferenced it
expect(properties[0].$ref?.enum).toStrictEqual(validV1Doc.components.schemas['GhostGang'].enum)
Expand Down
3 changes: 3 additions & 0 deletions tests/schemas/v1-valid-doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ components:
nullable: true
type: string
format: date-time
anUntypedObject:
description: An untyped object with no properties
type: object
MyInt:
description: an int as a schema
type: integer
Expand Down

0 comments on commit 38dea85

Please sign in to comment.