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

kiota-lock.json changes depending on OS #4228

Closed
bkoelman opened this issue Feb 25, 2024 · 4 comments · Fixed by #4932
Closed

kiota-lock.json changes depending on OS #4228

bkoelman opened this issue Feb 25, 2024 · 4 comments · Fixed by #4932
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Milestone

Comments

@bkoelman
Copy link

bkoelman commented Feb 25, 2024

Depending on the operating system on which Kiota is run, the direction of slashes changes in kiota-lock.json. In mixed teams, this results in constant pending changes to this file.

On Windows:

"descriptionLocation": "..\\..\\JsonApiDotNetCoreExample\\GeneratedSwagger\\JsonApiDotNetCoreExample.json",

On Ubuntu:

"descriptionLocation": "../../JsonApiDotNetCoreExample/GeneratedSwagger/JsonApiDotNetCoreExample.json",

Our case is worse, because it breaks the build. We run a tool in cibuild that verifies code style on different platforms, and it never succeeds because of this. Where success is defined as: build the code, run an automated reformat, then fail the build if this resulted in uncommitted git changes.

@github-project-automation github-project-automation bot moved this to Todo in Kiota Feb 25, 2024
@andrueastman andrueastman added type:bug A broken experience generator Issues or improvements relater to generation capabilities. labels Feb 26, 2024
@baywet baywet added this to the Kiota v1.13 milestone Feb 26, 2024
@baywet
Copy link
Member

baywet commented Feb 26, 2024

Hi @bkoelman,
Thanks for reporting this.
The normalization of the path before it gets written down happens here.

lockInfo.DescriptionLocation = GetRelativeDescriptionPath(lockInfo.DescriptionLocation, lockFilePath);

And you can add unit tests in this class.

public async Task UsesRelativePaths()

Do you think you'd be able to send a pull request to correct this issue?

@baywet baywet added the help wanted Issue caused by core project dependency modules or library label Feb 26, 2024
@bkoelman
Copy link
Author

Not anytime soon, I'm pretty occupied with other work at the moment.

@baywet baywet modified the milestones: Kiota v1.13, Backlog Feb 26, 2024
@diegosasw
Copy link

diegosasw commented Jun 27, 2024

I've experienced this problem.
In Windows, I generate code out of a local open api document located at a folder .openapi/openapi.json which is at the solution folder level.
Example:

dotnet kiota generate -l CSharp -o src/Foo/Api -c MyClient -n Foo.Api -d .openapi/openapi.json

This stores the following path in kiota-lock.json:

"descriptionLocation": "..\\..\\..\\.openapi\\openapi.json"

Notice it's Windows style path.

During CI/CD in Github Actions (ubuntu runner), this causes problems because I have a job step doing something like this:

- name: Update SDK
  run: dotnet kiota update -o src/Foo/Api

and this will complain about

crit: Kiota.Builder.KiotaBuilder[0]
      error updating the client: Could not open the file at /home/runner/work/my-repo/my-repo/src/Foo/Api/..\..\..\.openapi\openapi.json, reason: Could not find file '/home/runner/work/my-repo/my-repo/src/Foo/Api/..\..\..\.openapi\openapi.json'.

Workaround

My current workaround is to manually edit kiota-lock.json to set the relative path in Unix style

"descriptionLocation": "../../../.openapi\\openapi.json"

This fixes the problem in GitHub Actions and it seems to keep working locally on my Windows, at least when using dotnet CLI

dotnet kiota update -o src/Foo/Api

I'm not completely sure if using Unix style path always regardless of the OS would be the proper fix, as I don't know the risk with some other tooling.

But, just in case my scenario and workaround helps anyone.

@baywet
Copy link
Member

baywet commented Jun 27, 2024

@diegosasw Thanks for the additional information.
Windows has supported UNIX style paths for a while now and it'd probably be safe to normalize everything to forward slashes.

@andrueastman andrueastman modified the milestones: Backlog, Kiota v1.16 Jul 4, 2024
@andrueastman andrueastman moved this from Todo 📃 to In Progress 🚧 in Kiota Jul 4, 2024
@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants