Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rovast opened this issue Jan 7, 2025 · 0 comments
Open

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

rovast opened this issue Jan 7, 2025 · 0 comments

Comments

@rovast
Copy link

rovast commented Jan 7, 2025

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"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant