Giter Site home page Giter Site logo

Comments (8)

powerdude avatar powerdude commented on May 23, 2024 1
 public class RouterCreationSuccess
    {
        [JsonProperty("crmSuccess")] public bool CrmSuccess { get; set; }

        [JsonProperty("iotSuccess")] public bool IotSuccess { get; set; }
    }

 public class Response<T>
    {
        public Response()
        {
            ErrorCodes = new List<Error>();
            DebugMessage = "";

            Result = new Result<T>();
        }

        [JsonProperty("result")] public Result<T> Result { get; set; }

        [JsonProperty("debugMessage")] public string DebugMessage { get; set; }

        [JsonProperty("errorCodes")] public List<Error> ErrorCodes { get; set; }
    }

  public class Result<T>
    {
        [JsonProperty("value")] public T Value { get; set; }
    }

public class Error
    {
        [JsonProperty("message")] public string Message;
        [JsonProperty("error")] public string Type { get; set; }
    }

public class Router{}

  public class Bug
    {
        [FunctionName(FunctionNames.AddRouter)]
        [OpenApiOperation(operationId: nameof(AddRouter), tags: new[] { "router" }, Summary = "Adds a router", Description = "Registers a new router in the system", Visibility = OpenApiVisibilityType.Important)]
        [OpenApiRequestBody("application/json", typeof(Router), Required = true)]
        [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Response<RouterCreationSuccess>), Summary = "The response", Description = "This returns the response")]
        [OpenApiResponseWithoutBody(statusCode: HttpStatusCode.MethodNotAllowed, Summary = "Invalid input", Description = "Invalid input")]
        public async Task<IActionResult> AddRouter(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "router")]
            HttpRequest req,
            [FromBody] Router newRouter,
            ILogger log)
        {
            return null;
        }
        [FunctionName("FunctionNames.AddRouter2")]
        [OpenApiOperation(operationId: nameof(AddRouter2), tags: new[] { "router" }, Summary = "Adds a router", Description = "Registers a new router in the system", Visibility = OpenApiVisibilityType.Important)]
        [OpenApiRequestBody("application/json", typeof(Router), Required = true)]
        [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Response<int>), Summary = "The response", Description = "This returns the response")]
        [OpenApiResponseWithoutBody(statusCode: HttpStatusCode.MethodNotAllowed, Summary = "Invalid input", Description = "Invalid input")]
        public async Task<IActionResult> AddRouter2(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "router")]
            HttpRequest req,
            [FromBody] Router newRouter,
            ILogger log)
        {
            return null;
        }
    }

from azure-functions-openapi-extension.

powerdude avatar powerdude commented on May 23, 2024 1

this is the error i get if both use Response<T>:

[2021-03-10T01:15:20.522Z] Executed 'RenderSwaggerDocument' (Failed, Id=a442e2f7-a52c-4ccd-90d5-ea434e996a74, Duration=91ms)
[2021-03-10T01:15:20.524Z] System.Private.CoreLib: Exception while executing function: RenderSwaggerDocument. System.Private.CoreLib: An item with the same key has already been added. Key: response.

and if i change Response<int> to just int, then no error but the Response<RouterCreationSuccess> doesn't show correctly in models section

from azure-functions-openapi-extension.

powerdude avatar powerdude commented on May 23, 2024 1

thanks @justinyoo . I've already changed my object structure since i was under a timeline crunch, but if it works for the sample, then i'll eventually migrate back to my old setup. Thanks for the fix!

from azure-functions-openapi-extension.

Vivannaboa avatar Vivannaboa commented on May 23, 2024 1

Hello, with a generic type it's working now.
Here I am having a problem when there are two generic types.

it works:

Response<T>

It does not work:

Response<IEnumerable<T>>

image
image

from azure-functions-openapi-extension.

justinyoo avatar justinyoo commented on May 23, 2024

@powerdude Thanks for the issue. To repro on my side, could you provide more details how you got into that, including your class definitions?

from azure-functions-openapi-extension.

Arseth avatar Arseth commented on May 23, 2024

Same problem here when using OpenApiResponseWithBody with a generic type MyGenericClass<Data>

from azure-functions-openapi-extension.

ssa3512 avatar ssa3512 commented on May 23, 2024

@justinyoo I can pick this up if you give me some guidance on what the correct result should be. The call that is failing is Line 253 here because GetOpenApiTypeName is returning the generic root. If two methods have two responses with the same generic root and different type params the dictionary tries to add twice with the same key.

var schemas = new Dictionary<string, OpenApiSchema>();
this._acceptor.Types = types.ToDictionary(p => p.GetOpenApiTypeName(namingStrategy), p => p);
this._acceptor.RootSchemas = rootSchemas;
this._acceptor.Schemas = schemas;

Based on what I am seeing in the samples, the convention being used for generics is to append a _ to the generic type with the generic type param.

image

Edit: Repro is here: https://github.com/ssa3512/azure-functions-openapi-extension/commit/d889f35c9c16fa9f7eb5b7021f96a59647254962

from azure-functions-openapi-extension.

justinyoo avatar justinyoo commented on May 23, 2024

@powerdude It's been released to NuGet. Please have a look and let us know.

from azure-functions-openapi-extension.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.