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

Support Restsharp 107 plus #179

Merged
merged 6 commits into from
Jun 16, 2023
Merged

Support Restsharp 107 plus #179

merged 6 commits into from
Jun 16, 2023

Conversation

llimllib
Copy link

@llimllib llimllib commented Jun 16, 2023

🚥 Fixes Kong/httpsnippet#312

🧰 Changes

After version 107, restsharp completely changed their API. This PR fixes the code generator to support the new API.

🧬 QA & Testing

To test this, I:

  • generated all new fixtures with OVERWRITE_EVERYTHING=true npm run test
  • generated a C# hello world project with dotnet new console -o HelloWorld -f net7.0
  • installed RestSharp into it with dotnet add package RestSharp]
  • ran this script and looked for significant differences between csharp and bash:
#!/usr/bin/env bash
set -euxo pipefail
file=Program.cs
mkdir -p fixtures
# for the multipart test
printf "hello" > hello.txt
for fixture in ~/readme/httpsnippet/src/targets/csharp/restsharp/fixtures/*; do
    rm -f $file

    # the custom method isn't supported
    if [[ $fixture == *custom-method* ]]; then continue; fi

    sed 's,test/fixtures/files/hello.txt,hello.txt,' "$fixture" >> $file
    printf 'Console.WriteLine("{0}", response.Content);' >> $file

    dotnet run $file > "fixtures/$(basename "$fixture".out)"
done
#
# now run the bash fixtures for comparison
for fixture in ~/readme/httpsnippet/src/targets/shell/curl/fixtures/*; do
    # the curl for custom-indentation does not work properly, so we need to add
    # || true
    sed 's,test/fixtures/files/hello.txt,hello.txt,' "$fixture" |
        bash > "fixtures/$(basename "$fixture".out)" || true
done

# then, compare the outputs
for fixture in ~/readme/httpsnippet/src/targets/http/http1.1/fixtures/*; do
    base=$(basename "$fixture")
    cs="fixtures/$base.cs.out"
    sh="fixtures/$base.sh.out"

    if [[ ! -e $cs ]]; then printf "Unable to find fixture %s\n" "$cs"; continue; fi
    if [[ ! -e $cs ]]; then printf "Unable to find fixture %s\n" "$sh"; continue; fi

    git diff "fixtures/$base.cs.out" "fixtures/$base.sh.out" || true
done

Updates restsharp support following their breaking
changes, reported in Kong#312
@llimllib
Copy link
Author

test failures appear to be unrelated to this code

@erunion
Copy link
Member

erunion commented Jun 16, 2023

@llimllib I've just updated this branch with the latest, and rebased, main.

Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

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

lgtm! feel free to merge whenever you'd like and i'll cut a new release

@llimllib
Copy link
Author

I think "mostly working" is better than "not at all", so I'll merge this 👍

@llimllib llimllib merged commit 3fd5bbc into main Jun 16, 2023
10 checks passed
@llimllib llimllib deleted the restsharp-107-plus branch June 16, 2023 23:19
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.

C# RestSharp is using deprecated syntax
2 participants