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

Specific docs file type write #577

Merged
merged 8 commits into from Jan 18, 2022
Merged

Specific docs file type write #577

merged 8 commits into from Jan 18, 2022

Conversation

jodlajodla
Copy link
Contributor

This PR propose one new feature and fix:

  • Feature: Possibility to specify which docs file to generate - go or json or yaml. Defaults preserved to all file types.
  • Fix: Typo for file name and space before parentheses in cmd package.

Reason for implemented feature:
Needed because I created my own handler for serving static files and the only file I need to show Swagger UI for my API is docs.go. I don't need other files, because I'm setting basic project/docs variables (name, version, description, ...) dynamically at the start of API/Docs server and after swag init they are not fully correct (as expected).

@codecov-io
Copy link

codecov-io commented Dec 9, 2019

Codecov Report

Merging #577 (0a75523) into master (8ffc6c2) will increase coverage by 0.05%.
The diff coverage is 97.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #577      +/-   ##
==========================================
+ Coverage   94.47%   94.53%   +0.05%     
==========================================
  Files           9        9              
  Lines        2316     2341      +25     
==========================================
+ Hits         2188     2213      +25     
  Misses         67       67              
  Partials       61       61              
Impacted Files Coverage Δ
gen/gen.go 93.03% <97.56%> (+0.98%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ffc6c2...0a75523. Read the comment docs.

@ubogdan
Copy link
Contributor

ubogdan commented Dec 11, 2019

@jodlajodla Is there any open issue for this feature?

I'm happy to see our users contributing to swag project, but i don't see any benefit here

  • with the 2 go test you have added the coverage still got down a litle bit 95.89% <92.68%> (-0.81%).
  • skipping .json and .yaml files don't make any difference from a speed perspective.

As a workaround, I propose you should use a .gitignore into your project . or if you use a bash/makefile , you can run rm file immediately after swag init for the files you don't need

@jodlajodla
Copy link
Contributor Author

@ubogdan There is no any open issue for this as I checked. I contributed this because of my own needs for such feature. Your two points are completely valid, but the tests can be improved and the default generating of files is preserved after improvements - I see the generating of specific file as an advantage since additional code doesn't add much to code size and complexity. I implemented this feature just to get rid of the workaround you proposed, but if this doesn't get merged also no problem, I will keep using my fork - just sent this here in good faith if anyone else would need that.

@ubogdan
Copy link
Contributor

ubogdan commented Jan 23, 2020

@easonlin404 what's your input regarding this.

@0rax
Copy link

0rax commented Jul 5, 2021

Just chiming in to say that this feature may be useful when documentation serving and generation is done "out of scope".

In our use case we just require a swagger.json to exists for a service in our monorepo so that it can be used by our documentation builder to generate a ReDoc page and serve it with a Swagger UI, we have no need for the Go or YAML file to be generated.

Right now we are just removing those extraneous files using our Makefile, but it might be nice to be able to just target which type of file we want to generate.

Just wanted to let you know a use-case for this feature, right now we are happy to just remove the useless files ourselves after generation. Do not feel obligated to act on this at all. Just wanted to give you some insights.

@ubogdan
Copy link
Contributor

ubogdan commented Jan 8, 2022

@jodlajodla I will like to do a CR on your work, but I can't until the branch conflicts and imports like "github.com/jodlajodla/swag" get fixed.

@jodlajodla
Copy link
Contributor Author

@ubogdan This should be resolved now. I see there were some changes to the files where I added the code. Will you merge them or can you wait for me to do this by the end of the week?

@ubogdan
Copy link
Contributor

ubogdan commented Jan 11, 2022

@jodlajodla Please fix all the conflicts so I can review your PR. Take your time.

ubogdan
ubogdan previously approved these changes Jan 15, 2022
Copy link
Contributor

@ubogdan ubogdan left a comment

Choose a reason for hiding this comment

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

LGTM

@ubogdan
Copy link
Contributor

ubogdan commented Jan 15, 2022

@jodlajodla Thanks for your contribution!

@ubogdan
Copy link
Contributor

ubogdan commented Jan 15, 2022

Would you mind updating the README.md regarding this new feature?

@jodlajodla
Copy link
Contributor Author

I will do that tomorrow (Sunday).

@ubogdan
Copy link
Contributor

ubogdan commented Jan 15, 2022

@jodlajodla That's fine. Take your time.

@ubogdan ubogdan merged commit 97ea98e into swaggo:master Jan 18, 2022
@ubogdan
Copy link
Contributor

ubogdan commented Jan 18, 2022

@jodlajodla Thanks for your contribution.

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

5 participants