question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger documentation differing in structure from API response when using HAL

See original GitHub issue

Hi,

I am using Springfox 2.9.2.

I seem to still be experiencing a bug with HAL which is reported as fixed. The issue is described in #1980 and was reported fixed in #1927.

What I am seeing is that for a HAL enabled endpoint the swagger Documentation has a different structure to what is actually returned.

The swagger documentation describes this (I have simplified the model as we have a lot of fields):

{
  "_embedded": [
    {
      "_links": [
        {
          "deprecation": "string",
          "href": "string",
          "hreflang": "string",
          "media": "string",
          "rel": "string",
          "templated": true,
          "title": "string",
          "type": "string"
        }
      ],
      "name": "string",
      "key": "string",
      "referenceItemKey": "string"
    }
  ],
  "_links": [
    {
      "deprecation": "string",
      "href": "string",
      "hreflang": "string",
      "media": "string",
      "rel": "string",
      "templated": true,
      "title": "string",
      "type": "string"
    }
  ]
}

however the API returns this:

{
  "_embedded" : {
    "itemList" : [ {
      "name" : "Test Item 1",
      "key" : "ITEM_1",
      "referenceItemKey" : "ITEM_2",
      "_links" : {
        "self" : {
          "href" : "https://url.net/item-api/items/ITEM_1"
        },
        "referenceItem" : {
          "href" : "https://url.net/item-api/items/ITEM_2"
        }
      }
    }, {
      "name" : "Test Item 2",
      "key" : "ITEM_2",
      "_links" : {
        "self" : {
          "href" : "https://url.net/item-api/items/ITEM_2"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "https://url.net/item-api/items"
    }
  }
}

The main issue I am having is that in the swagger-doc the _embedded entry is an array, however in the return (and HAL specification) it is an object which contains a named object of type array.

Perhaps this is still a bug? Further note is that my API is returning only content type application/hal+json;charset=UTF-8

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vlfloriancommented, Feb 28, 2019

Any news on this? @caiodorn @altrdev @davidepedone did any of you manage to solve this problem?

0reactions
sforner405commented, Jul 6, 2021

Same issue here. Still getting content instead of _embedded

Read more comments on GitHub >

github_iconTop Results From Across the Web

Describing Responses - Swagger
A response is defined by its HTTP status code and the data returned in the response body and/or headers. Here is a minimal...
Read more >
RESTful API Documentation Made Easy with Swagger and ...
Swagger is a set of open-source tools built around the OpenAPI Specification that can help us to design, build, document and consume REST...
Read more >
Hypertext Application Language (HAL) - Apigility
HAL presents two hypermedia types, one for XML and one for JSON. Typically, the type is only relevant for resources returned by the...
Read more >
Spring REST Docs vs OpenAPI - Baeldung
REST docs is a totally different take on API documentation. As described earlier, the process is test-driven, and the output is in the...
Read more >
Python REST APIs With Flask, Connexion, and SQLAlchemy
You'll also test your API with Swagger UI API documentation. ... By now, your Flask project structure should look like this:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found