<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Swagger Contract for SAS REST Service in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361734#M5370</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm only in charge of operationalization, so the entire model, including feature engineering/reduction is out of my hands. &amp;nbsp;I'm content with my ability to create the REST API, and I can generate a C# client to serve as a reference implementation, (thanks for the document, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28236"&gt;@BrettWujek&lt;/a&gt;&amp;nbsp;- that helps). &amp;nbsp;But am asking about Swagger primilarily based on the same question being asked of me by my eventual C# consumers: they want something that will allow them to auto-generate their consumption classes and then worry only about mapping their core layer classes to the consumption layer classes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some browsing shows that others may have utilized Swagger to hit the API and generate what they need automatically; (based on bug reports at Swaggers' github site). &amp;nbsp;I'll give this a try and report back on how it goes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the feedback!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2017 18:37:16 GMT</pubDate>
    <dc:creator>JohnJPS</dc:creator>
    <dc:date>2017-05-25T18:37:16Z</dc:date>
    <item>
      <title>Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/359119#M5312</link>
      <description>&lt;P&gt;We're in the process of developing our first model using SAS, and we know we'll want to score it via a web service, presumably done RESTfully, utilizing json for the calls. &amp;nbsp;Another team will be consuming the webservice using clients developed in C#. &amp;nbsp;They were asking if we could generate a Swagger contract based on our eventual web service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thus I was wondering if anyone else has implemented C# clients of RESTful services with lots of (100 - 200'ish) parameters involved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reason for asking: for instance, a C# client can target&amp;nbsp;a SOAP/XML web service, and during development in Visual Studio, it's pretty much "right-click, point at the URL", and it generates base classes automatically, which is pretty handy to say the least. &amp;nbsp;We'd like to acheive the same sort of easy implementation with our SAS REST service. &amp;nbsp;Swagger preferred, but any comments appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 17:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/359119#M5312</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2017-05-16T17:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/360921#M5353</link>
      <description>&lt;P&gt;Hey John - One way to do this would be by registering your SAS code as a stored process and accessing it through the REST API offered in the BI Web Services interface. I did a little work with this in the past, but only with python, Java, and R. &amp;nbsp;But translating to C# should hopefully not be too difficult. &amp;nbsp;Just take a look at the attached doc and see if it helps you out at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm assuming this is SAS 9.4. &amp;nbsp;If you have SAS Viya then this would be even easier as it provides a REST API directly (along with APIs for other languages).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;Brett&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 20:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/360921#M5353</guid>
      <dc:creator>BrettWujek</dc:creator>
      <dc:date>2017-05-23T20:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361657#M5367</link>
      <description>Try feature selection, first -&lt;BR /&gt;then target whatever you want</description>
      <pubDate>Thu, 25 May 2017 15:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361657#M5367</guid>
      <dc:creator>ccaulkins9</dc:creator>
      <dc:date>2017-05-25T15:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361664#M5368</link>
      <description>couldn't help but notice that you might be missing a reference to the number of columns and how less is more.</description>
      <pubDate>Thu, 25 May 2017 15:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361664#M5368</guid>
      <dc:creator>ccaulkins91</dc:creator>
      <dc:date>2017-05-25T15:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361689#M5369</link>
      <description>&lt;P&gt;I think the question is more about the REST API right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But beyond that, yes - you should consider feature selection to reduce the number of parameters you need to pass to your web service and model with.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 17:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361689#M5369</guid>
      <dc:creator>BrettWujek</dc:creator>
      <dc:date>2017-05-25T17:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361734#M5370</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm only in charge of operationalization, so the entire model, including feature engineering/reduction is out of my hands. &amp;nbsp;I'm content with my ability to create the REST API, and I can generate a C# client to serve as a reference implementation, (thanks for the document, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28236"&gt;@BrettWujek&lt;/a&gt;&amp;nbsp;- that helps). &amp;nbsp;But am asking about Swagger primilarily based on the same question being asked of me by my eventual C# consumers: they want something that will allow them to auto-generate their consumption classes and then worry only about mapping their core layer classes to the consumption layer classes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some browsing shows that others may have utilized Swagger to hit the API and generate what they need automatically; (based on bug reports at Swaggers' github site). &amp;nbsp;I'll give this a try and report back on how it goes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the feedback!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 18:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/361734#M5370</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2017-05-25T18:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/385696#M5682</link>
      <description>&lt;P&gt;Just an FYI on this... I was able to generate a C# client to call a MAS REST API (as well as a SASBIWS json stored process). &amp;nbsp;MAS appears to be quite a bit faster for scoring a simple sample model but that's irrelevant to this specific topic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For MAS, I first generate a ticket; (by&amp;nbsp;HTTP Post to: https://SERVER/SASLogon/rest/VERSION/tickets with UID and PWD parameters... which returns a pre-authenticated URL in a "Location" header; calling that via another http post returns a ticket that can temporarily be used for subsequent calls).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I do that and set a breakpoint in Visual Studio order to grab the ticket... then tried NSwagStudio, looking to auto-generate implementation classes... so, basically, targeting this in NSwagStudio...&lt;/P&gt;&lt;PRE&gt;https://SERVER/SASMicroAnalyticService/rest/modules/MODEL/steps/execute?ticket=TICKET&lt;/PRE&gt;&lt;P&gt;(where SERVER = my midtier server, and MODEL = the name of what I deployed to MAS from Decision Builder)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... I was then able to pull a bunch of .json into Swagger... but, unfortunately, it is not in a format for which Swagger can automatically parse and generate C# client classes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it does pretty print ths json, and based on that it was pretty straight-forward to manually implement a generic "ScoringOutput" class, and to map it using a combination of RESTSharp (to make the calls to MAS) and Newtonsoft Json.Net, for parsing the resulting json.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I did:&lt;/P&gt;&lt;P&gt;The "SAS_ScoringOutput" class:&lt;/P&gt;&lt;PRE&gt;    class SAS_ScoringOutput
    {
        public String moduleId = "";
        public String moduleName = "";
        public String stepId = "";
        public IList&amp;lt;SAS_Mappings.SAS_Links&amp;gt; links = new List&amp;lt;SAS_Mappings.SAS_Links&amp;gt;();
        public Int64 version = 0;
        public IList&amp;lt;SAS_Mappings.SAS_NameValuePair&amp;gt; output = new List&amp;lt;SAS_Mappings.SAS_NameValuePair&amp;gt;();
    }&lt;/PRE&gt;&lt;P&gt;which uses two other helper classes...&lt;/P&gt;&lt;PRE&gt;    class SAS_Links
    {
        public String method;
        public String rel;
        public String href;
        public String uri;
        public String type;
    }&lt;/PRE&gt;&lt;P&gt;...and...&lt;/P&gt;&lt;PRE&gt;    class SAS_NameValuePair
    {
        public String name = "";
        public String value = "";
        public SAS_NameValuePair(String pName, String pValue)
        {
            name = pName;
            value = pValue;
        }
    }&lt;/PRE&gt;&lt;P&gt;Given all that, and references to both RESTSharp and Json.Net, and a valid ticket... the following should work:&lt;/P&gt;&lt;PRE&gt;private static SAS_ScoringOutput CallModelScoring(String sasTicket)
{
    SAS_ScoringOutput jsonRsp = null;
&lt;BR /&gt;    // 1. build the request
    StringBuilder jsonRequest = new StringBuilder("");&lt;BR /&gt;    // build your json request here... system dependent&lt;BR /&gt;
    IRestClient rstClient1 = new RestClient();
    rstClient1.BaseUrl = new Uri("https://SERVER/SASMicroAnalyticService/rest/modules/MODEL/steps/execute?ticket=" + sasTicket);
    rstClient1.CookieContainer = new System.Net.CookieContainer();
    IRestRequest rstReq1 = new RestSharp.RestRequest();
    rstReq1.Method = Method.POST;
    rstReq1.AddHeader("Accept", "*/*");
    rstReq1.Parameters.Clear();
    rstReq1.AddParameter(
        "application/json",
        jsonRequest.ToString(),
        ParameterType.RequestBody);

    // 2. Make the Call
    IRestResponse rstRsp1 = rstClient1.Execute(rstReq1);

    // 3. Process Results
    Newtonsoft.Json.Linq.JObject jo = Newtonsoft.Json.Linq.JObject.Parse(rstRsp1.Content);
    jsonRsp = new SAS_ScoringOutput();
    jsonRsp.moduleId = jo.SelectToken("moduleId").ToString();
    jsonRsp.moduleName = jo.SelectToken("moduleName").ToString();
    jsonRsp.stepId = jo.SelectToken("stepId").ToString();
    jsonRsp.version = long.Parse(jo.SelectToken("version").ToString());
    foreach (Newtonsoft.Json.Linq.JToken jt in jo.SelectToken("output").Children())
    {
        jsonRsp.output.Add(new SAS_NameValuePair(jt.SelectToken("name").ToString(), jt.SelectToken("value").ToString()));
    }
    return jsonRsp;
}&lt;/PRE&gt;&lt;P&gt;There are C# predicate tricks that could reduce the lines of code, and probably other code improvements that could be made, but you get the idea. Also, my names/values are always String... for a model that returns int/double/boolean/date type parameters, you'll have to do the appropriate conversions&amp;nbsp;when mapping your SAS_ScoringOutput class back into the consuming application code layers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, hope that helps, if anyone's working on something similar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 15:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/385696#M5682</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2017-08-04T15:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Swagger Contract for SAS REST Service</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/452807#M6874</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28236"&gt;@BrettWujek&lt;/a&gt;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129468"&gt;@JohnJPS&lt;/a&gt;</description>
      <pubDate>Tue, 10 Apr 2018 13:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Swagger-Contract-for-SAS-REST-Service/m-p/452807#M6874</guid>
      <dc:creator>ccaulkins9</dc:creator>
      <dc:date>2018-04-10T13:22:48Z</dc:date>
    </item>
  </channel>
</rss>

