Skip to content

Commit

Permalink
fix: map type buffer & binary to string in open api specs
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <aaqilniz@yahoo.com>
  • Loading branch information
aaqilniz committed Oct 10, 2023
1 parent fd3fd73 commit 297b7cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Expand Up @@ -76,7 +76,25 @@ describe('build-schema', () => {
title: 'TestModel',
type: 'object',
properties: {
image: {type: 'buffer'},
image: {type: 'string', format: 'binary'},
},
additionalProperties: false,
});
});

it('allows property of buffer type', () => {
@model()
class TestModel {
@property({type: 'buffer'})
image: Buffer;
}

const jsonSchema = modelToJsonSchema(TestModel);
expect(jsonSchema).to.eql({
title: 'TestModel',
type: 'object',
properties: {
image: {type: 'string', format: 'buffer'},
},
additionalProperties: false,
});
Expand Down
Expand Up @@ -78,6 +78,20 @@ describe('build-schema', () => {
});
});

it('converts Binary', () => {
expect(metaToJsonProperty({type: 'Binary'})).to.eql({
type: 'string',
format: 'binary',
});
});

it('converts buffer', () => {
expect(metaToJsonProperty({type: 'buffer'})).to.eql({
type: 'string',
format: 'buffer',
});
});

it('converts String', () => {
expect(metaToJsonProperty({type: String})).to.eql({
type: 'string',
Expand Down
10 changes: 10 additions & 0 deletions packages/repository-json-schema/src/build-schema.ts
Expand Up @@ -280,6 +280,16 @@ export function metaToJsonProperty(meta: PropertyDefinition): JsonSchema {
type: 'string',
format: 'date-time',
});
} else if (propertyType === 'buffer') {
Object.assign(propDef, {
type: 'string',
format: 'buffer',
});
} else if (propertyType === 'Binary') {
Object.assign(propDef, {
type: 'string',
format: 'binary',
});
} else if (propertyType === 'any') {
// no-op, the json schema for any type is {}
} else if (isBuiltinType(resolvedType)) {
Expand Down

0 comments on commit 297b7cb

Please sign in to comment.