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

Make re-usable helper method for RegisterSwaggerAPI #12149

Closed
4 tasks
ValarDragon opened this issue Jun 3, 2022 · 7 comments · Fixed by #12955
Closed
4 tasks

Make re-usable helper method for RegisterSwaggerAPI #12149

ValarDragon opened this issue Jun 3, 2022 · 7 comments · Fixed by #12955

Comments

@ValarDragon
Copy link
Contributor

ValarDragon commented Jun 3, 2022

Summary

Every SDK app has several lines dedicated to Registering a swagger API, that basically look identical. It would be great if we can just make a default function in baseapp, or server in the SDK, that apps can call unless they need further customization.

Each application I've looked at basically has the lines:

func (app *MyApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
        ...
	if apiConfig.Swagger {
		RegisterSwaggerAPI(clientCtx, apiSvr.Router)
	}

where api and config are

	"github.com/cosmos/cosmos-sdk/server/api"
	"github.com/cosmos/cosmos-sdk/server/config"

respectively.

The RegisterSwaggerAPI is basically the same across many apps. I don't understand why Osmosis does something different tbh, probably something that can be generically handled or we can adapt.

Gaia RegisterSwaggerAPI
Osmosis RegisterSwaggerAPI
Akash RegisterSwaggerAPI

This all seems within the bounds of something we can just call a function in server for! (Would appreciate if anyone figures out whats happening in osmosis' wrt static. Is that re-usable, something that should be a config option, or should it be deleted)

Problem Definition

Eliminate another ~15 lines from every SDK app package, that is noise to most applications.

Proposal

Make a common function, that encompasses the if swagger.Enabled { do default swagger init logic }.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez
Copy link
Contributor

Sounds reasonable to me!

@deepto98
Copy link
Contributor

deepto98 commented Jun 17, 2022

Hi, can I pick this up? It would be helpful if you can point me to the files I need to look at.

@alexanderbez
Copy link
Contributor

Yes please and thank you @deepto98!

@deepto98
Copy link
Contributor

deepto98 commented Jun 19, 2022

@alexanderbez I'm done with the code changes, but I'm getting an error while running make lint test test-race, make format and make lint-fix:

Makefile:72: RocksDB support is disabled; to build and test with RocksDB support, set ENABLE_ROCKSDB=true
golangci-lint run --out-format=tab 
make: golangci-lint: Command not found
make: *** [Makefile:367: lint-go] Error 127

Can you please help me build the project on my local (can't find the exact steps in the doc) and sort this issue?

@alexanderbez
Copy link
Contributor

alexanderbez commented Jun 21, 2022

@deepto98 yes, the fix is here: #12318

Let's get that merged and then we can resume.

@deepto98
Copy link
Contributor

Okay, sure. Thanks for letting me know.

@deepto98
Copy link
Contributor

@alexanderbez I've tried to add the changes in #12352. Do let me know if this looks okay

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