question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to describe models

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jnallardcommented, Oct 5, 2017

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)); where DateTimeDTO 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.

1reaction
jnallardcommented, Jul 13, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found