Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ overlay-docs: ## Apply overlays to OpenAPI documents
rm output/openapi/elasticsearch-openapi-docs.tmp*.json

generate-language-examples:
@npm update --prefix docs/examples @elastic/request-converter
@npm update --prefix docs/examples @elastic/request-converter @elastic/request-converter-dotnet
@node docs/examples/generate-language-examples.js
@npm run format:fix-examples --prefix compiler

Expand Down
30 changes: 25 additions & 5 deletions docs/examples/generate-language-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const { convertRequests, loadSchema } = require('@elastic/request-converter');
const {parseRequest} = require("@elastic/request-converter/dist/parse");
const {JavaCaller} = require("java-caller");

const LANGUAGES = ['Python', 'JavaScript', 'Ruby', 'PHP', 'curl'];
const LANGUAGES = ['Python', 'JavaScript', 'Ruby', 'PHP', 'curl', 'C#'];

// The C# converter runs out of process in a .NET WASM bundle and has known
// endpoint-coverage gaps; a failed conversion skips that language for the
// example instead of aborting the whole run.
const BEST_EFFORT_LANGUAGES = new Set(['C#']);
const conversionFailures = [];

const EXAMPLES_JSON = 'docs/examples/languageExamples.json';
let languageExamples = {};

Expand All @@ -46,10 +53,17 @@ async function generateLanguages(example) {
}
let alternatives = [];
for (const lang of LANGUAGES) {
alternatives.push({
language: lang,
code: (await convertRequests(request, lang, {})).trim(),
});
try {
alternatives.push({
language: lang,
code: (await convertRequests(request, lang, {})).trim(),
});
} catch (err) {
if (!BEST_EFFORT_LANGUAGES.has(lang)) {
throw err;
}
conversionFailures.push({ example, lang, message: err.message });
}
}
alternatives = alternatives.concat((languageExamples[example] ?? []).filter(pair => !LANGUAGES.includes(pair.language)));

Expand Down Expand Up @@ -149,6 +163,12 @@ async function main() {
}
await fs.promises.writeFile(EXAMPLES_JSON, JSON.stringify(languageExamples, null, 2));
console.log(`${count} examples processed, ${errors} errors.`);
if (conversionFailures.length > 0) {
console.log(`\n${conversionFailures.length} best-effort conversions skipped:`);
for (const failure of conversionFailures) {
console.log(` [${failure.lang}] ${failure.example}: ${failure.message}`);
}
}
}

main();
1 change: 1 addition & 0 deletions docs/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},
"dependencies": {
"@elastic/request-converter": "^9.1.2",
"@elastic/request-converter-dotnet": "~9.5.0",
"@redocly/cli": "^1.34.5",
"yaml": "^2.8.0",
"java-caller": "^4.1.1"
Expand Down
Loading