Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,940 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi I am using C# Azure OpenAPI function with return typeOf (customer), On Swagger.json validation online I am getting the below error message
Azure function::
[FunctionName("Function1")]
[OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
[OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "The **Name** parameter")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Customer), Description = "The OK response")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage);
}
}
public class Customer
{
[OpenApiProperty]
string code { set; get; }
[OpenApiProperty]
public Customer c { set; get; }
}
Error Message::
This API is valid, but it cannot be shown because it contains circular references
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'properties' -> object with constructor 'Object'
--- property 'c' closes the circle
The Customer class has a public property "c" which seems to be a recursive reference to the same class. This may cause an infinite loop when serializing/deserializing JSON.
To avoid an infinite loop scenario in the Customer class, you can remove the property "c" or change it to reference a different class that doesn't have a reference back to Customer.
For example:
public class Customer
{
[OpenApiProperty]
public string code { set; get; }
[OpenApiProperty]
public AnotherClass anotherClass { set; get; }
}
public class AnotherClass
{
// Properties and methods here
}