Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

[CO-327] Rely on Example type-class for Swagger API schema #3215

Merged
merged 1 commit into from
Jul 17, 2018
Merged

[CO-327] Rely on Example type-class for Swagger API schema #3215

merged 1 commit into from
Jul 17, 2018

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented Jul 9, 2018

Description

Use Example typeclass instead of Arbitrary when creating Swagger schema.

  1. Import and use Example typeclass in ../V1/Types.hs
    instead of Arbitrary
  2. Resolve circular dependencies
    Errors.hs -> Types.hs -> Example.hs -> Response.hs -> Errors.hs
    by moving Example instances from Example.hs to where the datatypes
    are defined, so that Example.hs does not need to import Response.hs
    or Types.hs.

Regarding name collisions between Data.Swagger and Cardano.Wallet.API.V1.Swagger.Example, I suspect hiding is the wrong way to go?

Linked issue

CO-327

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • [~] If my code deals with exceptions, it follows the guidelines.
  • [~] I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.

Testing checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed. Having problems running tests. Want to see CI.

QA Steps

Screenshots (if available)

@Anviking
Copy link
Member Author

Anviking commented Jul 9, 2018

Hm, CI is failing, but it seems to only be warnings I didn't see in ghci. I will look into this.

@Anviking Anviking changed the title [CO-327] Rely on Example type-class for Swagger API schema [CO-327] [WIP] Rely on Example type-class for Swagger API schema Jul 9, 2018
import Control.Lens (At, Index, IxValue, at, ix, makePrisms, to, (?~))
import Data.Aeson
import Data.Aeson.TH as A
import Data.Aeson.Types (toJSONKeyText, typeMismatch)
import qualified Data.Char as C
import Data.Swagger as S
import Data.Swagger as S hiding (Example, example)
import qualified Data.Swagger as SE (example)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep S instead of SE here. They refer to the same module anyway :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there was a reason. This way I could simply copy-paste the Example-instances and have example refer to Swagger.Example.example, and accessing Data.Swagger.example as SE.example.

So we can, but have to make 50+ references to Example and example qualified. Feels a little bit wrong, but I guess explicitly is good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, but what I meant was simply to have:

import           Data.Swagger hiding (Example, example)
import qualified Data.Swagger as S

Even though, I'd rather list everything we use from Data.Swagger if it's realistic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems borderline unrealistic (2k LoC and lots of things from Data.Swagger). Should I spend time on it? Could perhaps get importify working.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

("unrealistic" as in I got to like 10-20 symbols and then gave up, and not sure if there are 25 in total or 100)


instance Example WalletStateSnapshot



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about removing this whole file, moving the remaining instances in places where they belong 🤔 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KtorZ The remaining ones are

  • WalletSnapshot from ../wallet/src/Pos/Wallet/Web/Methods/Misc.hs
  • CUpdateInfo from ../wallet/src/Pos/Wallet/Web/ClientTypes/Types.hs
  • Mnemonic from ../wallet/src/Pos/Util/Mnemonic

Can we really depend on wallet-new from the old wallet?

Then, also, the class itself, and instances for (), NonEmpty, [], Maybe and Map need to be somewhere.

So it would seem difficult…?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm... Fair point. Not sure why we have this Example in the wallet-new in a first place since it's quite an isolated module. But it doesn't make sense to import anything from the wallet in the old one,

@KtorZ KtorZ added the wip label Jul 9, 2018
@KtorZ KtorZ changed the title [CO-327] [WIP] Rely on Example type-class for Swagger API schema [CO-327] Rely on Example type-class for Swagger API schema Jul 9, 2018
@Anviking Anviking removed the wip label Jul 11, 2018
1. Import and use `Example` typeclass in `../V1/Types.hs`
instead of `Arbitrary`
2. Resolve circular dependencies
`Errors.hs` -> `Types.hs` -> `Example.hs` -> `Response.hs` -> `Errors.hs`
by moving `Example` instances from `Example.hs` to where the datatypes
are defined, so that `Example.hs` does not need to import `Response.hs`
or `Types.hs`.
@KtorZ
Copy link
Contributor

KtorZ commented Jul 17, 2018

Weird failure on appveyor, merging into the feature branch anyway. This doesn't seem related to the PR itself 👍

@KtorZ KtorZ merged commit dc0e5b2 into input-output-hk:Squad1/CO-325/api-v1-improvements Jul 17, 2018
KtorZ added a commit that referenced this pull request Aug 8, 2018
…e-typeclass

[CO-327] Rely on Example type-class for Swagger API schema
KtorZ added a commit that referenced this pull request Aug 9, 2018
…e-typeclass

[CO-327] Rely on Example type-class for Swagger API schema
@Anviking Anviking deleted the anviking/CO-327/swagger-example-typeclass branch September 12, 2018 09:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants