/// <summary> /// Sets multiple examples on the operation for all of the operation's content types /// </summary> /// <returns>The first example so that it can be reused on the definition for V2</returns> private IOpenApiAny SetMultipleRequestExamplesForOperation( OpenApiOperation operation, IEnumerable <ISwaggerExample <object> > examples, ExamplesConverter examplesConverter) { var jsonExamples = new Lazy <IDictionary <string, OpenApiExample> >(() => examplesConverter.ToOpenApiExamplesDictionaryJson(examples) ); var xmlExamples = new Lazy <IDictionary <string, OpenApiExample> >(() => examplesConverter.ToOpenApiExamplesDictionaryXml(examples) ); foreach (var content in operation.RequestBody.Content) { if (content.Key.Contains("xml")) { content.Value.Examples = xmlExamples.Value; } else { content.Value.Examples = jsonExamples.Value; } } return(operation.RequestBody.Content.FirstOrDefault().Value?.Examples?.FirstOrDefault().Value?.Value); }
private void SetMultipleResponseExampleForStatusCode( KeyValuePair <string, OpenApiResponse> response, IEnumerable <ISwaggerExample <object> > examples, ExamplesConverter examplesConverter) { var jsonExamples = new Lazy <IDictionary <string, OpenApiExample> >(() => examplesConverter.ToOpenApiExamplesDictionaryJson(examples) ); var xmlExamples = new Lazy <IDictionary <string, OpenApiExample> >(() => examplesConverter.ToOpenApiExamplesDictionaryXml(examples) ); foreach (var content in response.Value.Content) { if (content.Key.Contains("xml")) { content.Value.Examples = xmlExamples.Value; } else { content.Value.Examples = jsonExamples.Value; } } }