Trouble with Swagger UI 2.1: Unable to retrieve resource list

Lately, I have been working on a RESTful API that I recently created. However, knowing myself, I'll probably forget how to use it in a few months. To avoid this, I decided to document my API using Swagger, but little did I know the frustrations that would come along with it.

I utilized to craft the YAML file which I then converted into a JSON file compatible with Swagger. However, when I tried to load the file into Swagger UI, I encountered an issue where it got stuck at

fetching resource list: localhost/swagger.json
. The console displayed an error message saying
Uncaught TypeError: Cannot read property '$ref' of undefined 
.

The version of Swagger UI that I am currently using is 2.1.0-alpha.5.

Below is the specification file:

swagger: '2.0'
info:
  title: TITLE
  description: BLAH, BLAH, BLAH, ETC
  version: "1.0b"
host: api.example.com
schemes:
 - http
basePath: /v1
produces:
 - application/json
paths:
  /match.json:
    get:
     #summary: Match Data
      description: Used for getting data about a match
      parameters:
        - name: id
          in: query
          description: The match ID of from a game
          required: true
          type: integer
          format: int32
        - name: key
          in: query
          description: API key used for authentication.
          required: true
          type: string
      responses:
        200:
          description: Returns match data
          schema:
            type: array
            items:
              $ref: '#/definitions/MatchData'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

definitions:
  MatchData:
    properties:
      info:
        type: integer
        format: int64
        description: General information about the match
      time:
        type: integer
        format: int64
        description: Information about the start/end time
      stats:
        type: array
        format: int64
        description: Stats about the match
  Error:
    required:
     - errorID
      - message
    properties:
      errorID:
        type: string
        description: Error ID.
      message:
        type: string
        description: Information about the error.

Answer №1

After testing your specifications, I noticed that while I didn't encounter the same error as you, it appears that the spec is indeed invalid.

Upon reviewing the

#/definitions/MatchData/properties/stats
, I observed that you have defined the type: array without specifying an 'items' property to indicate what type of array it is (which is required). It seems like you may have intended to use type: integer similar to the properties listed above, which aligns with the format: int64.

Without knowing your exact intentions, providing a precise solution is challenging. However, if you provide a comment explaining your objectives, I can offer a more detailed response.

Further investigation revealed a bug in the user interface. After implementing the suggested modification and reloading the spec, the operation will not expand automatically unless you click on the Expand Operations link. I have reported this issue in a GitHub ticket; feel free to monitor its progress there.

Answer №2

This issue may arise from incorrect indentation in the yaml file, which might not be visible in the Swagger editor. Make sure to review all your definitions and verify if they are correctly displayed in the preview within Swagger editor (especially look at MatchData).

Another approach you can take is:

responses:
200:
  description: Returns match data
  schema:
    type: array
    items:
      schema:
        $ref: '#/definitions/MatchData'

Answer №3

In our situation, we utilized Swagger-php and implemented the following: * @SWG\Response( * response=200, * description="application response" * @SWG\Schema( * type="array" * ) * ),

However, we overlooked adding " * @SWG\Items(ref="#/definitions/pet")". Once we removed "@SWG\Schema(", everything started working smoothly.

 *     @SWG\Response(
 *         response=200,
 *         description="application response"
 *     ),

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to save the project by generating incremental JSON diffs?

In the process of developing a web-based paint program, I have implemented a system where the user's artwork state is saved as a json object. Each time an addition is made to the client's undo stack (which consists of json objects describing the ...

Obtaining JSON information within the AngularJS Scope

I am delving into the world of AngularJS for the first time and trying to understand it by following this example: http://jsfiddle.net/SAWsA/11/ After successfully acquiring data in JSON format, I encountered no issues. Here is a snippet of the JSON data: ...

Unable to retrieve JSON data for the JavaScript object

I have been working on creating a JS object in the following manner var eleDetailsTop = new Array(); var j = 0; var id = "ele"+j; eleDetailsTop[id] = {id: id, size : "40%", sizeLabel : 12, type : "image", title : "Image& ...

Retrieving information from a table row and using it as a parameter in the URL for an AJAX request

New to implementing ajax, JQuery, and Json in my strut2 web application. I have a table on one web page with records displayed, and the last column contains an image as shown below. Currently using an anchor tag with an image for the last column with an ac ...

Facing a Null Pointer Exception when Deserializing Gson?

When attempting to parse JSON data in order to extract certain values, I encountered a particular issue. { "username":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2a1babdb0babba692b5bfb3bbbefcb1bdbf">[email protect ...

Issue encountered while parsing the JsonArray

Hi, I have encountered an issue while parsing a JSON data. Here is the link to the JSON data that I'm working with. Currently, I am trying to parse the JSON array for images so that I can display them in a recycler view using Picasso library. However ...

Swift Network Manager: Streamlining Connectivity Solutions

My current project involves creating a CRM app, and to do this, I have set up a database on my Raspberry Pi. Using PHP, I generated JSON results accessible through a URL. I've also developed a Network Manager in Swift for this project. However, I kee ...

Issue with Logstash version 1.5.3 when trying to index JSON data containing a float instead of an integer

I've encountered a strange issue with Kafka and Logstash configuration when using Elasticsearch as an output. I can successfully send a JSON object like this: { "user": "foo" "amount": 1 } But if I try to write: { "user": "foo" "amount": 0.1 ...

Decoding a JSON response requires understanding the structure and content of

[ { "property1": "prop-00000001", "property2": "property2value1", "property3": {}, "property4": [ "Prop4-00000001", "Prop4-00000002" ] }, { "property1": "prop-00000002", ...

Using the Onedrive API in Python for data manipulation

I'm struggling to write a Python script that can decode JSON data retrieved from my OneDrive. I've successfully authenticated and accessed the files, but I can't figure out how to extract the file names and URLs from the JSON response. The ...

Is there a recent problem with the flickrAPI where the photo description is showing as undefined

For the last couple of years, my two websites have been successfully populating galleries using a simple FlickrAPI call with JSON and jQuery. However, they recently encountered an error that caused gallery population to fail. I've narrowed down the i ...

Retrieve information from a .json file using the fetch API

I have created an external JSON and I am trying to retrieve data from it. The GET request on the JSON is functioning correctly, as I have tested it using Postman. Here is my code: import "./Feedback.css"; import { useState, useEffect } from " ...

Is there a way to divide a string that has two characters and store each of them in different variables?

I need to extract two characters from an array element by using a substring function. For instance, the value stored in the array element rank_tier is 52. I aim to store 5 into $firstnumber and 2 into $secondnumber. The error message I received is: A ...

Django Rest Framework encounters issues with processing incorrectly formatted JSON data

My Django Rest Framework function has the following structure: @api_view(['GET', 'PUT']) @permission_classes((permissions.IsAuthenticated,)) def TestView(request, app_id): return Response({}) It is supposed to always generate a JSON ...

Extracting a deeply nested JSON array from a document

After finding a JSON file named sample.json, I discovered that it contains an array of JSON objects with timestamps, extra data IDs, and event information. Here's a snippet: [ { "time": "2021-01-04T00:11:32.362Z", "extra_data": { "id": "123" ...

Differences between REST web services and JSON services

RESTful web services operate on a stateless server where URLs represent resources and utilize HTTP methods like GET, POST, DELETE, PUT for actions. I am considering developing a JSON service layer that relies on server-side state, with URLs representing r ...

Creating a dual-field autocomplete feature with jQuery and JSON data

I've been experimenting with jQuery's autocomplete widget and have hit a bit of a snag. I could really use some advice or guidance. Basically, I'm working on a form where users can input the name of a person, and then jQuery will search the ...

How can you modify the starting point of data in jQuery flot?

Currently using Flot to create a graph displaying clicks per minute within the first 60 minutes of short URLs generated at . The graph currently displays data from minute 0 to minute 59. My query is about adjusting the data to start at 1 and end at 59, wh ...

Manipulate Json in jq with Shell Script

I am currently working on a shell script that updates specific values within a JSON array, which is stored in a separate file. The basic logic behind this script involves setting an environment variable called URL, pinging that URL, and then modifying the ...

Encountering a SyntaxError with the message 'Unexpected token' while trying to require a module in strict mode from JSON at position 0

Within the index.js file, the following code is present: 'use strict'; const config = require('./config'); In the config.js file, the code looks like this: 'use strict'; const config = new function() { this.port = 3000; ...