Skip to content

Error when there are array items with $ref in additionalProperties #1049

@rovast

Description

@rovast

error message

failed to resolve \"definitions\" in fragment in URI: \"#/definitions/BaseDictResp\": struct field \"definitions\" not found

Preliminary Analysis

func toV3AdditionalProperties(from openapi3.AdditionalProperties) openapi3.AdditionalProperties {

fails to handle additionalProperties.items, which results in item.$refs not being properly converted by toV3Ref. As a consequence, the following remains unchanged:

"items": {
  "$ref": "#/definitions/BaseDictResp"
}

This leads to the inability to find #/definitions/BaseDictResp.

test openapi2 json

{
  "swagger": "2.0",
  "info": {
    "description": "Test for additionalProperties",
    "version": "v1",
    "title": "API Test"
  },
  "host": "Test",
  "paths": {
    "/map": {
      "post": {
        "summary": "api test summary",
        "description": "api test description",
        "operationId": "apiTestUsingPOST",
        "consumes": ["application/json"],
        "produces": ["*/*"],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/ResponseOfMap"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "BaseDictResp": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string",
          "description": "key of map"
        },
        "value": {
          "type": "string",
          "description": "value of map"
        }
      },
      "title": "BaseDictResp",
      "description": "BaseDictResp description"
    },

    "ResponseOfMap": {
      "type": "object",
      "properties": {
        "data": {
          "type": "object",
          "description": "response data",
          "additionalProperties": {
            "type": "array",
            "items": {
              "$ref": "#/definitions/BaseDictResp"
            }
          }
        }
      },
      "title": "ResponseOfMap"
    }
  }
}

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