Skip to content

Commit 92cd84a

Browse files
expand model to include language versions of examples
1 parent 095610c commit 92cd84a

File tree

10 files changed

+37812
-279
lines changed

10 files changed

+37812
-279
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ validate-no-cache: ## Validate a given endpoint request or response without loca
99

1010
generate: ## Generate the output spec
1111
@echo ">> generating the spec .."
12+
@make generate-language-examples
1213
@npm run generate-schema --prefix compiler -- --spec ../specification/ --output ../output/
1314
@npm run start --prefix typescript-generator
1415

@@ -53,7 +54,6 @@ transform-expand-generics: ## Create a new schema with all generics expanded
5354
@npm run transform-expand-generics --prefix compiler
5455

5556
transform-to-openapi: ## Generate the OpenAPI definition from the compiled schema
56-
@make generate-language-examples
5757
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor stack --output output/openapi/elasticsearch-openapi.json
5858
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor serverless --output output/openapi/elasticsearch-serverless-openapi.json
5959

compiler-rs/clients_schema/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,20 @@ impl TypeDefinition {
491491
/// The OpenAPI v3 spec also defines the 'Example' type, so
492492
/// to distinguish them, this type is called SchemaExample.
493493
494+
#[derive(Debug, Clone, Serialize, Deserialize)]
495+
pub struct LanguageAlternative {
496+
pub language: String,
497+
pub code: String,
498+
}
499+
494500
#[derive(Debug, Clone, Serialize, Deserialize)]
495501
pub struct SchemaExample {
496502
pub summary: Option<String>,
497503
pub method_request: Option<String>,
498504
pub description: Option<String>,
499505
pub value: Option<String>,
500506
pub external_value: Option<String>,
507+
pub alternatives: Option<Vec<LanguageAlternative>>,
501508
}
502509

503510
/// Common attributes for all type definitions

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ pub fn add_endpoint(
340340
"source": request_line + "\n" + request_body.as_str(),
341341
}));
342342
}
343+
if let Some(alternatives) = example.alternatives.clone() {
344+
for alternative in alternatives.iter() {
345+
code_samples.push(serde_json::json!({
346+
"lang": alternative.language,
347+
"source": alternative.code.as_str(),
348+
}));
349+
}
350+
}
343351
}
344352
}
345353
if !code_samples.is_empty() {

compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib.js

Lines changed: 35 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm.d.ts

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/src/model/metamodel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ export class Example {
277277
value?: string
278278
/** A URI that points to the literal example */
279279
external_value?: string
280+
/** A map of alternatives for this example in other languages */
281+
alternatives?: {
282+
language: string
283+
code: string
284+
}[]
280285
}
281286

282287
/**

0 commit comments

Comments
 (0)