Skip to content

Commit

Permalink
chery-pick(#19843): chore: update .net generator with deprecated/disc…
Browse files Browse the repository at this point in the history
…ouraged (#19844)

This PR cherry-picks the following commits:

- 599ae30

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
playwrightmachine and github-actions[bot] committed Jan 3, 2023
1 parent 6eec55c commit b8b1c40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
19 changes: 1 addition & 18 deletions docs/src/api/class-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,28 +638,11 @@ Optional response body as raw bytes.

### option: Route.fulfill.json
* since: v1.29
* langs: js, python
* langs: js, python, csharp
- `json` <[Serializable]>

JSON response. This method will set the content type to `application/json` if not set.

### option: Route.fulfill.json
* since: v1.29
* langs: csharp
- `json` <[JsonElement]>

JSON response. This method will set the content type to `application/json` if not set.

**Usage**

```csharp
await page.RouteAsync("https://dog.ceo/api/breeds/list/all", async route =>
{
var json = /* JsonElement with test payload */;
await route.FulfillAsync(new () { Json: json });
});
```

### option: Route.fulfill.path
* since: v1.8
- `path` <[path]>
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/dotnetXmlDocumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function _wrapAndEscape(node, maxColumns = 0) {
};


let text = node.text;
let text = (node.text || '').replace(//g, ' ');
text = text.replace(/\[([^\]]*)\]\((.*?)\)/g, (match, linkName, linkUrl) => {
const isInternal = !linkUrl.startsWith('http://') && !linkUrl.startsWith('https://');
if (isInternal)
Expand Down
45 changes: 33 additions & 12 deletions utils/doclint/generateDotnetApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const fs = require('fs');
const { parseApi } = require('./api_parser');
const { Type } = require('./documentation');
const { EOL } = require('os');
const { execSync } = require('child_process');

const maxDocumentationColumnWidth = 80;
Error.stackTraceLimit = 100;
Expand Down Expand Up @@ -91,10 +90,10 @@ classNameMap.set('Readable', 'Stream');
*
* @param {string} kind
* @param {string} name
* @param {Documentation.MarkdownNode[]} spec
* @param {Documentation.MarkdownNode[]|null} spec
* @param {string[]} body
* @param {string} folder
* @param {string} extendsName
* @param {string|null} extendsName
*/
function writeFile(kind, name, spec, body, folder, extendsName = null) {
const out = [];
Expand Down Expand Up @@ -144,10 +143,19 @@ function renderClass(clazz) {
renderMember(member, clazz, {}, body);
}

/** @type {Documentation.MarkdownNode[]} */
const spec = [];
if (clazz.deprecated)
spec.push({ type: 'text', text: '**DEPRECATED** ' + clazz.deprecated });
if (clazz.discouraged)
spec.push({ type: 'text', text: clazz.discouraged });
if (clazz.spec)
spec.push(...clazz.spec);

writeFile(
'public partial interface',
name,
clazz.spec,
spec,
body,
apiDir,
clazz.extends ? `I${toTitleCase(clazz.extends)}` : null);
Expand Down Expand Up @@ -278,7 +286,22 @@ function renderConstructors(name, type, out) {
}

/**
*
* @param {Documentation.Member} member
* @param {string[]} out
*/
function renderMemberDoc(member, out) {
/** @type {Documentation.MarkdownNode[]} */
const nodes = [];
if (member.deprecated)
nodes.push({ type: 'text', text: '**DEPRECATED** ' + member.deprecated });
if (member.discouraged)
nodes.push({ type: 'text', text: member.discouraged });
if (member.spec)
nodes.push(...member.spec);
out.push(...XmlDoc.renderXmlDoc(nodes, maxDocumentationColumnWidth));
}

/**
* @param {Documentation.Member} member
* @param {Documentation.Class|Documentation.Type} parent
* @param {{nojson?: boolean, trimRunAndPrefix?: boolean}} options
Expand All @@ -296,8 +319,7 @@ function renderMember(member, parent, options, out) {
if (!member.type)
throw new Error(`No Event Type for ${name} in ${parent.name}`);
out.push('');
if (member.spec)
out.push(...XmlDoc.renderXmlDoc(member.spec, maxDocumentationColumnWidth));
renderMemberDoc(member, out);
if (member.deprecated)
out.push(`[System.Obsolete]`);
out.push(`event EventHandler<${type}> ${name};`);
Expand All @@ -314,8 +336,7 @@ function renderMember(member, parent, options, out) {
const { name, jsonName } = overload;
let { type } = overload;
out.push('');
if (member.spec)
out.push(...XmlDoc.renderXmlDoc(member.spec, maxDocumentationColumnWidth));
renderMemberDoc(member, out);
if (!member.clazz)
out.push(`${member.required ? '[Required]\n' : ''}[JsonPropertyName("${jsonName}")]`);
if (member.deprecated)
Expand Down Expand Up @@ -623,7 +644,7 @@ function renderMethod(member, parent, name, options, out) {

if (!explodedArgs.length) {
if (!options.nodocs) {
out.push(...XmlDoc.renderXmlDoc(member.spec, maxDocumentationColumnWidth));
renderMemberDoc(member, out);
paramDocs.forEach((value, i) => printArgDoc(i, value, out));
}
if (member.deprecated)
Expand All @@ -633,7 +654,7 @@ function renderMethod(member, parent, name, options, out) {
let containsOptionalExplodedArgs = false;
explodedArgs.forEach((explodedArg, argIndex) => {
if (!options.nodocs)
out.push(...XmlDoc.renderXmlDoc(member.spec, maxDocumentationColumnWidth));
renderMemberDoc(member, out);
const overloadedArgs = [];
for (let i = 0; i < args.length; i++) {
const arg = args[i];
Expand Down Expand Up @@ -662,7 +683,7 @@ function renderMethod(member, parent, name, options, out) {
if (containsOptionalExplodedArgs) {
const filteredArgs = args.filter(x => x !== 'OPTIONAL_EXPLODED_ARG');
if (!options.nodocs)
out.push(...XmlDoc.renderXmlDoc(member.spec, maxDocumentationColumnWidth));
renderMemberDoc(member, out);
filteredArgs.forEach(arg => {
if (arg === 'EXPLODED_ARG')
throw new Error(`Unsupported required union arg combined an optional union inside ${member.name}`);
Expand Down

0 comments on commit b8b1c40

Please sign in to comment.