Skip to content

Commit

Permalink
fix: make function async
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jul 27, 2023
1 parent aecdf64 commit bf8ea3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/schema/src/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const extractOramaType = (jsonSchema: JSONSchema4): SearchableType => {
return oramaType as SearchableType
}

export const schemaFromJson = (jsonSchema: JSONSchema4) => {
export const schemaFromJson = async (jsonSchema: JSONSchema4): Promise<Schema> => {
assertTypeObject(jsonSchema)

const oramaSchema: Schema = {}
Expand All @@ -37,9 +37,9 @@ export const schemaFromJson = (jsonSchema: JSONSchema4) => {
if (isSupportedByOrama(propertyDefinition)) {
oramaSchema[propertyName] = extractOramaType(propertyDefinition)
} else if (isJsonObject(propertyDefinition)) {
oramaSchema[propertyName] = schemaFromJson(propertyDefinition)
oramaSchema[propertyName] = await schemaFromJson(propertyDefinition)
}
}

return oramaSchema;
return Promise.resolve(oramaSchema);
}
24 changes: 12 additions & 12 deletions packages/schema/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ t.test("it should return empty object for missing properties", async t => {
type: 'object',
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {})
})
Expand All @@ -32,7 +32,7 @@ t.test("it should convert type string", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myString: 'string'
Expand All @@ -49,7 +49,7 @@ t.test("it should convert type number", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myNumber: 'number'
Expand All @@ -67,7 +67,7 @@ t.test("it should convert type boolean", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myBoolean: 'boolean'
Expand All @@ -90,7 +90,7 @@ t.test("it should convert all types", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myString: 'string',
Expand All @@ -112,7 +112,7 @@ t.test("it should convert type string[]", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myStringArray: 'string[]'
Expand All @@ -132,7 +132,7 @@ t.test("it should convert type number[]", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myNumberArray: 'number[]'
Expand All @@ -152,7 +152,7 @@ t.test("it should convert type boolean[]", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myBooleanArray: 'boolean[]'
Expand Down Expand Up @@ -184,7 +184,7 @@ t.test("it should convert type array", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myStringArray: 'string[]',
Expand Down Expand Up @@ -227,7 +227,7 @@ t.test("it should convert all types", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myString: 'string',
Expand All @@ -252,7 +252,7 @@ t.test("it should skip unknown types", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myBoolean: 'boolean'
Expand All @@ -277,7 +277,7 @@ t.test("it should convert nested objects", async t => {
}
} as const

const oramaSchema = schemaFromJson(jsonSchema)
const oramaSchema = await schemaFromJson(jsonSchema)

t.same(oramaSchema, {
myBoolean: 'boolean',
Expand Down

0 comments on commit bf8ea3f

Please sign in to comment.