Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge 4d4b6d1 into 448cb12
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi authored Oct 13, 2021
2 parents 448cb12 + 4d4b6d1 commit 9abb983
Show file tree
Hide file tree
Showing 28 changed files with 563 additions and 915 deletions.
50 changes: 34 additions & 16 deletions .github/workflows/odata-v3-converter-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,41 @@ jobs:
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
env:
workingDirectory: 'converter/odata3'
runs-on: ubuntu-latest
workingDirectory: 'converter/odata'
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1

- name: Restore Packages
run: nuget restore converter/odata/OdataSwaggerConverter.sln

- name: Build Solution
run: |
msbuild.exe converter/odata/OdataSwaggerConverter.sln -property:Configuration=Release
- name: Create Archive
run: |
7z a odataconverter.zip converter/odata/bin/Release/
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
dotnet-version: '3.1.x'
- name: List SDKs
run: dotnet --list-sdks
- name: Restore dependencies
working-directory: ${{env.workingDirectory}}
run: dotnet restore
- name: Build
working-directory: ${{env.workingDirectory}}
run: dotnet build --no-restore -f net45
- name: Test
working-directory: ${{env.workingDirectory}}
run: dotnet test --no-build --verbosity normal
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./odataconverter.zip
asset_name: odataconverter.zip
asset_content_type: application/zip
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@

images/Routing-Policy.pptx
converter/odata/bin/*
converter/odata/obj/*
converter/odata/packages/*
.vs/*
converter/odata/.vs/*
17 changes: 6 additions & 11 deletions converter/odata3/App.config → converter/odata/App.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<!--appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings-->
Expand All @@ -18,20 +19,14 @@
<add name="System.Net"/>
</listeners>
</source>


</sources>
<switches>
<add name="System.Net" value="Verbose"/>
<add name="System.Net.Http" value="Verbose"/>

</switches>
<sharedListeners>
<add name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="network.log"
traceOutputOptions="ProcessId, DateTime"
/>
<add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log" traceOutputOptions="ProcessId, DateTime"/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>
Expand All @@ -45,4 +40,4 @@
</listeners>
</trace>
</system.diagnostics-->
</configuration>
</configuration>
229 changes: 229 additions & 0 deletions converter/odata/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@

using Newtonsoft.Json.Linq;
using Microsoft.Data.Edm;



namespace OdataSwaggerConverter
{
public static class ExtensionMethods
{
public static JObject Responses(this JObject jObject, JObject responses)
{
jObject.Add("responses", responses);
return jObject;
}

public static JObject ResponseRef(this JObject responses, string name, string description, string refType)
{
responses.Add(name, new JObject()
{
{"description", description},
{
"schema", new JObject()
{
{"$ref", refType}
}
}
});
return responses;
}

public static JObject Response(this JObject responses, string name, string description, IEdmType type)
{
var schema = new JObject();
Program.SetSwaggerType(schema, type);
responses.Add(name, new JObject()
{
{"description", description},
{"schema", schema}
});
return responses;
}

public static JObject Response(this JObject responses, string name, string description, Microsoft.OData.Edm.IEdmType type)
{
var schema = new JObject();
OData4.SetSwaggerType(schema, type);
responses.Add(name, new JObject()
{
{"description", description},
{"schema", schema}
});
return responses;
}

public static JObject ResponseArrayRef(this JObject responses, string name, string description, string refType)
{
responses.Add(name, new JObject()
{
{"description", description},
{
"schema", new JObject()
{
{"type", "array"},
{
"items", new JObject()
{
{"$ref", refType}
}
}
}
}
});
return responses;
}

public static JObject DefaultErrorResponse(this JObject responses)
{
return responses.ResponseRef("default", "Unexpected error", "#/definitions/_Error");
}

public static JObject Response(this JObject responses, string name, string description)
{
responses.Add(name, new JObject()
{
{"description", description},
});
return responses;
}

public static JObject Parameters(this JObject jObject, JArray parameters)
{
jObject.Add("parameters", parameters);
return jObject;
}

public static JArray Parameter(this JArray parameters, string name, string kind, string description,
string type)
{
return Parameter(parameters, name, kind, description, type, format: null, required: null);
}

public static JArray Parameter(this JArray parameters, string name, string kind, string description,
string type, string format = null, bool? required = null)
{
parameters.Add(new JObject()
{
{"name", name},
{"in", kind},
{"description", description},
{"type", type},
});

if (!string.IsNullOrEmpty(format))
{
(parameters.Last as JObject).Add("format", format);
}
if (required != null)
{
(parameters.Last as JObject).Add("required", required);
}
return parameters;
}

public static JArray Parameter(this JArray parameters, string name, string kind, string description,
IEdmType type)
{
return Parameter(parameters, name, kind, description, type, required: null);
}

public static JArray Parameter(this JArray parameters, string name, string kind, string description,
Microsoft.OData.Edm.IEdmType type)
{
return Parameter(parameters, name, kind, description, type, required: null);
}

public static JArray Parameter(this JArray parameters, string name, string kind, string description,
IEdmType type, bool? required)
{
var parameter = new JObject()
{
{"name", name},
{"in", kind},
{"description", description},
};

if (kind != "body")
{
Program.SetSwaggerType(parameter, type);
}
else
{
var schema = new JObject();
Program.SetSwaggerType(schema, type);
parameter.Add("schema", schema);
}
if (required != null)
{
parameter.Add("required", required);
}
parameters.Add(parameter);
return parameters;
}

public static JArray Parameter(this JArray parameters, string name, string kind, string description,
Microsoft.OData.Edm.IEdmType type, bool? required)
{
var parameter = new JObject()
{
{"name", name},
{"in", kind},
{"description", description},
};

if (kind != "body")
{
OData4.SetSwaggerType(parameter, type);
}
else
{
var schema = new JObject();
OData4.SetSwaggerType(schema, type);
parameter.Add("schema", schema);
}
if (required != null)
{
parameter.Add("required", required);
}
parameters.Add(parameter);
return parameters;
}

public static JArray ParameterRef(this JArray parameters, string name, string kind, string description, string refType)
{
parameters.Add(new JObject()
{
{"name", name},
{"in", kind},
{"description", description},
{
"schema", new JObject()
{
{"$ref", refType}
}
}
});
return parameters;
}

public static JObject Tags(this JObject jObject, params string[] tags)
{
jObject.Add("tags", new JArray(tags));
return jObject;
}

public static JObject Summary(this JObject jObject, string summary)
{
jObject.Add("summary", summary);
return jObject;
}

public static JObject Description(this JObject jObject, string description)
{
jObject.Add("description", description);
return jObject;
}

}
}
38 changes: 38 additions & 0 deletions converter/odata/HttpResponseValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OdataSwaggerConverter
{
class HttpResponseValue
{
private string responseBody;
private string contentType;
private int statusCode;
public HttpResponseValue(string responseBody, string contentType, int statusCode)
{
this.responseBody = responseBody;
this.contentType = contentType;
this.statusCode = statusCode;
}

public string getResponseBody()
{
return responseBody;
}

public string getContentType()
{
return contentType;
}

public int getStatusCode()
{
return statusCode;
}


}
}
Loading

0 comments on commit 9abb983

Please sign in to comment.