-
Notifications
You must be signed in to change notification settings - Fork 206
Provide REST API explorer #19
Comments
Pulling in a web server is a big dependency. I would advise against it. |
HIE's dependency footprint is going to be massive anyway. Also, this can be a frontend plugin eventually, to be configured in per user if wanted. See #25 |
Hi all, @alanz. We are interested in getting involved with this project as we have time. Commenting here because I'm in favor of a REST API. It can help with a local remote symmetry in development. As my laptop's compile times are fairly long, there's a scenario in which I could see preferring to develop on a more powerful virtualized machine. It also makes it easy to integrate in build / stage / deploy pipelines, which would likely be cloud based. |
Sounds good, shall I add you to the project? |
Please. No promises on pushing code soon, but we want an IDE! It was nearly at the point where we were considering rolling our own - not that the existing alternatives are bad, but they weren't enough of a gain over just using emacs. It would be much better to contribute to a community project. |
Ok, great. You know that this is not an IDE? That said, one of the first integrations On Sun, Dec 6, 2015 at 10:59 PM, Kieren James-Lubin <
|
Yes - but I am still trying to understand exactly what it is. But I think the approach of not building an impenetrable monolith is completely right. Once I put a project into something like Eclipse, it's stuck there forever, and I have to find an Eclipse plugin to use e.g. CLI tools that I'm already using. I think the vision could be flushed out a bit though - I have skimmed the docs but I'm not 100% clear what the organizing principle would be, in a sentence. My priorities would be:
|
That sounds like a good agenda. I would summarise the project as a set of mutually reinforcing goals
This means the people who can do IDE integration can do that, the tool On Sun, Dec 6, 2015 at 11:15 PM, Kieren James-Lubin <
|
Sounds great to me, thanks. |
Maybe this is old news for you, @alanz, but If we go the swagger-route, the actual API-browser could be the Swagger UI |
Yes, I agree that swagger is probably the best approach here, in terms of On Mon, Dec 7, 2015 at 12:00 AM, Tobias G. Waaler notifications@github.com
|
I've looked into servant-swagger lately, and have a crude POC ready, so I'll assign myself to this issue unless @kjameslubin is also working on this? |
Please go ahead @tobiasgwaaler. I do have one comment, though - it would be nice to have a RAML based spec, as RAML is pretty lightweight and can be useful to generate live docs. See an example here - this is generated from a yesod-raml routes file and it mostly just works though we need to fix some stuff. But if you are going to actually do the work, don't let me get in the way. Can swagger take RAML as input? I seem to remember servant being able to output RAML fairly easily. |
Just an FYI. Servant swagger is going to release a 1.0 version soon to generically infer schema. Cc @fizruk Sent from my iPhone
|
That's great news, @dmjio! Will the 1.0 release break the code I've already written (which isn't a lot)? I guess my question is if I should wait for the 1.0 release or start working with the current version? |
@tobiasgwaaler yes, 1.0 release is going to bring a lot of changes, since it's spec model will change. More specifically If you're are impatient and want to start working with something, you can probably help us out by reviewing If you have any questions, you can find us on |
@fizruk thank you for informing me :) I'm looking forward to |
@tobiasgwaaler we've just released |
@tobiasgwaaler servant-swagger is released and #152 is merged so there should be nothing stopping you now :) |
Wonderful, I'll take a look as soon as I get the chance. If anyone else is eager to work on this, please go ahead. Although I'm motivated, I'm not sure when I'll get the time :/ |
no pressure |
@tobiasgwaaler Out of curiosity, have you gotten anywhere with this ticket? If not, I was going to spend a bit of time this evening to see if I can get something working. |
Hi, @ankhers. I started working on this branch a while ago, but haven't done anything since the release of servant-swagger-0.1 and after the commands were moved to the type level. So I would say no, I haven't gotten anywhere ;) And I probably won't in a good while, so please go ahead! 👍 |
@ankhers @tobiasgwaaler @cocreature Is anyone making progress on this? I have some time available and want to get my brain around the tech for my day job, so I can tackle it if not |
@alanz I'm not working on this :) |
Need some instances
FYI, I have started here https://github.com/alanz/haskell-ide-engine/tree/swagger2 I think I am making progress, but need to chase some instances through |
I have constructed a function The problem is, I do not know how to create an instance of @cocreature any ideas? |
@alanz One straightforward way to introduce -- ------------------------------------------
-- This is copied for convenience
-- ------------------------------------------
data ParamType = PtText | PtFile | PtPos
data ParamValP = forall t. ParamValP { unParamValP :: ParamVal t }
data ParamVal (t :: ParamType) where
ParamText :: T.Text -> ParamVal 'PtText
ParamFile :: T.Text -> ParamVal 'PtFile
ParamPos :: (Int,Int) -> ParamVal 'PtPos
-- ------------------------------------------
data UParamValP = UParamValP { unUParamValP :: UParamVal }
deriving (Generic)
data UParamVal
= UParamText T.Text
| UParamFile T.Text
| UParamPos (Int,Int)
deriving (Generic)
instance ToSchema UParamVal where
declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
{ datatypeNameModifier = drop 1 -- we drop the U prefix
, constructorTagModifier = drop 1 } -- we drop the U prefix
instance ToSchema UParamValP where
declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
{ datatypeNameModifier = drop 1 -- we drop the U prefix
, fieldLabelModifier = \s -> take 2 s ++ drop 3 s } -- we drop the U in unUParamValP
instance ToSchema (ParamVal t) where
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy UParamVal)
instance ToSchema ParamValP where
declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy UParamValP) Another straightforward approach would be to manually write the instance ToSchema ParamValP where
declareNamedSchema _ = do
sParamVal <- declareSchemaRef (Proxy :: Proxy (ParamVal t))
return $ NamedSchema (Just "ParamValP") $ mempty
& type_ .~ SwaggerObject
& properties . at "unParamValP" ?~ sParamVal
& required .~ ["unParamValP"]
instance ToSchema (ParamVal t) where
declareNamedSchema _ = do
sText <- declareSchemaRef (Proxy :: Proxy T.Text)
sPos <- declareSchemaRef (Proxy :: Proxy (Int, Int))
return $ NamedSchema (Just "ParamVal") $ mempty
& type_ .~ SwaggerObject
& maxProperties ?~ 1
& minProperties ?~ 1
& properties . at "ParamText" ?~ sText
& properties . at "ParamFile" ?~ sText
& properties . at "ParamPos" ?~ sPos BTW, it should be possible to derive this instances with TH, so if you have lots of GADTs or existentials, feel free to file a feature request! |
@fizruk thanks for the great pointers, I will give it a go some time this weekend |
Writing the instances manually seems like the best way to go. |
The I think the best approach may be a custom generator based on the |
@alanz which part goes into an infinite loop? |
If you run this test: https://github.com/alanz/haskell-ide-engine/blob/swagger2/test/JsonSpec.hs#L204 it will terminate (and fail the test), but if you uncomment https://github.com/alanz/haskell-ide-engine/blob/swagger2/test/JsonSpec.hs#L236 (instead of the RNil on the line above) it fails to terminate. |
@fizruk FYI I have found using the swagger2 package directly that using
for |
@alanz I have just fixed the infinite loop in |
@fizruk I just tested it, and it works, thanks for the update. |
The swagger2 package provides declareResponse :: ToSchema a => proxy a -> Declare (Definitions Schema) Response I would like to declare a response schema for a declareCmdResponse :: ToSchema a => CommandFunc a -> Declare (Definitions Schema) Response
declareCmdResponse _ = declareCmdResponse XXXX Could this work, and any ideas of what XXX could be? my initial approach of trying declareCmdResponse _ = declareCmdResponse (Proxy :: Proxy a) does not typecheck. I am pretty sure I am missing something simple here. |
declareCmdResponse :: ToSchema a => CommandFunc a -> Declare (Definitions Schema) Response
declareCmdResponse = declareResponse This should work because Unless |
yes indeed, thanks. Was pretty sure it would be something straightforward. I am still getting my head around all this type level programming. |
This is turning out to be trickier than I thought. Some observations so far
So I am contemplating making the following changes to the HTTP API (with knock-on effects)
Comments? |
For haskell#19. Outstanding - [ ] The issue of "Null" encoding for Aeson.Value. See GetShopTV/swagger2#62 - [ ] The entire body parameters needs to be wrapped in a JSON object with "params" key. - [ ] The Bounded range for Line and Col should be used, rather than the current Integer range - [ ] Required params should be marked as such - [ ] The CommandDescriptor documentation should be brought through
The fledgeling HIE has a JSON API. This includes some introspection as to what plugins are available, and what commands they provide, together with their parameters.
Provide an application that can interact with the API, and present the results in a meaningful way.
i.e.
Then access
http://localhost:8001/
as inPossibly consider using http://swagger.io, especially as there is now servant-swagger
Or any other appropriate technology. It needs to be able to run locally though.
cc @kritzcreek
The text was updated successfully, but these errors were encountered: