Skip to content

Commit 151b516

Browse files
expand model to include language versions of examples
1 parent 095610c commit 151b516

File tree

11 files changed

+37830
-281
lines changed

11 files changed

+37830
-281
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,20 +484,28 @@ impl TypeDefinition {
484484

485485
/// The Example type is used for both requests and responses.
486486
///
487-
/// This type definition is taken from the OpenAPI spec
487+
/// This type definition is based on the OpenAPI spec
488488
/// https://spec.openapis.org/oas/v3.1.0#example-object
489-
/// with the exception of using String as the 'value' type.
489+
/// with the exception of using String as the 'value' type,
490+
/// and some custom additions.
490491
///
491492
/// The OpenAPI v3 spec also defines the 'Example' type, so
492493
/// to distinguish them, this type is called SchemaExample.
493494
495+
#[derive(Debug, Clone, Serialize, Deserialize)]
496+
pub struct ExampleAlternative {
497+
pub language: String,
498+
pub code: String,
499+
}
500+
494501
#[derive(Debug, Clone, Serialize, Deserialize)]
495502
pub struct SchemaExample {
496503
pub summary: Option<String>,
497504
pub method_request: Option<String>,
498505
pub description: Option<String>,
499506
pub value: Option<String>,
500507
pub external_value: Option<String>,
508+
pub alternatives: Option<Vec<ExampleAlternative>>,
501509
}
502510

503511
/// 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ export class Interface extends BaseType {
260260
variants?: Container
261261
}
262262

263+
/**
264+
* An alternative of an example, coded in a given language.
265+
*/
266+
export class ExampleAlternative {
267+
language: string
268+
code: string
269+
}
270+
263271
/**
264272
* The Example type is used for both requests and responses
265273
* This type definition is taken from the OpenAPI spec
@@ -277,6 +285,8 @@ export class Example {
277285
value?: string
278286
/** A URI that points to the literal example */
279287
external_value?: string
288+
/** An array of alternatives for this example in other languages */
289+
alternatives?: ExampleAlternative[]
280290
}
281291

282292
/**

0 commit comments

Comments
 (0)