Skip to content

Add crlf to lf conversion to swagger generation #33613

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

Closed
wants to merge 1 commit into from

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Feb 16, 2025

  1. Strip all \r characters from the file, to avoid Windows users from introducing CRLF.
  2. Consistently specify the -e argument to sed, see https://stackoverflow.com/a/66900353/808699 for explanation why both ways with and without -e work, I think it's better to be explicit about it.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 16, 2025
@silverwind silverwind added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Feb 16, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 16, 2025
@lunny
Copy link
Member

lunny commented Feb 17, 2025

I think the last blank line in the v1_json.tmpl is necessary. I tested the generate-swagger command based on this PR. The line will be removed.

@silverwind
Copy link
Member Author

I think the last blank line in the v1_json.tmpl is necessary. I tested the generate-swagger command based on this PR. The line will be removed.

Are you sure? https://github.com/go-gitea/gitea/pull/33613/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R277 should ensure that the final newline is added and this behaviour should not have changed with this PR.

@lunny
Copy link
Member

lunny commented Feb 19, 2025

I think the last blank line in the v1_json.tmpl is necessary. I tested the generate-swagger command based on this PR. The line will be removed.

Are you sure? https://github.com/go-gitea/gitea/pull/33613/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R277 should ensure that the final newline is added and this behaviour should not have changed with this PR.

Yes, I manually tested it in my dev machine.

@ChristopherHX
Copy link
Contributor

I think the last blank line in the v1_json.tmpl is necessary. I tested the generate-swagger command based on this PR. The line will be removed.

Are you sure? https://github.com/go-gitea/gitea/pull/33613/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R277 should ensure that the final newline is added and this behaviour should not have changed with this PR.

Yes, I manually tested it in my dev machine.

Confirm this as well, with and without this I have problems on macOS 15 that this line disappears.

I will try something as well and report back

@silverwind
Copy link
Member Author

@ChristopherHX thanks, looking forward to your investiation. My issue is that the problem does not reproduce on my machine, so if you can reproduce, that is very helpful.

@wxiaoguang
Copy link
Contributor

Confirm this as well, with and without this I have problems on macOS 15 that this line disappears.

I will try something as well and report back

I think the reason is that sed command is not right #33613 (review)

@wxiaoguang
Copy link
Contributor

After reading code, I believe all these sed tricks should be removed.

  1. On Windows, it won't output \r\n, there will always be \n only.
  2. No need to add the final new line, just use the output by Go's json.MarshalIndent

Comment on lines +276 to +277
$(SED_INPLACE) -e 's/\r$$//' './$(SWAGGER_SPEC)' # convert crlf to lf
$(SED_INPLACE) -e '$$a\' './$(SWAGGER_SPEC)' # add final newline
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$(SED_INPLACE) -e 's/\r$$//' './$(SWAGGER_SPEC)' # convert crlf to lf
$(SED_INPLACE) -e '$$a\' './$(SWAGGER_SPEC)' # add final newline

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried this now as well, zero changes on my end

Copy link
Contributor

@wxiaoguang wxiaoguang Feb 20, 2025

Choose a reason for hiding this comment

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

Yes, no final new line is the expected result. Remove the no-sense final new line forever. See #33613 (comment)

just use the output by Go's json.MarshalIndent

Copy link
Contributor

@ChristopherHX ChristopherHX Feb 20, 2025

Choose a reason for hiding this comment

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

This worked at my first try, but no idk what this implies (crlf to lf not needed on my end)

Suggested change
$(SED_INPLACE) -e 's/\r$$//' './$(SWAGGER_SPEC)' # convert crlf to lf
$(SED_INPLACE) -e '$$a\' './$(SWAGGER_SPEC)' # add final newline
$(SED_INPLACE) -e 's/\r$$//' './$(SWAGGER_SPEC)' # convert crlf to lf
echo "" >> './$(SWAGGER_SPEC)' # add final newline

Now I wonder does this cause issues for others? (At least this is what I understand better as this is simple)

EDIT if we agree of removing final newline enforcement ignore this

Copy link
Contributor

Choose a reason for hiding this comment

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

This worked at my first try, but no idk what this implies (crlf to lf not needed on my end)

But I do not think the final new line makes sense here. The file content is just a generated JSON output, no one would really edit it.

@ChristopherHX
Copy link
Contributor

2. No need to add the final new line, just use the output by Go's json.MarshalIndent

Ok in this case, if the ci doesn't enforce the final new line I'm for it

@wxiaoguang
Copy link
Contributor

  1. No need to add the final new line, just use the output by Go's json.MarshalIndent

Ok in this case, if the ci doesn't enforce the final new line I'm for it

CI will be happy because it works like this:

  • Developers generate the json file and commit & push.
  • CI checkouts, and runs the "generate" command again, then "git diff" to see whether the newly generated one is the same as the one in the commit.
  • So since we use the same logic here, the generated file should be the same.

@wxiaoguang
Copy link
Contributor

I managed to use another approach to handle the swagger generation.

-> Improve swagger generation #33664

@silverwind
Copy link
Member Author

Replaced by #33664

@silverwind silverwind closed this Feb 21, 2025
@go-gitea go-gitea locked as resolved and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/internal skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants