在构建Swagger生成的API时找不到“日期”类型(Cannot find 'Date' type when building Swagger generated API)

编程入门 行业动态 更新时间:2024-10-21 20:43:12
在构建Swagger生成的API时找不到“日期”类型(Cannot find 'Date' type when building Swagger generated API)

我不确定Haskell中是否有内置的Date类型,很难说,我找不到任何文档。

这是我的导入声明

import Data.Aeson (FromJSON (..), ToJSON (..), Value, genericParseJSON, genericToJSON) import Data.Aeson.Types (Options (..), defaultOptions) import Data.Function ((&)) import Data.List (stripPrefix) import qualified Data.Map as Map import Data.Maybe (fromMaybe) import Data.Text (Text) import qualified Data.Text as T import GHC.Generics (Generic)

这是有问题的一行

productionEntryProductionDate :: Date

这是我在尝试运行stack build时遇到的错误

Not in scope: type constructor or class `Date'

我的代码来自我从一些Swagger 2.0 YAML生成的Web API。

我是Haskell的新手,所以如果您需要更多信息,请告诉我。

I am not sure if there is a built in Date type in Haskell or not, it is hard to tell and I can find no documentation.

Here are my import statements

import Data.Aeson (FromJSON (..), ToJSON (..), Value, genericParseJSON, genericToJSON) import Data.Aeson.Types (Options (..), defaultOptions) import Data.Function ((&)) import Data.List (stripPrefix) import qualified Data.Map as Map import Data.Maybe (fromMaybe) import Data.Text (Text) import qualified Data.Text as T import GHC.Generics (Generic)

Here is the line in question

productionEntryProductionDate :: Date

And here is the error I get when trying to run stack build

Not in scope: type constructor or class `Date'

The code I have was from a Web API I generated from some Swagger 2.0 YAML.

I am fairly new to Haskell, so if you need more info please let me know.

最满意答案

Date不是Haskell中的标准类型。 您可以定义自己的,也可以从时间库中使用Day 。 无论哪种方式,您都需要自己定义Aeson实例。 时间库有一个parseTimeM函数可以为你完成工作,但你仍然需要实例声明。

更正 :事实证明,Aeson已经拥有Day和UTCTime类型的实例。

Date is not a standard type in Haskell. You can either define your own or you can use Day from the time library. Either way you will need to define the Aeson instances for it yourself. The time library has a parseTimeM function which can do the work for you, but you still need the instance declarations.

Correction: it turns out that Aeson already has instances for both Day and UTCTime types.

更多推荐

本文发布于:2023-08-01 17:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   日期   类型   API   Swagger

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!