Make names of named tuples appear in serialized JSON responses

后端 未结 4 1637
借酒劲吻你
借酒劲吻你 2021-02-05 05:31

Situation: I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. F

4条回答
  •  执念已碎
    2021-02-05 05:43

    You have a little bid conflicting requirements

    Question:

    I have loads of these custom classes like MyType and would love to use a generic container instead

    Comment:

    However, what type would I have to declare in my ProducesResponseType attribute to explicitly expose what I am returning

    Based on above - you should stay with types you already have. Those types provide valuable documentation in your code for other developers/reader or for yourself after few months.

    From point of readability

    [ProducesResponseType(typeof(Trip), 200)]
    

    will be better then

    [ProducesResponseType(typeof((double speed, int distance)), 200)]
    

    From point of maintainability
    Adding/removing property need to be done only in one place. Where with generic approach you will need to remember update attributes too.

提交回复
热议问题