Changeset 965


Ignore:
Timestamp:
Oct 23, 2020, 6:28:11 PM (3 years ago)
Author:
djay
Message:

Display inputs when not valid properly. Add element for list of values. Add required operationId and summary for every request, useful to validate the APIusing openapi-cli.

Location:
trunk/zoo-project
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_json.c

    r963 r965  
    13751375    }
    13761376    if (tok->char_offset < slen){
     1377      fprintf(stderr, "Error parsing json\n");
    13771378      return NULL;
    13781379    }
     
    18141815              json_object_array_add(cc,json_object_new_string(vMap->value));
    18151816              json_object_object_add(methodc,"tags",cc);
     1817              json_object_object_add(methodc,"operationId",json_object_new_string(vMap->value));
     1818
    18161819            }
    18171820            json_object *responses=json_object_new_object();
     
    19241927                 
    19251928                  json_object *pajDescription=json_object_new_object();
    1926                   if(pmTitle!=NULL)
     1929                  json_object *pajPost=json_object_new_object();
     1930                  if(pmTitle!=NULL){
    19271931                    json_object_object_add(pajDescription,"description",json_object_new_string(pmTitle->value));
     1932                    json_object_object_add(pajPost,"summary",json_object_new_string(pmTitle->value));
     1933                  }
    19281934                  json_object *pajResponse=json_object_new_object();
    19291935                  json_object_object_add(pajResponse,"200",pajDescription);
    19301936
    1931                   json_object *pajPost=json_object_new_object();
    19321937                  json_object_object_add(pajPost,"requestBody",pajRBody);
    19331938                  json_object_object_add(pajPost,"responses",pajResponse);
     1939                  json_object_object_add(pajPost,"operationId",json_object_new_string(pmState->value));
    19341940
    19351941                  json_object *pajMethod=json_object_new_object();
     
    19421948                  json_object *pajFinal=json_object_new_object();
    19431949                  json_object_object_add(pajFinal,pacUri,pajMethod);
    1944 
    19451950                  json_object_object_add(pajRes,pmState->value,pajFinal);
    19461951
  • trunk/zoo-project/zoo-services/utils/open-api/templates/index.html

    r964 r965  
    202202 #end if
    203203#end if
     204#if $obj["maxOccurs"]>1
     205        <div class="btn-group" role="group" aria-label="Basic example">
     206          <button type="button" class="btn btn-secondary" onclick="addElementToList(\$(this));">Add</button>
     207          <button type="button" class="btn btn-secondary" onclick="delElementToList(\$(this));">Delete</button>
     208        </div>
     209#end if
    204210#end def
    205211#def printProvider(conf)
     
    339345    <script>
    340346      var socket;
     347      function addElementToList(){
     348        var lClosure=arguments[0];
     349        var isOver=false;
     350        var cnt=0;
     351        lClosure.parent().parent().find("div").each(function(){
     352          if(isOver) return;
     353          if(\$(this).hasClass("btn-group")) isOver=true;
     354          if(\$(this).hasClass("input-group")){
     355            lClosure.parent().parent().append(\$(this)[0].outerHTML);
     356            cnt++;
     357          }
     358        });
     359        if(lClosure.parent().parent().find(".input-group").length>cnt)
     360          lClosure.next().attr("disabled",false);
     361        else
     362          lClosure.next().attr("disabled",true);
     363      }
     364      function delElementToList(){
     365        var lClosure=arguments[0];
     366        var isOver=false;
     367        var cnt=0;
     368        lClosure.parent().parent().find("div").each(function(){
     369          if(isOver) return;
     370          if(\$(this).hasClass("btn-group")) isOver=true;
     371          if(\$(this).hasClass("input-group")) cnt++;
     372        });
     373        if(lClosure.parent().parent().find(".input-group").length>cnt)
     374        for(var i=0;i<cnt;i++)
     375          lClosure.parent().parent().find(".input-group").last().remove();
     376        if(lClosure.parent().parent().find(".input-group").length==cnt)
     377          lClosure.attr("disabled",true);
     378        else
     379          lClosure.attr("disabled",false);
     380      }
     381     
    341382      function loadRequest(){
    342383        var requestObject={
     
    348389        }
    349390        for(var i=0;i < System["JSON_STR"]["inputs"].length;i++){
    350           var cInput={"id": System["JSON_STR"]["inputs"][i]["id"]};
    351391          var cName=System["JSON_STR"]["inputs"][i]["id"].replace(".","_");
    352392          var selector="input[name='input_value_"+cName+"'],"+
    353393                       "select[name='input_value_"+cName+"']";
    354394          if(\$(selector).val()!=""){
    355             cInput["input"]={};
    356           if(System["JSON_STR"]["inputs"][i]["input"]["formats"]){
    357             var selector1="input[name='input_format_"+cName+"'],"+
    358               "select[name='input_format_"+cName+"']";
    359             cInput["input"]["format"]={
    360               "mimeType": \$(selector1).val()
    361             };
    362             cInput["input"]["value"]={
    363               "href": \$(selector).val()
    364             };
    365           }
    366           else{
    367             if(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]){
    368               console.log(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]);
    369               cInput["input"]["dataType"]={
    370                 "name": System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"][0]["dataType"]["name"]
     395            \$(selector).each(function(){
     396            var cInput={"id": System["JSON_STR"]["inputs"][i]["id"], "input": {}};
     397            if(System["JSON_STR"]["inputs"][i]["input"]["formats"]){
     398              var selector1="input[name='input_format_"+cName+"'],"+
     399                "select[name='input_format_"+cName+"']";
     400              console.log(\$(this).parent().prev().find("select").val());
     401              cInput["input"]["format"]={
     402                "mimeType": \$(this).parent().prev().find("select").val()
    371403              };
    372               cInput["input"]["value"]=\$(selector).val();
     404              cInput["input"]["value"]={
     405                "href": \$(this).val()
     406              };
    373407            }
    374             }
     408            else{
     409              if(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]){
     410                console.log(System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"]);
     411                cInput["input"]["dataType"]={
     412                  "name": System["JSON_STR"]["inputs"][i]["input"]["literalDataDomains"][0]["dataType"]["name"]
     413                };
     414                cInput["input"]["value"]=\$(this).val();
     415              }
     416            }console.log(cInput);
    375417            requestObject["inputs"].push(cInput);
     418            });
    376419          }
    377420        }
     
    628671                if(\$(selector).length>0){
    629672                  \$(selector).each(function(){
    630                     \$(this).parent().parent().parent().parent().find(".btn").first().click();
     673                    if(!\$(this).parent().parent().parent().hasClass("show"))
     674                      \$(this).parent().parent().parent().parent().find(".btn").first().click();
    631675                  });
    632                   console.log(System["JSON_STR"]["inputs"][i]["id"]);
    633676                }
    634677              }             
     
    644687      <hr>
    645688      <address>$openapi["openapi"]["rootUrl"]$(currentUrl).html</address>
    646       <!-- hhmts start -->Last modified: Thu Oct 22 14:21:02 CEST 2020 <!-- hhmts end -->
     689      <!-- hhmts start -->Last modified: Fri Oct 23 18:25:03 CEST 2020 <!-- hhmts end -->
    647690    </main>
    648691#if $currentKey=="root"
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png