Skip to content

Commit

Permalink
feat: review 2
Browse files Browse the repository at this point in the history
review 2
  • Loading branch information
Hage Yaapa committed Sep 21, 2018
1 parent c41ed2f commit 533ce5b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/openapi-v3/src/generate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function resolveSchema(
} else if (fn === Boolean) {
resolvedSchema = {type: 'boolean'};
} else if (fn === Date) {
resolvedSchema = {type: 'string', format: 'date'};
resolvedSchema = {type: 'string', format: 'date-time'};
} else if (fn === Object) {
resolvedSchema = {type: 'object'};
} else if (fn === Array) {
Expand Down
3 changes: 2 additions & 1 deletion packages/repository-json-schema/src/build-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export function metaToJsonProperty(meta: PropertyDefinition): JSONSchema {
Object.assign(propDef, {$ref: `#/definitions/${propertyType.name}`});
} else if (propertyType === Date) {
Object.assign(propDef, {
type: 'date-time',
type: 'string',
format: 'date-time',
});
} else {
Object.assign(propDef, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ describe('build-schema', () => {
expectValidJsonSchema(jsonSchema);
});

it('properly converts date property', () => {
@model()
class TestModel {
@property()
date: Date;
}

const jsonSchema = modelToJsonSchema(TestModel);
expect(jsonSchema.properties).to.deepEqual({
date: {
type: 'string',
format: 'date-time'
}
});
expectValidJsonSchema(jsonSchema);
});

it('properly converts object properties', () => {
@model()
class TestModel {
Expand Down
10 changes: 8 additions & 2 deletions packages/repository-json-schema/test/unit/build-schema.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ describe('build-schema', () => {
expect(isComplexType(Function)).to.eql(false);
});

it('returns false for Date', () => {
expect(isComplexType(Date)).to.eql(false);
});

it('returns false for Array', () => {
expect(isComplexType(Array)).to.eql(false);
});
Expand Down Expand Up @@ -108,7 +112,8 @@ describe('build-schema', () => {

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

Expand Down Expand Up @@ -138,7 +143,8 @@ describe('build-schema', () => {

it('converts "date" in strings', () => {
expect(metaToJsonProperty({type: 'date'})).to.eql({
type: 'date-time',
type: 'string',
format: 'date-time',
});
});

Expand Down

0 comments on commit 533ce5b

Please sign in to comment.