Skip to content

Commit 7f3db23

Browse files
Applied suggestions in the PR request.
1 parent 3a2c22b commit 7f3db23

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

compiler-rs/clients_schema/src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,14 @@ impl TypeDefinition {
482482
}
483483
}
484484

485-
/**
486-
* The Example type is used for both requests and responses
487-
* This type definition is taken from the OpenAPI spec
488-
* https://spec.openapis.org/oas/v3.1.0#example-object
489-
* With the exception of using String as the 'value' type.
490-
* This type matches the 'Example' type in metamodel.ts. The
491-
* data serialized by the Typescript code in schema.json,
492-
* needs to be deserialized into this equivalent type.
493-
* The OpenAPI v3 spec also defines the 'Example' type, so
494-
* to distinguish them, this type is called SchemaExample.
485+
/// The Example type is used for both requests and responses.
486+
///
487+
/// This type definition is taken from the OpenAPI spec
488+
/// https://spec.openapis.org/oas/v3.1.0#example-object
489+
/// with the exception of using String as the 'value' type.
490+
///
491+
/// The OpenAPI v3 spec also defines the 'Example' type, so
492+
/// to distinguish them, this type is called SchemaExample.
495493
*/
496494
#[derive(Debug, Clone, Serialize, Deserialize)]
497495
pub struct SchemaExample {

compiler/src/model/metamodel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export class Request extends BaseType {
301301
body: Body
302302
behaviors?: Behavior[]
303303
attachedBehaviors?: string[]
304-
examples?: Map<string, Example>
304+
examples?: Record<string, Example>
305305
}
306306

307307
/**
@@ -314,7 +314,7 @@ export class Response extends BaseType {
314314
behaviors?: Behavior[]
315315
attachedBehaviors?: string[]
316316
exceptions?: ResponseException[]
317-
examples?: Map<string, Example>
317+
examples?: Record<string, Example>
318318
}
319319

320320
export class ResponseException {

compiler/src/steps/add-examples.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class BaseExamplesProcessor {
146146
// Convert to prettified JSON string
147147
example.value = JSON.stringify(example.value, null, 2)
148148
}
149-
examples[exampleName] = example
149+
examples.set(exampleName, example)
150150
}
151151
return examples
152152
}
@@ -189,7 +189,10 @@ class RequestExamplesProcessor extends BaseExamplesProcessor {
189189
const examplesRequestSubfolder = this.getExamplesRequestSubfolder(examplesFolder)
190190
// If there is an examples/request folder, add the request examples to the model.
191191
if (examplesRequestSubfolder !== undefined) {
192-
requestDefinition.examples = this.getExampleMap(examplesRequestSubfolder)
192+
const examples = this.getExampleMap(examplesRequestSubfolder)
193+
if (examples.size > 0) {
194+
requestDefinition.examples = Object.fromEntries(examples)
195+
}
193196
}
194197
}
195198
}
@@ -223,7 +226,7 @@ class ResponseExamplesProcessor extends BaseExamplesProcessor {
223226
const subfolders = this.getSubfolders(examplesSubfolder)
224227
// If we have a "response" subfolder, stop there and return.
225228
// We should not have a mix of response and {nnn}_response folders.
226-
if ('response' in subfolders) {
229+
if (subfolders.includes('response')) {
227230
const responseSubfolder = path.join(examplesSubfolder, 'response')
228231
return new Map([['200', responseSubfolder]])
229232
}
@@ -255,7 +258,10 @@ class ResponseExamplesProcessor extends BaseExamplesProcessor {
255258
// If there is an examples/response or examples/200_response folder,
256259
// add the response examples to the model.
257260
if (examples200ResponseSubfolder !== undefined) {
258-
responseDefinition.examples = this.getExampleMap(examples200ResponseSubfolder)
261+
const examples = this.getExampleMap(examples200ResponseSubfolder)
262+
if (examples.size > 0) {
263+
responseDefinition.examples = Object.fromEntries(examples)
264+
}
259265
}
260266
}
261267
}

0 commit comments

Comments
 (0)