Typedoc: Json deserialization

Created on 1 Dec 2018  路  4Comments  路  Source: TypeStrong/typedoc

In order to easily use the json file for documentation rendering, could it be possible to "deserialize" and get a ProjectReflection object ?

enhancement

Most helpful comment

Neat idea! Currently not possible, and this would probably require a fair bit of work since serialization is spread out over so many different classes right now. If you want a ProjectReflection for now it's probably best to use the api to generate one.

const td = require('typedoc');
const app = new td.Application({
  // options
});
const inputFiles = app.expandInputFiles('src');
const projectReflection = app.convert(inputFiles);

All 4 comments

Neat idea! Currently not possible, and this would probably require a fair bit of work since serialization is spread out over so many different classes right now. If you want a ProjectReflection for now it's probably best to use the api to generate one.

const td = require('typedoc');
const app = new td.Application({
  // options
});
const inputFiles = app.expandInputFiles('src');
const projectReflection = app.convert(inputFiles);

From what I (believe to) recall this is practically impossible at the moment because:

  • not all the required information is retained in the JSON output,
  • there's a lot of cross-references between reflections that cannot be restored,
  • there are references to TypeScript type instances that cannot be skipped.

A better way might be to stop accessing reflection instances in the theme and instead rely on a reduced dataset (like from toObject()).

I recently spent quite a bit of time in the serialization code and agree with mootari. There isn't any nice way to resolve this. If you need a ProjectReflection when rendering a theme, the best way to do that is to use the code I provided above.

So... this seems to be a recurring theme with TypeDoc for me. I think something is impossible, then 6 months or a year later I come back and realize - this isn't that difficult. There are a few things that need to happen first (and some of these are being done for library mode), but this is definitely doable, and I really like the idea.

  • [ ] Semi-revert the serialization work done to separate models and serailizers. We still need the serialization module so that plugins can add their own data to the serialized models, but much of it can be restored to the models so that the code lives together and is easier to reason about.
  • [ ] Create a new method on Application:
    ```ts
    interface Application {
    restoreFromJson(json: object): ProjectReflection
    }
    ````
  • [ ] Create the Deserializer module.
    ts interface Deserailizer { addReflectionDeserailizer(kind: ReflectionKind, Extract<SomeReflection, { kind }>) addTypeDeserailizer(kind: TypeKind, Extract<SomeType, { kind }>) deserializeReflection(json: object): SomeReflection deserializeType(json: object): SomeType }

The deserializer should work in much the same way as the serializer used in library mode (not pushed to GH yet, still have another 200 or so type errors to fix...)

Was this page helpful?
0 / 5 - 0 ratings