Skip to content

fix: Unexpected reference depth oapi-codegen#1348#1950

Draft
moemoequte wants to merge 6 commits intooapi-codegen:mainfrom
moemoequte:main
Draft

fix: Unexpected reference depth oapi-codegen#1348#1950
moemoequte wants to merge 6 commits intooapi-codegen:mainfrom
moemoequte:main

Conversation

@moemoequte
Copy link
Copy Markdown

Here is my api.json file

{
  "swagger": "2.0",
  "info": {
    "title": "",
    "version": ""
  },
  "host": "example.com",
  "basePath": "/example",
  "schemes": [
    "http",
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/info/search": {
      "post": {
        "summary": "",
        "description": "",
        "operationId": "InfoSearchHandler",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/InfoSearchResp"
            }
          }
        },
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/InfoSearchReq"
            }
          }
        ],
        "tags": [
          "info"
        ]
      }
    }
  },
  "definitions": {
    "AuthorizeResourceReq": {
      "type": "object",
      "properties": {
        "action": {
          "type": "integer",
          "format": "int32"
        },
        "request_side": {
          "type": "string"
        }
      },
      "title": "AuthorizeResourceReq",
      "required": [
        "action",
        "request_side"
      ]
    },
    "AuthorizeResourceResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      },
      "title": "AuthorizeResourceResp",
      "required": [
        "code",
        "message"
      ]
    },
    "InfoIDReq": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        }
      },
      "title": "InfoIDReq"
    },
    "InfoIDResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "result": {
          "$ref": "#/definitions/InfoIDResult"
        }
      },
      "title": "InfoIDResp",
      "required": [
        "code",
        "message",
        "result"
      ]
    },
    "InfoIDResult": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "username": {
          "type": "string"
        },
        "nickname": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        }
      },
      "title": "InfoIDResult",
      "required": [
        "user_id",
        "username"
      ]
    },
    "InfoListReq": {
      "type": "object",
      "properties": {
        "page": {
          "type": "integer",
          "format": "int32",
          "default": "1"
        },
        "size": {
          "type": "integer",
          "format": "int32",
          "default": "20"
        },
        "name": {
          "type": "string"
        },
        "identity": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        }
      },
      "title": "InfoListReq",
      "required": [
        "page",
        "size",
        "name",
        "identity",
        "phone"
      ]
    },
    "InfoListResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "size": {
          "type": "integer",
          "format": "int32"
        },
        "total": {
          "type": "integer",
          "format": "int32"
        },
        "page": {
          "type": "integer",
          "format": "int32"
        },
        "result": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/InfoListResult"
          }
        }
      },
      "title": "InfoListResp",
      "required": [
        "code",
        "message",
        "size",
        "total",
        "page",
        "result"
      ]
    },
    "InfoListResult": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "username": {
          "type": "string"
        },
        "nickname": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "identity": {
          "type": "string"
        },
        "gender": {
          "type": "integer",
          "format": "int32"
        },
        "age": {
          "type": "integer",
          "format": "int32"
        },
        "is_active": {
          "type": "boolean",
          "format": "boolean"
        },
        "date_joined": {
          "type": "string"
        },
        "last_login": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "birthday": {
          "type": "string"
        },
        "item": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/InfoListResultItem"
          }
        }
      },
      "title": "InfoListResult",
      "required": [
        "user_id",
        "username",
        "nickname",
        "name",
        "identity",
        "gender",
        "age",
        "is_active",
        "date_joined",
        "last_login",
        "birthday",
        "item"
      ]
    },
    "InfoListResultItem": {
      "type": "object",
      "properties": {
        "item_id": {
          "type": "string"
        },
        "item_code": {
          "type": "string"
        },
        "item_value": {
          "type": "string"
        },
        "start_date": {
          "type": "string"
        },
        "end_date": {
          "type": "string"
        }
      },
      "title": "InfoListResultItem",
      "required": [
        "item_id",
        "item_code",
        "item_value"
      ]
    },
    "InfoQueryResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "result": {
          "$ref": "#/definitions/InfoQueryResult"
        }
      },
      "title": "InfoQueryResp",
      "required": [
        "code",
        "message",
        "result"
      ]
    },
    "InfoQueryResult": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "username": {
          "type": "string"
        },
        "nickname": {
          "type": "string"
        },
        "gender": {
          "type": "string"
        },
        "birthday": {
          "type": "string"
        },
        "age": {
          "type": "integer",
          "format": "int32"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "role": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "role_end_date": {
          "type": "string"
        },
        "is_staff": {
          "type": "boolean",
          "format": "boolean"
        },
        "is_superuser": {
          "type": "boolean",
          "format": "boolean"
        },
        "huawei_openid": {
          "type": "string"
        },
        "wechat_unionid": {
          "type": "string"
        },
        "wechat_app_openid": {
          "type": "string"
        },
        "head_image": {
          "type": "string"
        },
        "huawei_health": {
          "type": "integer",
          "format": "int32",
          "default": "0"
        },
        "item": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/InfoQueryResultItem"
          }
        }
      },
      "title": "InfoQueryResult",
      "required": [
        "user_id",
        "nickname",
        "gender",
        "birthday",
        "age",
        "phone",
        "email",
        "role",
        "is_staff",
        "is_superuser",
        "wechat_app_openid",
        "huawei_health",
        "item"
      ]
    },
    "InfoQueryResultItem": {
      "type": "object",
      "properties": {
        "item_id": {
          "type": "string"
        },
        "item_code": {
          "type": "string"
        },
        "item_value": {
          "type": "string"
        },
        "start_date": {
          "type": "string"
        },
        "end_date": {
          "type": "string"
        }
      },
      "title": "InfoQueryResultItem",
      "required": [
        "item_id",
        "item_code",
        "item_value"
      ]
    },
    "InfoRenewReq": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "is_active": {
          "type": "boolean",
          "format": "boolean"
        }
      },
      "title": "InfoRenewReq",
      "required": [
        "user_id",
        "name",
        "phone",
        "email",
        "is_active"
      ]
    },
    "InfoRenewResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      },
      "title": "InfoRenewResp",
      "required": [
        "code",
        "message"
      ]
    },
    "InfoSearchReq": {
      "type": "object",
      "properties": {
        "search": {
          "type": "string"
        }
      },
      "title": "InfoSearchReq",
      "required": [
        "search"
      ]
    },
    "InfoSearchResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "result": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/InfoSearchResult"
          }
        }
      },
      "title": "InfoSearchResp",
      "required": [
        "code",
        "message",
        "result"
      ]
    },
    "InfoSearchResult": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "username": {
          "type": "string"
        },
        "nickname": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        }
      },
      "title": "InfoSearchResult",
      "required": [
        "user_id",
        "username"
      ]
    },
    "InfoServicesReq": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "phone": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "title": "InfoServicesReq"
    },
    "InfoServicesResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "result": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/InfoServicesResult"
          }
        }
      },
      "title": "InfoServicesResp",
      "required": [
        "code",
        "message",
        "result"
      ]
    },
    "InfoServicesResult": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        },
        "username": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "gender": {
          "type": "integer",
          "format": "int32"
        },
        "age": {
          "type": "integer",
          "format": "int32"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "birthday": {
          "type": "string"
        },
        "source": {
          "type": "string"
        },
        "role": {
          "type": "string"
        },
        "role_end_date": {
          "type": "string"
        }
      },
      "title": "InfoServicesResult",
      "required": [
        "user_id",
        "username",
        "name",
        "gender",
        "age",
        "birthday",
        "source",
        "role"
      ]
    },
    "InfoUpdateReq": {
      "type": "object",
      "properties": {
        "nickname": {
          "type": "string"
        },
        "head_image": {
          "type": "string"
        },
        "item": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/InfoQueryResultItem"
          }
        }
      },
      "title": "InfoUpdateReq",
      "required": [
        "item"
      ]
    },
    "InfoUpdateResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      },
      "title": "InfoUpdateResp",
      "required": [
        "code",
        "message"
      ]
    },
    "UpdateUsernameReq": {
      "type": "object",
      "properties": {
        "username": {
          "type": "string"
        }
      },
      "title": "UpdateUsernameReq",
      "required": [
        "username"
      ]
    },
    "UpdateUsernameResp": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      },
      "title": "UpdateUsernameResp",
      "required": [
        "code",
        "message"
      ]
    }
  },
  "securityDefinitions": {
    "apiKey": {
      "type": "apiKey",
      "description": "Enter JWT Bearer token **_only_**",
      "name": "Authorization",
      "in": "header"
    }
  }
}

Here is my cfg.yaml

# yaml-language-server: $schema=https://raw.githubusercontent.com/oapi-codegen/oapi-codegen/HEAD/configuration-schema.json
package: common
output: ../app/internal/common/client.gen.go
generate:
  models: true
  client: true

I execute

oapi-codegen -config cfg.yaml api.json

Here is my Error log

error generating code: error creating operation definitions: error describing global parameters for POST//info/search: error generating type for param (body): error turning reference (#/definitions/InfoSearchReq) into a Go type: unexpected reference depth: 3 for ref: #/definitions/InfoSearchReq local: true

If I merge the fix branch, the problem solve

jamietanna and others added 6 commits December 18, 2023 17:00
In my opinion, this check doesn't seem to be providing much value, and
we've got a few folks requesting this be disabled.

Instead of gating this behind a feature flag, we'll just remove it.

Closes oapi-codegen#1348.
@jamietanna
Copy link
Copy Markdown
Member

@moemoequte this spec you're using is OpenAPI 2.0 (aka Swagger) which isn't supported by oapi-codegen

Can you retry after converting from OpenAPI 2.0 to 3.0? Thanks

@jamietanna jamietanna marked this pull request as draft April 14, 2025 06:20
@jamietanna jamietanna changed the base branch from main to feature/remove-reference-depth-check April 14, 2025 06:20
@jamietanna jamietanna changed the base branch from feature/remove-reference-depth-check to main April 14, 2025 06:21
@iamkhalidbashir
Copy link
Copy Markdown

having same error with openapi 3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants