Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions apps/api-extractor/src/generators/ApiModelGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export class ApiModelGenerator {
this._processApiProperty(astDeclaration, exportedName, parentApiItem);
break;

case ts.SyntaxKind.SetAccessor:
this._processApiProperty(astDeclaration, exportedName, parentApiItem);
break;

case ts.SyntaxKind.IndexSignature:
this._processApiIndexSignature(astDeclaration, exportedName, parentApiItem);
break;
Expand Down Expand Up @@ -817,13 +821,17 @@ export class ApiModelGenerator {
let apiProperty: ApiProperty | undefined = parentApiItem.tryGetMemberByKey(containerKey) as ApiProperty;

if (apiProperty === undefined) {
const propertyDeclaration: ts.PropertyDeclaration =
astDeclaration.declaration as ts.PropertyDeclaration;

const nodesToCapture: IExcerptBuilderNodeToCapture[] = [];

const propertyTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
nodesToCapture.push({ node: propertyDeclaration.type, tokenRange: propertyTypeTokenRange });

// If the property declaration's type is `undefined`, then we're processing a setter with no corresponding
// getter. Use the parameter type instead (note that TSC will enforce that the setter has exactly one
// parameter).
const propertyTypeNode: ts.TypeNode =
(astDeclaration.declaration as ts.PropertyDeclaration | ts.GetAccessorDeclaration).type ||
(astDeclaration.declaration as ts.SetAccessorDeclaration).parameters[0].type!;
nodesToCapture.push({ node: propertyTypeNode, tokenRange: propertyTypeTokenRange });

const excerptTokens: IExcerptToken[] = this._buildExcerptTokens(astDeclaration, nodesToCapture);
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
Expand Down
11 changes: 10 additions & 1 deletion build-tests/api-documenter-test/config/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
"enabled": false
},

"testMode": true
"testMode": true,

"messages": {
"extractorMessageReporting": {
// Purposefully disabled for the `writeonlyProperty` test case.
"ae-missing-getter": {
"logLevel": "none"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,33 @@
"endIndex": 2
},
"isStatic": false
},
{
"kind": "Property",
"canonicalReference": "api-documenter-test!DocClass1#writeonlyProperty:member",
"docComment": "/**\n * API Extractor will surface an `ae-missing-getter` finding for this property.\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "set writeonlyProperty(value: "
},
{
"kind": "Content",
"text": "string"
},
{
"kind": "Content",
"text": ");"
}
],
"isOptional": false,
"releaseTag": "Public",
"name": "writeonlyProperty",
"propertyTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"isStatic": false
}
],
"extendsTokenRange": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class DocClass1 extends DocBaseClass implements IDocInterface1, IDocInter
// (undocumented)
get writeableProperty(): string;
set writeableProperty(value: string);
set writeonlyProperty(value: string);
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The constructor for this class is marked as internal. Third-party code should no
| [readonlyProperty](./api-documenter-test.docclass1.readonlyproperty.md) | | string | |
| [regularProperty](./api-documenter-test.docclass1.regularproperty.md) | | [SystemEvent](./api-documenter-test.systemevent.md) | This is a regular property that happens to use the SystemEvent type. |
| [writeableProperty](./api-documenter-test.docclass1.writeableproperty.md) | | string | |
| [writeonlyProperty](./api-documenter-test.docclass1.writeonlyproperty.md) | | string | API Extractor will surface an <code>ae-missing-getter</code> finding for this property. |

## Methods

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [api-documenter-test](./api-documenter-test.md) &gt; [DocClass1](./api-documenter-test.docclass1.md) &gt; [writeonlyProperty](./api-documenter-test.docclass1.writeonlyproperty.md)

## DocClass1.writeonlyProperty property

API Extractor will surface an `ae-missing-getter` finding for this property.

<b>Signature:</b>

```typescript
set writeonlyProperty(value: string);
```
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ properties:
set writeableProperty(value: string);
return:
type: string
- name: writeonlyProperty
uid: 'api-documenter-test!DocClass1#writeonlyProperty:member'
package: api-documenter-test!
fullName: writeonlyProperty
summary: API Extractor will surface an `ae-missing-getter` finding for this property.
remarks: ''
example: []
isPreview: false
isDeprecated: false
syntax:
content: 'set writeonlyProperty(value: string);'
return:
type: string
methods:
- name: deprecatedExample()
uid: 'api-documenter-test!DocClass1#deprecatedExample:member(1)'
Expand Down
5 changes: 5 additions & 0 deletions build-tests/api-documenter-test/src/DocClass1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export class DocClass1 extends DocBaseClass implements IDocInterface1, IDocInter
}
public set writeableProperty(value: string) {}

/**
* API Extractor will surface an `ae-missing-getter` finding for this property.
*/
public set writeonlyProperty(value: string) {}

/**
* This event is fired whenever the object is modified.
* @eventProperty
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Generate API doc model nodes for setters without getters",
"type": "minor"
}
],
"packageName": "@microsoft/api-extractor"
}