Skip to content

Commit

Permalink
Fix of documentation generation for aggregation (#184)
Browse files Browse the repository at this point in the history
* Fix generating aggregation documentation when downstrem docs doesnot contain content

* new version
  • Loading branch information
Burgyn authored Aug 24, 2021
1 parent 16eb92d commit 7eb6ee2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/MMLib.SwaggerForOcelot/Aggregates/RouteDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public string GetSummary()
/// </summary>
public OpenApiResponse GetResponse()
{
var response = Docs[PathKey].SelectToken("responses.200")?.ToObject(typeof(Response), _serializer) as Response;
var response = Docs[PathKey]?.SelectToken("responses.200")?.ToObject(typeof(Response), _serializer) as Response;

return new OpenApiResponse()
{
Expand All @@ -134,22 +134,28 @@ public OpenApiResponse GetResponse()

private Dictionary<string, OpenApiMediaType> CreateContent(Response response)
{
OpenApiMediaTypeEx content = response?.Content[MediaTypeNames.Application.Json];
var ret = new Dictionary<string, OpenApiMediaType>();
if (response?.Content is null)
{
return ret;
}

if (content != null)
OpenApiMediaTypeEx content = response.Content[MediaTypeNames.Application.Json];
if (content == null)
{
if (!content.SchemaExt.IsReference)
{
content.SetSchema();
}
else
{
FindSchema(content);
}
return ret;
}

ret.Add(MediaTypeNames.Application.Json, content);
if (!content.SchemaExt.IsReference)
{
content.SetSchema();
}
else
{
FindSchema(content);
}

ret.Add(MediaTypeNames.Application.Json, content);

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MMLib.SwaggerForOcelot/MMLib.SwaggerForOcelot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>4.4.1</Version>
<Version>4.4.2</Version>
<Authors>Milan Martiniak</Authors>
<Company>MMLib</Company>
<Description>Swagger generator for Ocelot downstream services.</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class RoutesDocumentationProviderShould
[InlineData("serviceWithMoreSimpleParameter1", "serviceWithMoreSimpleParameter2", "/{id}/{message}")]
[InlineData("serviceWithMoreSimpleParameter1", "serviceWithMoreSimpleParameterAnotherNames", "/{id}/{message}", "{id}-{idcko};{message}-{sprava}")]
[InlineData("moreMethod1", "moreMethod2")]
[InlineData("withoutcontent1", "withoutcontent2")]
public async Task GetDocs(string firstService, string secondService, string parameters = null, string paramsMap = null)
{
RoutesDocumentationProvider provider = await CreateProviderAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@
}
}
},
"/api/withoutcontent1/endpoint1": {
"get": {
"tags": [
"withoutcontent1"
],
"summary": "withoutcontent1 - endpoint 1",
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/api/withoutcontent2/endpoint1": {
"get": {
"tags": [
"withoutcontent2"
],
"summary": "withoutcontent2 - endpoint 1",
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/api/serviceWithSimpleParameter1/endpoint1/{id}": {
"get": {
"tags": [
Expand Down

0 comments on commit 7eb6ee2

Please sign in to comment.