Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a swagger ui page for chain index endpoints #130

Merged
merged 2 commits into from Nov 25, 2021

Conversation

kk-hainq
Copy link
Contributor

@kk-hainq kk-hainq commented Nov 21, 2021

This is a step forward for #129.
image

I have two questions:

  1. Should we derive OpenApi.ToSchema instances with the newtype strategy like the following?
    https://github.com/input-output-hk/plutus-apps/blob/7333e3c3ae62c955c5db7799dbf1c1f58593325d/plutus-ledger/src/Ledger/Orphans.hs#L89

It is cleaner but will lead to imprecise schemas. For instance, the above Slot is returned with getSlot in the tip endpoint.

$ curl -s localhost:9083/tip | jq
{
  "tipBlockId": "fd42a734b285b01d40a90a042a92915c931458c24051e2c7e02de505dcf44ccb",
  "tipSlot": {
    "getSlot": 1714
  },
  "tipBlockNo": 684,
  "tag": "Tip"
}

The answer might be the other way around, to derive/write ToJSON through the newtype strategy more? Most things in Orphans are in plutus though.

  1. It is not so clean responding with a tuple in these endpoints:
    https://github.com/input-output-hk/plutus-apps/blob/7333e3c3ae62c955c5db7799dbf1c1f58593325d/plutus-chain-index-core/src/Plutus/ChainIndex/Api.hs#L110-L112

Should we write a dedicated data type for each case, at least for better Aeson and OpenApi instances?

Pre-submit checklist:

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

@silky
Copy link
Contributor

silky commented Nov 24, 2021

Hey @kk-hainq

Thanks for working on this!

Re: 1) I think it's fine to just use the newtype instances (It's not ideal, but it's what we do elsewhere)

Re: 2) I think a richer type might be nice, I agree.

@kk-hainq kk-hainq force-pushed the chain-index-swagger branch 2 times, most recently from e2c479d to d1f560e Compare November 25, 2021 12:33
Copy link
Contributor

@silky silky left a comment

Choose a reason for hiding this comment

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

Nice, thanks @kk-hainq ! :) If you're happy with it I'll merge?

@kk-hainq
Copy link
Contributor Author

@silky False alarm! I pushed those initial IsUtxoResponse commits to see if I missed any CI checks. I did, have fixed it and completed IsUtxoResponse similarly. The PR should be ready now.

image

Should I update and write more to plutus-chain-index & plutus-chain-index-core's READMEs next?

@silky silky merged commit 21d96e5 into IntersectMBO:main Nov 25, 2021
@kk-hainq kk-hainq deleted the chain-index-swagger branch November 25, 2021 15:23
@silky
Copy link
Contributor

silky commented Nov 25, 2021

Yes, that sounds great! Thanks so much for your work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants