Skip to content

Commit

Permalink
fix: generate example wrongly returns array of examples
Browse files Browse the repository at this point in the history
Because of an error in a previous commit generate example always returns an  array even for simple models. This fix returns a simple object as expected by openapi specs and merges examples in one object in case of allOf inheritance.
  • Loading branch information
Benjamin Ledentec committed Nov 14, 2024
1 parent 307b234 commit 0b6c2d4
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ export class ModelUtils {
*/
public static generateExampleFromSchema(schema: OasSchema | AaiSchema): any {
let generator: ExampleGenerator = new ExampleGenerator();
let example : any[] = [];
example.push(generator.generate(schema));
let example = generator.generate(schema);
if (schema.allOf) {
schema.allOf.forEach( inherited => {
schema.allOf.forEach(inherited => {
if (inherited.$ref) {
example.push(generator.generate(inherited));
Object.assign(example, generator.generate(inherited));
}
});
}
Expand Down

0 comments on commit 0b6c2d4

Please sign in to comment.