How to describe models
See original GitHub issueI have a couple of routes that return non-primitive types. I know how to include them in the swagger specification, but how do I influence the types and documentation of the properties on those models. E.g. a DateTime
property is always exposed in the Swagger spec as a string
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Synonyms of model - Merriam-Webster Thesaurus
Synonyms for MODEL: reproduction, miniature, replica, imitation, copy, duplicate, clone, carbon; Antonyms of MODEL: prototype, original, archetype, ...
Read more >Model Definition & Meaning
The meaning of MODEL is a usually miniature representation of something; also : a pattern of something to be made. How to use...
Read more >Model
A model is an informative representation of an object, person or system. The term originally denoted the plans of a building in late...
Read more >134 Synonyms & Antonyms for MODEL
synonyms for model. Most relevant. exemplary · miniature · classic · classical · copy · dummy · facsimile · imitation ...
Read more >What is a Model?
A model can come in many shapes, sizes, and styles. It is important to emphasize that a model is not the real world...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What does the JSON look like?
SwaggerTypeMapping.AddTypeMapping(typeof(DateTime), typeof(DateTime));
won’t work because the type mapping happens before the actual modeling. So DateTime will map to DateTime, but DateTime will still be treated like a primitive string.What you could do (as I said above) is
SwaggerTypeMapping.AddTypeMapping(typeof(DateTime), typeof(DateTimeDTO));
whereDateTimeDTO
is a class that has all the properties from DataTime you want the consumer to be aware of. I think that would work. If not, you might have to have the swagger model say it’s a DateTimeDTO. (Which should be easy to do - I can tell you how to do it, but I’d need to know how you’re modeling the data)I personally would dislike adding other code to manage this, because, as @yahehe said, Datetime should be represented as a string in the Swagger Spec.
We should probably have DateTime reflected as a string automatically. (I thought we did).
Anyways, you can make use of SwaggerTypeMapping: https://github.com/yahehe/Nancy.Swagger/blob/master/src/Nancy.Swagger/SwaggerTypeMapping.cs
It should allow you to represent any type as whatever type you want. I use it on of my projects to represent a Units.Net struct as a string and I wrote a custom json serializer/deserializer to make the conversion.
For DateTime you would want a line like: SwaggerTypeMapping.AddTypeMapping(typeof(DateTime), typeof(string));
I’ll add this info to the wiki.