Skip to content

Commit

Permalink
Copy schema from #156 and include css properties/parts in json2 format
Browse files Browse the repository at this point in the history
  • Loading branch information
runem committed Mar 28, 2020
1 parent 545b7b1 commit 0ba843f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
25 changes: 23 additions & 2 deletions src/transformers/json2/json2-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
AttributeDoc,
ClassDoc,
ClassMember,
CSSPartDoc,
CSSPropertyDoc,
CustomElementDoc,
EventDoc,
ExportDoc,
Expand Down Expand Up @@ -203,7 +205,9 @@ function getExportsDocFromDeclaration(
tagName: definition.tagName,
events: getEventDocsFromDeclaration(declaration, checker, config),
slots: getSlotDocsFromDeclaration(declaration, checker, config),
attributes: getAttributeDocsFromDeclaration(declaration, checker, config)
attributes: getAttributeDocsFromDeclaration(declaration, checker, config),
cssProperties: getCSSPropertyDocsFromDeclaration(declaration, checker, config),
cssParts: getCSSPartDocsFromDeclaration(declaration, checker, config)
};

return customElementDoc;
Expand Down Expand Up @@ -241,6 +245,22 @@ function getSlotDocsFromDeclaration(declaration: ComponentDeclaration, checker:
}));
}

function getCSSPropertyDocsFromDeclaration(declaration: ComponentDeclaration, checker: TypeChecker, config: TransformerConfig): CSSPropertyDoc[] {
return declaration.cssProperties.map(cssProperty => ({
name: cssProperty.name,
description: cssProperty.jsDoc?.description,
type: cssProperty.typeHint,
default: cssProperty.default != null ? JSON.stringify(cssProperty.default) : undefined
}));
}

function getCSSPartDocsFromDeclaration(declaration: ComponentDeclaration, checker: TypeChecker, config: TransformerConfig): CSSPartDoc[] {
return declaration.cssParts.map(cssPart => ({
name: cssPart.name,
description: cssPart.jsDoc?.description
}));
}

/**
* Returns attribute docs for a declaration
* @param declaration
Expand Down Expand Up @@ -313,7 +333,8 @@ function getFieldDocsFromDeclaration(declaration: ComponentDeclaration, checker:
name: member.propName,
privacy: member.visibility,
description: member.jsDoc?.description,
type: getTypeHintFromType(member.typeHint || member.type?.(), checker, config)
type: getTypeHintFromType(member.typeHint || member.type?.(), checker, config),
default: member.default != null ? JSON.stringify(member.default) : undefined
// TODO: "static" and "summary"
});
}
Expand Down
37 changes: 30 additions & 7 deletions src/transformers/json2/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ExportDoc = ClassDoc | FunctionDoc | VariableDoc;
* A reference to an export of a module.
*
* All references are required to be publically accessible, so the canonical
* representation of a reference is the export it's available from.
* representation of a refernce it the export it's available from.
*/
export interface Reference {
name: string;
Expand All @@ -65,6 +65,10 @@ export interface CustomElementDoc extends ClassDoc {
*/
slots?: SlotDoc[];

cssProperties?: CSSPropertyDoc[];

cssParts?: CSSPartDoc[];

demos?: Demo[];
}

Expand Down Expand Up @@ -130,9 +134,25 @@ export interface SlotDoc {
description?: string;
}

export interface CSSPropertyDoc {
name: string;
description?: string;
type?: string;
default?: string;
}

export interface CSSPartDoc {
name: string;
description?: string;
}

export interface ClassDoc {
kind: "class";
name: string;

/**
* The class name, or `undefined` if the class is anonymous.
*/
name?: string;

/**
* A markdown summary suitable for display in a listing.
Expand Down Expand Up @@ -168,6 +188,7 @@ export interface FieldDoc {
* A markdown description of the field.
*/
description?: string;
default?: string; // TODO: make this a Type type or a Reference
privacy?: Privacy;
type?: string;
}
Expand Down Expand Up @@ -207,6 +228,12 @@ export interface FunctionDoc extends FunctionLike {
kind: "function";
}

export interface Parameter {
name: string;
type?: string;
description?: string;
}

export interface FunctionLike {
name: string;

Expand All @@ -220,11 +247,7 @@ export interface FunctionLike {
*/
description?: string;

parameters?: {
name: string;
type?: string;
description?: string;
}[];
parameters?: Array<Parameter>;

return?: {
type?: string;
Expand Down

0 comments on commit 0ba843f

Please sign in to comment.