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

Refactor some things for the needs of github.com/go-chai/chai #1094

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

e-nikolov
Copy link

@e-nikolov e-nikolov commented Dec 31, 2021

Describe the PR

I am working on https://github.com/go-chai/chai - an extension for the chi router that provides support for type safe http handlers via generics. This allows it to also provide swagger spec generation that automatically detects the request/response types, http methods and route paths. Chai uses swaggo/swag annotations for the parts of the swagger spec that cannot be automatically inferred.

I am using swaggo/swag as a library but some of the functions that I needed were unexported and others I needed to modify a bit. I forked swag and made the changes I needed there, but I'd rather not have to maintain that fork and put the changes back into swag itself. This is the main place where I use swag.

I am opening this PR as a place for discussion for which parts can be merged into swag.

}

// Generate outputs a swagger spec
func (g *Gen) Generate(swagger *spec.Swagger, config *GenConfig) error {
Copy link
Author

Choose a reason for hiding this comment

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

I moved out of the Build function the parts that deal with generating the files that store the generated swagger spec, because in my case I don't generate the specs from the swag binary, but I want to create the same files that swag does.

@@ -810,6 +810,10 @@ func (operation *Operation) parseCombinedObjectSchema(refType string, astFile *a
}), nil
}

func (operation *Operation) ParseAPIObjectSchema(schemaType, refType string, astFile *ast.File) (*spec.Schema, error) {
Copy link
Author

Choose a reason for hiding this comment

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

I need to use this function for creating a swagger schema for a type name

return filepath.Walk(searchDir, func(path string, f os.FileInfo, _ error) error {
if err := parser.Skip(path, f); err != nil {
// GetAllGoFileInfoAndParseTypes gets all Go source files information for given searchDir and parses the types from them.
func (parser *Parser) GetAllGoFileInfoAndParseTypes(searchDir string) error {
Copy link
Author

Choose a reason for hiding this comment

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

I need this in order to be able to go through packages one by one and incrementally parse the types from them.

I saw that ParseAPIMultiSearchDir() first collects all types from the astFiles and then parses them all at once via parser.packages.ParseTypes(), but in my case that would mean having to do a double pass through all routes, which I'd rather not have to do and instead have a function that parses the types of a single package.

@ubogdan
Copy link
Contributor

ubogdan commented Jan 11, 2022

@e-nikolov Thanks for contributing to this project. The idea of opening a pull request for your project requirements without discussing it on an issue it's very uninspired.

@e-nikolov
Copy link
Author

e-nikolov commented Jan 11, 2022

I'm sorry if a PR wasn't your preference. I thought that making the proposed changes more visible would benefit the discussion. I'm not sure if it would be as easy to talk about each line in an issue.

@ubogdan
Copy link
Contributor

ubogdan commented Jan 20, 2022

@e-nikolov I'm afraid these changes may introduce some breaking changes, and I can't take this responsibility.

@e-nikolov
Copy link
Author

e-nikolov commented Jan 20, 2022

I understand not wanting to break backwards compatibility. Do you think it would be possible to export some of the functions? This way I could make an extension of swaggo/swag without having to fork 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

Successfully merging this pull request may close these issues.

None yet

2 participants