Swagger UI not displaying JSON files

Question!

I'm trying to document an API with Swagger (in Rails with gem swagger-docs). I have some basic documentation complete. Ran sudo SD_LOG_LEVEL=1 rake swagger:docs RAILS_ENV=production without any errors.

My problem is the Swagger UI doesn't show my all documentation when navigating to the JSON. I can view individual files/controllers (ie. users.json), but when I access api-docs.json, I can see the copyright and company information, etc. but none of my APIs.

Each controller has its documentation written to {root}/public/apis/v1/*.json.

Screenshots:

api-docs.json shows api description only example json file that exists and that I should see



Answers
1


There is no reason to have any JavaScript with that layout. Basic CSS can style based on the state of the checkbox.

.cb {
  display: none;
}
.fake-checkbox {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: white;
  border-radius: 5px;
  border: 1px solid black;
}
.cb:checked + .fake-checkbox {
  background-color: blue;
}
<label>
  <input class="cb" type="checkbox">
  <span class="fake-checkbox"> </span>
</label>

<label>
  <input class="cb" type="checkbox" checked="checked">
  <span class="fake-checkbox"> </span>
</label>

So what to do when it is not wrapped in a label? Well you can either wrap them in a label and be done, or you can shove a lot of JavaScript at it. So what I would do is add click events to the spans that are not wrapped in a label. That way the label ones work correctly. And all the JavaScript does is toggle the checkbox state. The filte/selection can be done any way, this is a quick solution.

$(".fake-checkbox").filter( function() {
  return !$(this).parent().is("label");
}).on("click", function() {
  $(this).prev("input").click();
});
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"],
.input-group input[type="checkbox"]
{
  display: none;
}
.fake-checkbox {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: white;
  border-radius: 5px;
  border: 1px solid black;
}
input:checked + .fake-checkbox {
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="checkbox">
    <label>
      <input type="checkbox">
      <span class="fake-checkbox"></span>
    </label>
  </div>
  <div class="checkbox">
    <label>
      <input type="checkbox" checked>
      <span class="fake-checkbox"></span>
    </label>
  </div>
  <hr>
  <label class="checkbox-inline">
    <input type="checkbox">
    <span class="fake-checkbox"></span>
  </label>
  <label class="checkbox-inline">
    <input type="checkbox" checked>
    <span class="fake-checkbox"></span>
  </label>
  <hr>
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon" style="position: relative;">
        <input type="checkbox">
        <span class="fake-checkbox"></span>
      </div>
      <input type="text" class="form-control">
    </div>
  </div>
  <div class="input-group">
    <div class="input-group-addon" style="position: relative;">
      <input type="checkbox" checked>
      <span class="fake-checkbox"></span>
    </div>
    <input type="text" class="form-control">
  </div>
</div>



You should be using the .change() method rather than click for checkbox inputs. Once a checkbox has been changed you need to determine if it's checked or not. If it is remove the checked-state class. If it isn't add the class.

$(function(){
    $('.fake-checkbox').change(function() {
        if( this.checked ){
            $(this).removeClass('checked-state');
        }else{
            $(this).addClass('checked-state');
        }
    });
});

if you're looking to change the class of the parent label, then use .parent() method:

$(this).parent('label').addClass('checked-state'); $(this).parent('label').removeClass('checked-state');

As per your comments if you have some instances where there are the checkbox is/isn't inside of a label you can just do more conditional checks. See the example below where it looks for the parent label to have the class is-label:

$(function(){
    $('.fake-checkbox').change(function() {
        if( this.checked ){
            $(this).removeClass('checked-state');
        }else{
            $(this).addClass('checked-state');
        }

        if( $(this).parent('label').hasClass('is-label') ){
            if( this.checked ){
                $(this).parent('label').removeClass('checked-state');
            }else{
                $(this).parent('label').addClass('checked-state');
            }
        }
    });
});


This video can help you solving your question :)
By: admin