-
Notifications
You must be signed in to change notification settings - Fork 189
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
OpenApi fails to use a model with a property named Aliases #167
Comments
That's interesting. Can you change the class name from
Try this (class name with public class BlackWidows
{
public DateTime Date { get; set; }
}
public class WeatherForecast
{
...
public List<BlackWidows> BlackWidows { get; set; }
} And try this (class name without public class BlackWidow
{
public DateTime Date { get; set; }
}
public class WeatherForecast
{
...
public List<BlackWidow> BlackWidows { get; set; }
} |
So I tried that and indeed failed. It seems like when the Property has the same name as the class, it fails. But, as far as I can confirm, it only happens for objects of List, because I have a Property in my main project with the same name of the model but it is like this:
and it works. The moment I change it to List Class it fails with the Swagger Error. |
Thanks for the confirmation. Let me have a look. |
Thank you very much! |
Also seeing the same issue |
That's interesting! I will try this issue, but i'm not sure that solve or not. |
@level120 You want to try to take this issue? This will be a breaking change. Let's keep this discussion open and going. |
@justinyoo Sure, It is a good chance for me. |
@level120 Because we don't know what will be duplicated, appending sequence number could be a good idea. For example, public class BlackWidows
{
public DateTime Date { get; set; }
}
public class WeatherForecast
{
...
public List<BlackWidows> BlackWidows { get; set; }
} It should be something like: {
"components": {
"schemas": {
"BlackWidows": {
"type": "object",
"properties": {
"date": {
...
}
}
},
"BlackWidows_1": {
"type": "array",
"properties": {
"items": {
"$ref": "#/components/schemas/BlackWidows"
}
}
},
"WeatherForecast": {
"type": "object",
"properties": {
"blackWidows": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BlackWidows_1"
}
}
}
}
}
}
} |
@justinyoo How about this? I think that its aliases have a different reference. {
"components": {
"schemas": {
"blackWidows": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date-time"
}
}
},
"weatherForecast": {
"type": "object",
"properties": {
"blackWidows": {
"type": "array",
"items": {
"$ref": "#/components/schemas/blackWidows"
}
}
}
}
}
}
} The "blackWindows" reference is "#/components/schemas/blackWindows". |
@level120 The expected JSON object should be like that, as you mentioned. {
"components": {
"schemas": {
"blackWidows": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date-time"
}
}
},
"weatherForecast": {
"type": "object",
"properties": {
"blackWidows": {
"type": "array",
"items": {
"$ref": "#/components/schemas/blackWidows"
}
}
}
}
}
}
} The current issue is that it's not rendered like that, if there's a property that has a same name of the schema object. |
@justinyoo In my opinion, When instance schema key check skip, it makes the correct script. |
@level120 That might be correct. But make sure that the schema only allows the unique name. Can you write relevant codes including test codes that prove your idea? |
Hi guys, so, I have this model in my solution:
If I try to add this property to the Function:
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(List<WeatherForecast>), Summary = "The response", Description = "This returns a weatherList")]
And if I try to check the Function Swagger, I get this error:
If I change the name, the error disappears.
For example, If I change the property name to Alias I have no problem, but if I make it Aliases it just gives me that error.
Can someone confirm whether or not this word is somehow reserved or is being used in the code and it's giving this error?
I don't know if this is actually related to this, but the azure functions open API extension solution has these 2 js Swagger Files that might be excluding the name:
The text was updated successfully, but these errors were encountered: