Skip to content

#588 Issue 정리

Woosam Hwang edited this page Sep 2, 2023 · 2 revisions

#588 Issue - 링크

public class Yellow
{

}
public partial class Color : System.Collections.ObjectModel.Collection<Yellow>
{

}

[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(Color), Required = true, Description = "Pet object that needs to be updated to the store")]

위의 클래스로 BodyType을 설정하여 실행할 경우 해당 Type을 찾지 못해서 Null로 반환하여 오류 발생

이를 해결하기 위해서 아래의 코드로 수정

underlyingType = type.GetElementType() ?? (type.GetGenericArguments() != null && type.GetGenericArguments().Length > 0 ? type.GetGenericArguments()[0] : type.BaseType.GetGenericArguments()[0]);

type.GetElementType()이 Null일 경우 type.GenericArguments() 또한 Null일 경우 type.BaseType.GetGenericArguments()[0]로 할당

결과

"summary": "Update an existing pet",
        "description": "This updates an existing pet.",
        "operationId": "updatePet",
        "requestBody": {
          "description": "Pet object that needs to be updated to the store",
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/yellow"
                }
              }
            }
          },
          "required": true
        }
      "yellow": {
        "type": "object"
      }

위의 결과로 나오나 기존 Color Class에 대한 이름이 존재하지 않음

"summary": "Update an existing pet",
        "description": "This updates an existing pet.",
        "operationId": "updatePet",
        "requestBody": {
          "description": "Pet object that needs to be updated to the store",
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Color_yellow"
                }
              }
            }
          },
          "required": true
        }
      "Color_yellow": {
        "$ref" : "#/components/schemas/yellow"
      }

      "yellow": {
        "type": "object"
      }

위의 결과처럼 나오게 하려함

Clone this wiki locally