Skip to content

TypeError: Cannot read property 'properties' of undefined #104

@flyfishMT

Description

@flyfishMT

Hi, I am trying to generate a react client from a swagger API.

npx @api-platform/client-generator http:/myapi/swagger/docs/v1 src/ --resource Item --format swagger

I get the error

TypeError: Cannot read property 'properties' of undefined

I stepped through this a little and this error occurs here:

exports.default = function (response, entrypointUrl) {
  var paths = (0, _lodash.uniq)((0, _keys2.default)(response.paths).map(function (item) {
    return item.replace("/{id}", "");
  }));

  var resources = paths.map(function (item) {
    var name = item.replace("/", "");
    var url = removeTrailingSlash(entrypointUrl) + item;
    var firstMethod = (0, _keys2.default)(response.paths[item])[0];
    var title = response.paths[item][firstMethod]["tags"][0];
    /* 
     * ERROR OCCURS HERE:
     */
    var fieldNames = (0, _keys2.default)(response.definitions[title].properties);

What happens, is it attempts to get fieldNames from

var title = response.paths[item][firstMethod]["tags"][0]; // tags[0] = "Item"
response.definitions["Item"].properties.

However, the Item endpoint does not return an Item object, it returns "ApiResponse[ItemDto]".

"paths": {

    "/api/v1/Item": {
      "get": {
        "tags": [
          "Item"
        ],
        ....
        "parameters": [
	....
        ],

        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/ApiResponse[ItemDto]"
            }
          }
        }
      },
},
"definitions": {
"ApiResponse[ItemDto]": {
      "type": "object",
      "properties": {
        "Pagination": {
          "$ref": "#/definitions/ApiPagination"
        },
        "Data": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ItemDto"
          }
        }
      }
    },

So I can see that to find the properties it needs to traverse the "$ref's".

Any advice would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions