question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Unexpected character '«' when generate client API using CSharpClientGenerator

See original GitHub issue
Screen Shot 2563-06-08 at 21 14 45

Project

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="NSwag.CodeGeneration.CSharp" Version="13.6.0" />
  </ItemGroup>

</Project>

Source

  public static class Program {
        private static async Task<OpenApiDocument> FromUrl() {
            const string url = "https://activiti.alfresco.com/activiti-app/api/v2/api-docs?group=enterprise";
            return await OpenApiDocument.FromUrlAsync(url).ConfigureAwait(false);
        }

        private static async Task<OpenApiDocument> FromFile() {
            const string input = "resource/api.json";
            var json = File.ReadAllText(input);
            return await OpenApiDocument.FromJsonAsync(json).ConfigureAwait(false);
        }

        public static async Task Main(string[] _) {
            const string output = "src/ProcessApi/ProcessClient.cs";

            // var single = new SingleClientFromPathSegmentsOperationNameGenerator();

            var settings = new CSharpClientGeneratorSettings {
                ClassName = "ProcessClient",
                ExposeJsonSerializerSettings = true,
                InjectHttpClient = true,
                // OperationNameGenerator = single,
                CSharpGeneratorSettings = {
                    Namespace = "ProcessApi",
                },
            };

            var document = await FromUrl();
            var generator = new CSharpClientGenerator(document, settings);
            var code = generator.GenerateFile();

            File.WriteAllText(output, code);
        }
    }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Jun 9, 2020

Best option is to preprocess the spec and remove these…

0reactions
RicoSutercommented, Sep 29, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected character encountered while parsing value
This is throwing the error: Unexpected character encountered while parsing value: [. when trying to deserialize it in my code: //Create the ...
Read more >
Issues with Swagger-codegen for C#
I am trying to generate client-side code using Swagger-codegen [java ... and do a 'mvn clean install` before generating the C# API client?...
Read more >
Automatically generating C# API clients on build with NSwag
The NSwag target is configured to log the output of nswag.exe as MSBuild messages. If the exit code is anything but 0 and...
Read more >
C# Json.net Unexpected character encountered while parsing ...
C# Xamarin Android Rest call in PCL error "Unexpected character ... Error converting value to type while posting data in Asp.net Core API...
Read more >
The 10 Most Common Mistakes in C# Programming
This tutorial describes 10 of the most common C# programming mistakes made, or problems to be avoided, by C# programmers and provide them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found