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

Replacing init in doc.go as a Register method #1113

Closed
Ferrany1 opened this issue Jan 28, 2022 · 13 comments
Closed

Replacing init in doc.go as a Register method #1113

Ferrany1 opened this issue Jan 28, 2022 · 13 comments

Comments

@Ferrany1
Copy link
Contributor

Is your feature request related to a problem? Please describe.
As for it would be easier to register swagger by myself through a direct import

Describe the solution you'd like
Replacing init with Register method

Describe alternatives you've considered
Adding a configuration (by default keep init) else self register

@Ferrany1
Copy link
Contributor Author

I will implement it by myself if its okay by you @bojand

@ubogdan
Copy link
Contributor

ubogdan commented Jan 28, 2022

@Ferrany1 that's a great idea but we can't break compatibility.

This may be a feature to add maybe in v2.x.x.

@Ferrany1
Copy link
Contributor Author

Ferrany1 commented Jan 28, 2022

Cant it be configured thorough a cli for now? (to not break current usages)

@ubogdan
Copy link
Contributor

ubogdan commented Jan 28, 2022

I'm looking at the pr you make and I'm not sure what exactly do you want to accomplish.

I've understood the fact you may like to have 2 swagger docs in the same packages. Still not sure what is wrong with init function ?

I'm worried because it looks like we are adding possible unnecessary complexity ...

@Ferrany1
Copy link
Contributor Author

@ubogdan No, I want to have 1 doc file and make a direct call for register to handle error and get doc name to handle in ReadDoc later while using my middleware.
As for me init func is worse, because I can't control it, also direct import > blank import as injection

@ubogdan
Copy link
Contributor

ubogdan commented Jan 28, 2022

@ubogdan No, I want to have 1 doc file and make a direct call for register to handle error and get doc name to handle in ReadDoc later while using my middleware.

So then why are u naming the files by instance name ?

@Ferrany1
Copy link
Contributor Author

Ferrany1 commented Jan 28, 2022

Because in my case I have different microservices stored in monorepo and all documentation stored in doc folder, so in this case each doc will overwrite previous, that's why instance name may be necessary in monorepo cases

Because in my case I have different microservices stored in monorepo and all documentation stored in doc folder, so in this case each doc will overwrite previous, that's why instance name may be necessary in monorepo cases

@ubogdan
Copy link
Contributor

ubogdan commented Jan 30, 2022

The init method allows you to register multiple instance names. Why can't you use that?

@Ferrany1
Copy link
Contributor Author

I want to get instance name as a string as well to pass to handler for ReadDoc method

@ubogdan
Copy link
Contributor

ubogdan commented Jan 30, 2022

Okay, but we can introduce breaking changes.

As you may see this repo has 5k followers, you can imagine there are over 5k projects depending on it.

@Ferrany1
Copy link
Contributor Author

But right now I'm not proposing to break contract, just to make option to make a modification

@Ferrany1
Copy link
Contributor Author

It's up to user now handle error or not, this won't break any current repos

@ubogdan
Copy link
Contributor

ubogdan commented Jan 30, 2022

If you look closer, the same pattern was used by the SQL drivers. See MySQL implementation

func init() {
	sql.Register("mysql", &MySQLDriver{})
}

That's been said, the Register method signature cannot be changed and the init method will not be removed.

Please figure out a different way to implement this.

Documentation that was generated with an older version of swagger will stop compiling after a library update because you changed the Register function signature. This is called a breaking change and we can't accept it.

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

No branches or pull requests

2 participants