How to specify line endings (CRLF)
Asked Answered
S

1

9

We're using Swagger Codegen 2.4.5 to generate models from our API. Everything is working exactly as we need with one relatively minor exception.

We're generating C# models, and as per windows these are typically stored with CRLF line endings. Whenever we run the generator these files are generated with the LF line endings.

We'd like all the models to be generated with CRLF instead of LF. Is there a way to modify this behaviour?

I've looked into how mustache is used - a bit - and read through the general command line options for codegen and the csharp specific options (java -jar swagger-codegen-cli-2.4.5.jar config-help -l csharp), and couldn't find anything.

For further clarification:

Currently this is a problem as each time you checkout then run generation again, then models appear as changed. This is simply because they're now encoded with LF line-endings, whereas git has checked them out as CRLF (which we cannot change)

The only other option I can think of at the moment, is to rewrite each file in the project with CRLF after the generation process has completed. I'd prefer it if there was a way via the generator tho.

Storax answered 10/6, 2019 at 11:41 Comment(6)
Do you run codegen on Windows or Mac/*nix?Sacksen
We run codegen on a windows PCStorax
You'll probably need to open an issue at github.com/swagger-api/swagger-codegen/issuesSacksen
For now we have added a .gitattributes file to state that LF eol characters are expected and appropriate for this area of the repository. Not ideal but solves the immediate problemStorax
I'm facing the exact same problem and i'm not able to make my .gitattributes file work. Can you post how your .gitattributes file looks like?Falda
I can't remember exactly what the file looked like, but would have been along the lines of *.cs text eol=lf. See this page for more examples git-scm.com/docs/gitattributesStorax
C
0

this is because of the config by Git. I think this blog will help you. Configuring Git to handle line endings - GitHub Help

solution

git config --global core.autocrlf true
Contraindicate answered 30/12, 2019 at 9:1 Comment(1)
My git config is already set to autocrlf, this affects the way line endings are committed. But doesn't affect the defection of changes locally. If a file is changed to have LF line endings from CRLF (as is happening here) git detects a change, even though the content hasn't (really) changed.Storax

© 2022 - 2024 — McMap. All rights reserved.