swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.62k stars 1.19k forks source link

insert a new line at the end of the swagger.json file #1224

Open LordNoteworthy opened 2 years ago

LordNoteworthy commented 2 years ago

Hello,

A humble request to insert a new line at the end of swagger.json.

swagger.yaml seems to be all right.

Thank you.

ubogdan commented 2 years ago

Not sure why we should do this since swagger.json is a valid JSON without a new line.

LordNoteworthy commented 2 years ago

There is no big valid reason it should be, I agree.

It it just because, in general, text files should end with a new line, here is why: https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline

Many people have pre-commit hooks that checks for new line in text files (yaml, json, toml, ..), well I can just exclude it but I taught if you will be keen to insert it.

Anyway, feel free to close this issue if it does not make a lot of sense for this project.

Cheers.

ubogdan commented 2 years ago

well, this is not a "text file" is a petrified JSON data.

I don't find this file useful/importat since we use docs.go in HTTP handlers (eg http-swagger, echo-swagger ).

If this request gets a few votes I don't see why not.

LordNoteworthy commented 2 years ago

Thanks @ubogdan

When I said text file, I meant any non binary file, not necessarily a file terminating with the .txt extension.

The swagger.yaml file that get generated ends with a new line, though it does not need it.

Tt is a POSIX standard that text files should end with a new line, when they don't, it will break some programs like sed.

I don't use the http-swagger handlers, I am only using this project to annotate code and generate the spec file, then I feed it to projects like docusaurus (there is a plugin that offers the same experience as swagger-ui) to generate the documentation.

I agree, let's see if someone will upvote this, then I can issue a PR.

markstickley commented 1 year ago

Hello! I can't see an official way of upvoting but here's my +1...

Our review guidelines stipulate a newline at the end of each file unless there's a good reason not to. This will mean writing a script or manually inserting a newline every time the swagger.json file is generated, unless we can at least define a flag that will add a newline to the end of the output!

Many thanks :)

LordNoteworthy commented 1 year ago

My pre-commit-hook that checks for a new line at end of file also complains about it.

Same @markstickley in my place for work, we have that policy to always do that :)

isaiah-yoon commented 1 year ago

Running into the same issue - my pre-commit hooks are set to add a newline at the end of each file, and conflicts with the current way of generating swagger.json.

jchen42703 commented 1 year ago

Same issue here, My pre-commit complains about the lack of a newline in swagger.json and it would be awesome to have some sort of option to include this! It's been an issue for the past 6 months and it's starting to get on nerves a little (might just add a script to our build pipeline that auto adds the new line at this point lol)

isaiah-yoon commented 1 year ago

If anyone wants a workaround, you can add an exclude tag to forgo end-of-file linting for swagger.json in your .pre-commit-config.yaml.

-   id: end-of-file-fixer
        exclude: |
            (?x)^(
                docs/swagger.json
            )