Skip to content
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

Fixes #2716: XML response example for Arrays #2896

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ private OpenApiSchema CreateArraySchema(DataContract dataContract, SchemaReposit
{
Type = "array",
Items = GenerateSchema(dataContract.ArrayItemType, schemaRepository),
UniqueItems = hasUniqueItems ? (bool?)true : null
UniqueItems = hasUniqueItems ? (bool?)true : null,
Xml = new OpenApiXml()
Copy link
Collaborator

@martincostello martincostello May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having familiarised myself with the original issue, I think while these might be reasonable defaults to assume, they might not match how the response is actually returned to the user.

I think we're missing a way for the user to customise these or we should infer them from attributes on the type.

It's been a while since I did some XML serialization, but there should be some attributes that can be used to influence how objects are serialised (say to use camelCase not PascalCase) and we should respect those if the user's model uses them.

Similarly there should be a way to wrap the elements, or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I'm going to investigate it 🤓.

{
Wrapped = true,
Name = dataContract.ArrayItemType.Name,
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ public void GenerateSchema_GeneratesArraySchema_IfEnumerableType(
Assert.Equal(expectedItemsFormat, schema.Items.Format);
}

[Theory]
[InlineData(typeof(List<BadHttpRequestException>), typeof(BadHttpRequestException))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add test cases for IList<T> and ICollection<T> please?

[InlineData(typeof(List<string>), typeof(string))]
[InlineData(typeof(int[]), typeof(int))]
public void GenerateSchema_GeneratesArraySchema_ShouldContainXMLInformation(Type type,
Type expectedItemsType)
{
var schema = Subject().GenerateSchema(type, new SchemaRepository());

Assert.True(schema.Xml.Wrapped);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also assert schema.Xml is not null?

Assert.Equal(expectedItemsType.Name, schema.Xml.Name);
}

[Theory]
[InlineData(typeof(ISet<string>))]
[InlineData(typeof(SortedSet<string>))]
Expand Down
Loading