Skip to content

Commit

Permalink
fix: JSON output types
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jan 13, 2020
1 parent 3faa547 commit f388ee0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/lib/serialization/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ type S<T, K extends keyof T> = {

// Reflections

export interface ReflectionGroup extends Reflection, S<M.ReflectionGroup, 'title' | 'kind' | 'categories'> {
export interface ReflectionGroup extends S<M.ReflectionGroup, 'title' | 'kind' | 'categories'> {
children?: M.ReflectionGroup['children'][number]['id'][];
}

export interface ReflectionCategory extends Reflection, S<M.ReflectionCategory, 'title'> {
export interface ReflectionCategory extends S<M.ReflectionCategory, 'title'> {
children?: M.ReflectionCategory['children'][number]['id'][];
}

Expand Down Expand Up @@ -149,6 +149,14 @@ export interface Reflection extends S<M.Reflection,
originalName?: M.Reflection['originalName'];
flags: ReflectionFlags;
decorators?: ModelToObject<DecoratorWrapper[]>;

children?: ModelToObject<M.Reflection>[];
parameters?: ModelToObject<M.Reflection>[];
typeParameter?: ModelToObject<M.Reflection>[];
signatures?: ModelToObject<M.Reflection>[];
indexSignature?: ModelToObject<M.Reflection>[];
getSignature?: ModelToObject<M.Reflection>[];
setSignature?: ModelToObject<M.Reflection>[];
}

// Types
Expand Down
3 changes: 1 addition & 2 deletions src/lib/serialization/serializers/reflection-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ReflectionCategory } from '../../models/ReflectionCategory';

import { SerializerComponent } from '../components';
import {
Reflection as JSONReflection,
ReflectionCategory as JSONReflectionCategory
} from '../schema';

Expand All @@ -20,7 +19,7 @@ export class ReflectionCategorySerializer extends SerializerComponent<Reflection
return r instanceof ReflectionCategory;
}

toObject(category: ReflectionCategory, obj: JSONReflection): JSONReflectionCategory {
toObject(category: ReflectionCategory, obj?: Partial<JSONReflectionCategory>): JSONReflectionCategory {
const result: JSONReflectionCategory = {
...obj,
title: category.title
Expand Down
3 changes: 1 addition & 2 deletions src/lib/serialization/serializers/reflection-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ReflectionGroup } from '../../models/ReflectionGroup';

import { SerializerComponent } from '../components';
import {
Reflection as JSONReflection,
ReflectionGroup as JSONReflectionGroup
} from '../schema';

Expand All @@ -20,7 +19,7 @@ export class ReflectionGroupSerializer extends SerializerComponent<ReflectionGro
return true;
}

toObject(group: ReflectionGroup, obj: JSONReflection): JSONReflectionGroup {
toObject(group: ReflectionGroup, obj?: Partial<JSONReflectionGroup>): JSONReflectionGroup {
const result: JSONReflectionGroup = {
...obj,
title: group.title,
Expand Down
10 changes: 10 additions & 0 deletions src/test/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { deepStrictEqual as equal, ok } from 'assert';
import { SourceFileMode } from '../lib/converter/nodes/block';
import { ScriptTarget, ModuleKind, JsxEmit } from 'typescript';

import json = require('./converter/class/specs.json');
import { JSONOutput } from '../lib/serialization';

describe('Converter', function() {
const base = Path.join(__dirname, 'converter');
const app = new Application();
Expand Down Expand Up @@ -70,3 +73,10 @@ describe('Converter', function() {
});
});
});

describe('Serializer', () => {
it('Type checks', () => {
const typed: JSONOutput.ProjectReflection = json;
equal(json, typed);
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"outDir": "dist/",
"rootDir": "src/",
"experimentalDecorators": true,
"newLine": "LF"
"newLine": "LF",
"resolveJsonModule": true
},
"include": [
"src/**/*.ts"
Expand Down

0 comments on commit f388ee0

Please sign in to comment.