GithubHelp home page GithubHelp logo

unchase / unchase.openapi.connectedservice Goto Github PK

View Code? Open in Web Editor NEW
100.0 2.0 16.0 9 MB

:scroll: Visual Studio extension to generate OpenAPI (Swagger) web service reference.

Home Page: https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService

License: Apache License 2.0

C# 92.05% PowerShell 7.95%
openapi swagger openapi-codegen openapi-client nswag vsix vsix-extensions visual-studio visual-studio-extension scaffolding

unchase.openapi.connectedservice's Introduction

Logo

Unchase OpenAPI (Swagger) Connected Service is a Visual Studio 2017/2019/2022 extension to generate C# (TypeScript) HttpClient (or C# Controllers) code for OpenAPI (formerly Swagger API) web service with NSwag.

Starting from Visual Studio Community 2019 v16.1.3 extensions based on Microsoft Connected Services now work fine.

The project is developed and maintained by Nikolay Chebotov (Unchase).

Getting Started

Install from Tools -> Extensions and Updates menu inside Visual Studio 2017 (for VisualStudio 2019: Extensions -> Manage Extensions) or download as VSIX package from VSGallery or download as VSIX package from Visual Studio Marketplace:

Adding Unchase OpenAPI (Swagger) Connected Service in Visual Studio

Builds status

Status Value
Build Build status
Buid History Build history
GitHub Release GitHub release
GitHub Release Date GitHub Release Date
GitHub Release Downloads Github Releases
VS Marketplace VS Marketplace
VS Marketplace Downloads VS Marketplace Downloads
VS Marketplace Installs VS Marketplace Installs

Features

  • Generate C# or TypeScript clients/proxies (client code) from Swagger 2.0 and OpenAPI 3.0 specifications
  • Generate C# ASP.NET Controller from Swagger 2.0 and OpenAPI 3.0 specifications
  • Experimental: Generate C# or TypeScript clients/proxies (client code) or ASP.NET Controller from OData specification converted to OpenAPI based on OpenAPI.NET.OData
  • Generate .nswag file for using in NSwagStudio (no need to install for generating)
  • Add required dependencies for the C# client (before generating):
    • Library targeting .NET Standard 1.4+:
      1. Newtonsoft.Json (NuGet)
      2. System.Net.Http (NuGet)
      3. System.ComponentModel.Annotations (NuGet)
    • Library targeting the full .NET:
      1. Newtonsoft.Json (NuGet)
      2. System.Runtime.Serialization (GAC)
      3. System.ComponentModel.DataAnnotations (GAC)
    • Library targeting PCL 259 (Portable Class Library):
      1. Newtonsoft.Json (NuGet)
      2. Microsoft.Net.Http (NuGet)
      3. Portable.DataAnnotations (NuGet)
  • Add Required dependences for the C# controller (before generating):
    1. Microsoft.AspNetCore.Mvc (NuGet)
  • Command to open generated .nswag and .nswag.json files in NSWagStudio
  • Command to compare .nswag.json specification file with another .nswag.json specification file (or specification given by endpoint)
  • Storage of the last 10 endpoints (specification path)

Settings Meaning

Meaning of the Unchase OpenAPI (Swagger) Connected Service settings according to NSwagStudio:

Unchase OpenAPI (Swagger) Connected Service settings meaning

Exclude type names

Since v1.4.0 you can exclude type names in separate Window for C# client code generation:

Unchase OpenAPI (Swagger) Connected Service - exclude type names

Generate code from OData specification converted to OpenAPI specification

Since v1.5.0 you can generate code from OData specification converted to OpenAPI specification:

Unchase OpenAPI (Swagger) Connected Service - generate from OData

Custom Commands

Open in NSwagStudio Command

Since v1.1.* have been added menu command embedded in Visual Studio Solution Explorer context menu lets you open generated .nswag and .nswag.json files in NSwagStudio.

This extension is for those times where you generate .nswag and .nswag.json files and you want to be able to quickly open it in NSwagStudio.

Prerequisite

In order to use this extension, you must have Visual Studio 2017/2019, this connected service as well as NSwagStudio installed.

Solution Explorer

You can open .nswag and .nswag.json files in NSWagStudio by simply right-clicking it in Solution Explorer and select Open in NSwagStudio:

Open in NSwagStudio menu Command

Path to NSwagStudio.exe

If you installed NSwagStudio at a non-default location, a prompt will ask for the path to NSwagStudio.exe.

You can always change the location in Tools -> Options -> Web -> Unchase OpenAPI (Swagger) Connected Service:

Open in NSwagStudio Option

Compare OpenAPI-specifications... Command

Since v1.2.* have been added menu command embedded in Visual Studio Solution Explorer context menu lets you compare generated .nswag.json specification-file with another .nswag.json specification-file (or with specification given by endpoint).

This extension is for those times where you generate .nswag.json file and you want to quickly compare it with another specification or specification given by endpoint.

Prerequisite

In order to use this extension, you must have Visual Studio 2017/2019 as well as this connected service.

Solution Explorer

You can compare .nswag.json specification-file with another .nswag.json specification-file (or with specification given by endpoint) by simply selecting one or two files and right-clicking them in Solution Explorer and select Compare OpenAPI-specifications...:

Compare OpenAPI Specifications Command Compare OpenAPI Specifications Command

Path to the specification Endpoint

You can always change the specification Endpoint to compare with in Tools -> Options -> Web -> Unchase OpenAPI (Swagger) Connected Service:

Compare OpenAPI Specifications Option

Compare View

Compare OpenAPI Specifications Command result

HowTos

Troubleshooting

Can't open .nswag file in NSwagStudio

  • You can use Open in NSwagStudio menu command
  • If generated code corrupted, try to open .nswag file in NSwagStudio (Windows GUI for editing .*nswag files)
  • If it doesn't open, try to create new .nswag file in NSwagStudio for the same API service link and check the differences

Installation completes but I can't see the Service in the list of connected services (Visual Studio 2019)

Roadmap

See the changelog for the further development plans and version history.

Feedback

Please feel free to add your review, request a feature, ask a question or report a bug including in connected service:

Unchase OpenAPI Connected Service Report a Bug

Thank you in advance!

Thank me!

If you like what I am doing and you would like to thank me, please consider:

Buy me a coffe!

Thank you for your support!


Copyright © 2019 Nikolay Chebotov (Unchase) - Provided under the Apache License 2.0.

unchase.openapi.connectedservice's People

Contributors

matherm-aboehm avatar unchase avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

unchase.openapi.connectedservice's Issues

Incorrect generated method names

Generated method names contain endpoint name and request type e.g. PostersGetAsync, while client generated with built-in tool creates names according to description (parameter operationId) e.g. GeneratePosterRequestAsync

Visual Studio 2022 Support

Installed product versions

Visual Studio: 2022 All Versions

Description

Make the extension available in Visual Studio 2022.

Steps to recreate

  1. Download the extension installer.
  2. Run the installer.

Current behaviour

The message that it is already installed to all applicable products appears even though it is not installed in Visual Studio 2022.
It is also not listed in Online Extensions in Manage Extensions Visual Studio 2022.

Expected behaviour

Installs and works in Visual Studio 2022.

Note: Sorry for all the extra details. I probably could have stopped with the title on this one.

BUG: Could not load file or assembly 'YamlDotNet, Version=5.0.0.0' when trying to generate code

Describe the bug

When I try to use the Unchase Connected Service Tool v1.4.7 to generate client and/or controller code from a YAML file, I get an error referencing YamlDotNet. I have the problem whether trying to generate the code for the first time, or if trying to update the connected service. Manually adding YamlDotNet version 5.0.0 to the project did not resolve the problem.

Use this public YAML to generate against: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

Assemblies affected

YamlDotNet.

Steps to reproduce

The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue:

  1. Open a Visual Studio Solution.
  2. Within the Connected Services section, right click on the service and select "Updated Unchase OpenAPI..." from the context menu which appears.
  3. Generate for https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
  4. Choose to generate both Client and Controller code.
  5. Select Finish.
  6. Select "Yes" if prompted to replace the .nswag file.

Expected result

C# code should be generated.

Actual result

No C# code is generated. From the Output window:
[5/13/2020 6:11:26.450 PM] Adding Unchase OpenAPI (Swagger) Connected Service to the project.
[5/13/2020 6:11:26.450 PM] Adding service instance for "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml"...
[5/13/2020 6:11:26.452 PM] Adding Nuget Packages for OpenAPI (Swagger) CSharp Client...
[5/13/2020 6:11:26.456 PM] Nuget Package "Newtonsoft.Json" for OpenAPI (Swagger) already installed.
[5/13/2020 6:11:26.458 PM] Nuget Packages for OpenAPI (Swagger) CSharp Client were installed.
[5/13/2020 6:11:26.461 PM] Adding Nuget Packages for OpenAPI (Swagger) CSharp Controller...
[5/13/2020 6:11:26.465 PM] Nuget Package "Microsoft.AspNetCore.Mvc" for OpenAPI (Swagger) already installed.
[5/13/2020 6:11:26.467 PM] Nuget Packages for OpenAPI (Swagger) CSharp Controller were installed.
[5/13/2020 6:11:26.469 PM] Generating NSwag-file for OpenAPI (Swagger)...
[5/13/2020 6:11:26.499 PM] NSwag-file "YamlPet.nswag" for OpenAPI (Swagger) was generated.
[5/13/2020 6:11:26.500 PM] Generating Client Proxy for OpenAPI (Swagger) Client...
[5/13/2020 6:11:26.549 PM] Warning:Error: Could not load file or assembly 'YamlDotNet, Version=5.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e' or one of its dependencies. The system cannot find the file specified..
[5/13/2020 6:11:26.552 PM] Client Proxy for OpenAPI (Swagger) Client was generated.
[5/13/2020 6:11:26.553 PM] Adding service instance complete!
[5/13/2020 6:11:26.624 PM] Finished adding Unchase OpenAPI (Swagger) Connected Service to the project.

Environment

Windows 10
Visual Studio Enterprise 2017, v15.9.14
Windows C# solution created targeting .NET Framework 4.8.03752

Microsoft.CodeAnalysis package not deploy with extension package

I installed the latest version of the extension and an error started saying that I can't find the Microsoft.CodeAnalysis package when I'm generating the CSharp client.

In order to use the version I had to copy the DLL (Microsoft.CodeAnalysis, 3.4.0) to the extension installation folder.

Could you put the DLL as part of the package in the next version?
Thanks

Unable to read string as a response

Hi,
I am unable to read the string response, as it always tries to deserialize the response. is there any way to read the string, int without deserialization?

BUG: Data Annotations in DTO generated even if option is unticked

Describe the bug

The tooling seems to ignore the option Generate data annotation attributes.

Assemblies affected

CSharp Client Settings - c# DTO generation

Steps to reproduce

Use tooling to create DTOs only (without client)
...

Expected result

Expected Code Snipped of the Generated.cs

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.0.27.0 (Newtonsoft.Json v12.0.0.2)")]
    public partial class ACHPmtBasicType 
    {
        public string AchpmtId { get; set; }
    

Actual result

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.0.27.0 (Newtonsoft.Json v12.0.0.2)")]
    public partial class ACHPmtBasicType 
    {
        [Newtonsoft.Json.JsonProperty("achpmtId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public string AchpmtId { get; set; }
    

How do I change method naming convention?

I would like to change method naming convention to have less verbose naming, is it possible?

Current behavior:
path: /api/services/app/Account/Register
csharp method: ApiServicesAppAccountRegister

Expected: AppAccountRegister

Thank you!

Cannot use parent class in client

Hi,

i have two classes both with the same parent class


CLASSES
public class MailMessageSmtpData : MailData
{
     public int SmtpPort { get; set; }
}

public class MailMessageSendGridData : MailData
{
     public int ApiKey{ get; set; }
}

public class MailData
{
     public string Subject { get; set; }
}

CONTROLLER

[HttpPost]
[Route("mail/smtp")]
[ProducesResponseType(typeof(MailMessage), 200)]
public async Task<IActionResult> SendSmtpMail([FromBody] MailMessageSmtpData m)
{
     return Ok(await new MailMessageService().SendMailWithSmtp(m));
}

[HttpPost]
[Route("mail/sendgrid")]
[ProducesResponseType(typeof(MailMessage), 200)]
public async Task<IActionResult> SendSendGridMail([FromBody]  MailMessageSendGridData m)
{
     return Ok(await new MailMessageService().SendMailWithSendGrid(m));
}



CLIENT CODE

-> MailData Class did not exist
 private MailData data= new MailData(); 

My problem here is that i can't instantiate an object from type MailData in my client code.
Can't find the MailData class in the generated code.

How can i solve this issue?

Updating / Regenerating a service client causes error in Visual Studio

UpdateFailure

If you try to update a previously added connected service (OpenAPI C# client) an error happens and Visual Studio shows a message box. The connected service is also not updated.

The error message is:

Connected Services

The Connected Services component 'Unchase OpenAPI
(Swagger) Connected Service' failed: (HRESULT:0x80131500)
Error setting value to 'PathPrefix' on
'Microsoft.OpenApi.OData.OpenApiConvertSettings'.

BUG generated code fails with runtime error

Describe the bug

the generated code at line 1493 var dictionary_ = in attached file fails with error below
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(parameterValues, settings.Value);
var dictionary
= Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, string>>(json_, _settings.Value);

Assemblies affected

Which assemblies and versions are known to be affected?

Steps to reproduce

using .net core 3.1
add the attached class UnchaseIssueDemo.cs.txt to a console app or other host app.
Run the code

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error
    ...

Expected result

A clear and concise description of what you expected to happen.
expect generated code to work

Actual result

What is actually happening.
UnchaseIssueDemo.cs.txt
ContentAccessAPIClient.cs.txt

get error
Message=Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
ContentAccessAPIClient.cs.txt

If applicable, add screenshots to help explain your problem.

Additional detail

Add any other context about the problem here.
Optional, details of the root cause if known.

Error: Exception has been thrown by the target of an invocation..

When generating C# client with option: Generate contracts output

Re-adding service instance for "C:\tmp\c#\WebAPI\zzi.si-e-customs-1.0.0-resolved.json"...
Generating NSwag-file for OpenAPI (Swagger)...
NSwag-file "eCustomsAPI.nswag" for OpenAPI (Swagger) was generated.
Generating Client Proxy for OpenAPI (Swagger) Client...
Warning:Error: Exception has been thrown by the target of an invocation..
Client Proxy for OpenAPI (Swagger) Client was generated.
Re-Adding service instance complete!

Client is NOT generated .. what is wrong?

zzi.si-e-customs-1.0.0-resolved.txt

BUG Fixes : Need modification in generated serializer

Hi,

I had an issue of including subclasses using swagger and I have resolved it by introducing the $type variable upon which JsonInheritanceConverter class is generated but my other methods which include child class stopped working. The exception was thrown on the below line as code was unable to find discriminator value in child class.

var discriminator = Newtonsoft.Json.Linq.Extensions.Value<string>(jObject.GetValue(_discriminator));

To resolve this i have modified the generated code manually by replacing the above line with

var discriminator = "";
if (jObject.TryGetValue(_discriminator, out var jToken))
{
discriminator = Newtonsoft.Json.Linq.Extensions.Value<string>(jToken);
}
So it would be great if you can modify the extension so it will be code safe for the child classes.

Error caused when generating C# code from OpenApi json file (Bungie.net API)

Software versions:

  • Unchase 1.5.10
  • Visual Studio 2019 Pro 16.8.3

When using the OpenApi specification json file available from: https://github.com/Bungie-net/api/blob/master/openapi.json

And using the following options:

image

Unchase generator produces the following output:

Adding service instance for "D:\Downloads\openapi.json"...
Adding Nuget Packages for OpenAPI (Swagger) CSharp Client...
Nuget Package "Newtonsoft.Json" for OpenAPI (Swagger) already installed.
Nuget Package "System.Net.Http" for OpenAPI (Swagger) already installed.
Nuget Package "System.ComponentModel.Annotations" for OpenAPI (Swagger) already installed.
Nuget Packages for OpenAPI (Swagger) CSharp Client were installed.
Generating NSwag-file for OpenAPI (Swagger)...
NSwag-file "OpenAPI.nswag" for OpenAPI (Swagger) was generated.
Generating Client Proxy for OpenAPI (Swagger) Client...
Warning:Error: Error converting value True to type 'System.Collections.Generic.ICollection`1[System.String]'. Path 'components.headers.X-API-Key.required', line 41425, position 24..
Client Proxy for OpenAPI (Swagger) Client was generated.
Adding service instance complete!

No client code is generated.

I am uncertain if this is caused by an invalid OpenAPI json file, if this is something that I am doing wrong, or if this is an odd edge case. Source OpenAPI json is attached.

openapi.zip

If there is any additional information that I can provide which will be helpful please let me know.

no code generated

It appears that there is an error with a path variable or something but no suggestion what to do. I only used default settings. Here is the output. What should I do?

Adding Nuget Packages for OpenAPI (Swagger) CSharp Client...
Nuget Package "Newtonsoft.Json" for OpenAPI (Swagger) already installed.
Nuget Package "System.Net.Http" for OpenAPI (Swagger) already installed.
Nuget Package "System.ComponentModel.Annotations" for OpenAPI (Swagger) already installed.
Nuget Packages for OpenAPI (Swagger) CSharp Client were installed.
Generating NSwag-file for OpenAPI (Swagger)...
NSwag-file "ArtistApiService.nswag" for OpenAPI (Swagger) was generated.
Generating Client Proxy for OpenAPI (Swagger) Client...
Warning:Error: Unexpected character encountered while parsing value: <. Path '', line 0, position 0..
Client Proxy for OpenAPI (Swagger) Client was generated.
Adding service instance complete!

Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0

Seems the Connected Service is dependent upon a nuget package that doesnt exist anymore.

Adding service instance for "https://raw.githubusercontent.com/unbound-tech/ukc_rest/master/admin.yaml"... Adding Nuget Packages for OpenAPI (Swagger) CSharp Client... Nuget Package "Newtonsoft.Json" for OpenAPI (Swagger) already installed. Nuget Package "System.Net.Http" for OpenAPI (Swagger) already installed. Nuget Package "System.ComponentModel.Annotations" for OpenAPI (Swagger) already installed. Nuget Packages for OpenAPI (Swagger) CSharp Client were installed. Generating NSwag-file for OpenAPI (Swagger)... Warning:NSwag-file for OpenAPI (Swagger) was not generated. Error: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040). Generating Client Proxy for OpenAPI (Swagger) Client... Warning:Client Proxy for OpenAPI (Swagger) Client was not generated. Error: Object reference not set to an instance of an object.. Adding service instance complete! Error:Adding Unchase OpenAPI (Swagger) Connected Service to the project failed: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Use relative specification file path not working as expected

Describe the bug

I select "use relative specification file path" and only leave the file name of my specification.yaml in the "will combine with:" edit field. When I click finish and inspect the generated files, the "Endpoint" setting in the "ConnectedService.json" contains the full path to the specification. When you then run the wizard again through "Update Unchase OpenAPI (Swagger) Connected Service...", the "will combine with:" edit field now contains the full path as well.

Assemblies affected

Unchase OpenAPI (Swagger) Connected Service 1.5.8

Expected result

I would expect the full path to be constructed at run-time using the project directory and the path to the specification file, relative to it, so that the project can be used independently from it's location (and shared between devs).

Actual result

The full path to the specification.yaml file is saved inside "ConnectedService.json" and as soon as you rename the solution folder, or move the solution folder to a different location, the next time you start the wizard, it fails.

Route Template

is here a way to template a routing
example
api/blahblah/{controller}/blahblah/{action}

Error: Cannot populate JSON array onto ype 'NJsonSchema.JsonSchemaProperty'

Describe the bug

When trying to populate this spec, I get the following error:

Error: Cannot populate JSON array onto ype 'NJsonSchema.JsonSchemaProperty'. Path 'definitions.Granularity.properties.enum', line 35, position 17..

And the client doesn't generate.

Assemblies affected

Which assemblies and versions are known to be affected?

Steps to reproduce

The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue:

  1. Create a new VS project
  2. Try adding a connected service of the attached file
  3. See error

Expected result

Clients generated

Actual result

Error

Screenshots

image

I cannot generate code from file with size 528kb

I trying to generate client code for open api json file with size 528kb and it does not work, but, when i try with another file with size 115kb, that file works. Is it possible to fix this?

Question: Is there a way to re-generate from ConnectedService.json

Hi,

This service is great!

I however, don't understand what the ConnectedService.json is supposed to do if there is no way to re-generate the classes from it?
I can modify MyClient.nswag and open it in nswag studio, and that works, but what is the ConnectedService.json for then?

My gut feeling is that I'm just missing something and I can't seem to find a setting/button for this.

Dave

After update on v1.5.19 from v1.5.17 cannot serialized object.

new HttpClient add:
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(tenderTypeAttachementApiDTO, settings.Value);
var dictionary
= Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, string>>(json_, settings.Value);
var content
= new System.Net.Http.FormUrlEncodedContent(dictionary_);

Error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' because the type requires a JSON object (e.g. \name:\value) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. \name:\value) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1.

Incorrect `DisallowNull`

Describe the bug

swagger.json describes an optional parameter but a DisallowNull tag is generated for it.

Assemblies affected

Generated using the NSwag toolchain v13.6.1.0 (NJsonSchema v10.1.21.0 (Newtonsoft.Json v12.0.0.2))

Steps to reproduce

My class looks like this:

public abstract class Option
{
    protected Option(string? error)
    {
        this.Error = error;
        this.HasFailed = error != null;
    }

    public string? Error { get; }

    public bool HasFailed { get; }
}

public sealed class Option<T> : Option
    where T : class
{
    public Option(T? value, string? error)
    : base(error)
    {
        this.Value = value;
    }

    public T? Value { get; set; }
}

When I use this class, like Option<AccountDto>, it generates this json:

"AccountDtoOption":{
  "type":"object",
  "properties":{
	 "value":{
		"$ref":"#/components/schemas/AccountDto"
	 },
	 "error":{
		"type":"string",
		"nullable":true
	 },
	 "hasFailed":{
		"type":"boolean"
	 }
  },
  "additionalProperties":false
}

Which generates the following model in the client:

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v12.0.0.2)")]
public partial class AccountDtoOption 
{
    [Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public AccountDto? Value { get; set; }

    [Newtonsoft.Json.JsonProperty("error", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public string? Error { get; set; }

    [Newtonsoft.Json.JsonProperty("hasFailed", Required = Newtonsoft.Json.Required.Always)]
    public bool HasFailed { get; set; }
}

Expected result

I expect the generated JsonPropertyattribute for the Value property to have its Requred property set to AllowNull. It even adds a nullable sign (?) to the Value property.

Error during Client Proxy generation

Hey,

my openapi.json file openapi.zip for a MicroStrategy REST API seems to be invalid. The code generation fails with following error:

Error: Error while rendering Liquid template CSharp/Client.Class:
System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei NSwag.CodeGeneration.Models.OperationModelBase`2.get_UnwrappedResultType()

Do you have any idea why this happens? Exists a method for enabling verbose log mode in NSwag? Thx a lot.

Regards
Thomas

VS 2019 OpenAPI code generator same as Unchase?

Hi, im using the latest version of VS 2019 and have added a swagger service reference in Connected Services.

Im trying to get the generated httpclient to include a custom type (converted from string (example: BigInteger)). How can this be done using Unchase and is it the same way when using VS Connected Services directly?

Hope you can help.

Code generation with DateTimeOffset? under .NET 5 with JsonSchema v10.3.1.0 and NSwag v13.9.3.0

 public async System.Threading.Tasks.Task OrderEntryAsync(string x_client_id, string x_client_secret, System.DateTimeOffset? x_message_timestamp, string x_message_id, string x_correlation_id_internal, string x_correlation_id_external, string x_external_reference_id, string x_domain, Order_entry generated, System.Threading.CancellationToken cancellationToken)
        {
            var urlBuilder_ = new System.Text.StringBuilder();
            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/order_entry");
    
            var client_ = _httpClient;
            var disposeClient_ = false;
            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    if (x_client_id == null)
                        throw new System.ArgumentNullException("x_client_id");
                    request_.Headers.TryAddWithoutValidation("x-client-id", ConvertToString(x_client_id, System.Globalization.CultureInfo.InvariantCulture));
                    if (x_client_secret == null)
                        throw new System.ArgumentNullException("x_client_secret");
                    request_.Headers.TryAddWithoutValidation("x-client-secret", ConvertToString(x_client_secret, System.Globalization.CultureInfo.InvariantCulture));
                    if (x_message_timestamp != null)
if (x_message_timestamp != null)
                        request_.Headers.TryAddWithoutValidation("x-message-timestamp", System.Uri.EscapeDataString(x_message_timestamp.ToString("s", System.Globalization.CultureInfo.InvariantCulture)));

The Compiler complains that ToString takes 2 arguments for x_message_timestamp

x_message_timestamp is delcared as System.DateTimeOffset?

If I change the code to use GetValueOrDefault() it works, which I will use for now as workaround.

if (x_message_timestamp != null)
if (x_message_timestamp != null)
                        request_.Headers.TryAddWithoutValidation("x-message-timestamp", System.Uri.EscapeDataString(x_message_timestamp.GetValueOrDefault().ToString("s", System.Globalization.CultureInfo.InvariantCulture)));

DOC

Hello,

did i need both CSharp Client and Controller ?
And how can i use the Api in my Code? I can't access to the functions.
Did you have a working sample project?

Thank you
Kevin

How do I add http header attributes and values using the generated web api client

Hello There, I need your help/advice. I have installed Connected Service tool on Visual Studio 2019 and followed your instructions to generate web Api client.

I was able generate the client successfully and was able to invoke the endpoint methods.

Now I have to pass HTTP headers to the end point, how can I set the values for each Header property without altering the generated code.

Thank you

-Arvin

Error trying to update the connected service

When trying to execute Update Unchase OpenAPI (Swagger) Connected Service... on a connected service, which was generated with an older version, I get the following error:
grafik

When I set the OpenApiConvertSettings->PathPrefix to "OData" in ConnectedService.json and save the file, the above command works and the Wizard displays correctly.

My Version: 1.5.26

Feature Request: Allow Relative Path for swagger.json file

Basically, the tooling currently supports a URI or a file.
The URI is great in most cases, however in our use-case, the URI cannot be reached (due to network restrictions / proxy).

Therefore a file based approach works, however a full relative path is used instead of a relative path to the project (such that the swagger.json can be checked in and updated as required in the future but linked form the source repository rather than a full file path)

Hopefully I was clear enough in my explanation. Thank you

Updating / Regenerating a service client causes error in Visual Studio

Describe the bug

If you try to update a previously added connected service (OpenAPI C# client) an error happens and Visual Studio shows a message box. The connected service is also not updated.

The error message is:

Connected Services

The Connected Services component 'Unchase OpenAPI 
(Swagger) Connected Service' failed: (HRESULT:0x80131500) 
Error setting value to 'PathPrefix' on 
'Microsoft.OpenApi.OData.OpenApiConvertSettings'.

Assemblies affected

v1.5.13

Steps to reproduce

  1. Open a project with an existing OpenAPI C# client
  2. Click on 'Connected Services'
  3. Right-click on the 'client folder'
  4. Click 'Update Unchase OpenAPI (Swagger) Connected Service...'
  5. Error happens - Message box is shown

Expected result

The C# client is updated to the current state as specified by the API URI

Actual result

An error message is shown. Otherwise nothing happens

Additional detail

The likely cause is the recent dependency update of Microsoft.OpenApi.OData to v1.0.6
As v1.0.6 contains the following commit Add Path provider and path prefix provider into setting

Now PathPrefix being null or the empty string is blocked in OpenApiConvertSettings.cs

The ConnectedService.json generated by this extension - which is loaded when you want to update the c# client - contains "PathPrefix": null, which causes the described error.

If you manually change the content to e.g. "PathPrefix": "/", you can update the c# client once but afterwards PathPrefix is again set to null

The Extension doesn't restore the previous settings for a client update.

The Extension doesn't restore the previous settings for a client update. I have to re-enter settings like the base class every time. I would also be very nice, if you could just right-click the json file to update the client.

Other than that, it is a real time saver. Thank you so much.

Compilation error generating C# client. Not all code paths return a value.

An invalid method has been generated.
The method has a code path which does not return anything.
As far as I can see it seems to only affect methods which have a return type of System.Collections.Generic.ICollection<long> in my project. Other simular methods return default(sometype), except for the type stated before.

The json used to generate the client can be downloaded from the file attached to this issue.

swaggerfile.json.txt

Impossible to add multiple connected services?

I want to add multiple services (multiple swagger docs), however when I click on the service reference I get a pop-up to update the existing service:
image
Is there a way to add a second one?

System.InvalidOperationException: Sequence contains more than one matching element

Hello all,
i get an error while generating c# client:

Generating NSwag-file for OpenAPI (Swagger)...
NSwag-file "UnchaseApi.nswag" for OpenAPI (Swagger) was generated.
Generating Client Proxy for OpenAPI (Swagger) Client...
Warning:Error: Error while rendering Liquid template CSharp/Class: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at NJsonSchema.CodeGeneration.Models.ClassTemplateModelBase.DerivedClassModel..ctor(String typeName, JsonSchema schema, OpenApiDiscriminator discriminator, TypeResolverBase resolver)
   at NJsonSchema.CodeGeneration.Models.ClassTemplateModelBase.<get_DerivedClasses>b__16_0(KeyValuePair`2 p)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at NJsonSchema.CodeGeneration.Models.ClassTemplateModelBase.get_DerivedClasses()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at NJsonSchema.CodeGeneration.LiquidProxyHash.GetValue(String key)
   at DotLiquid.Hash.System.Collections.IDictionary.get_Item(Object key)
   at DotLiquid.Context.LookupAndEvaluate(Object obj, Object key)
   at DotLiquid.Context.FindVariable(String key)
   at DotLiquid.Context.Variable(String markup, Boolean notifyNotFound)
   at DotLiquid.Context.Resolve(String key, Boolean notifyNotFound)
   at DotLiquid.Tags.For.Render(Context context, TextWriter result)
   at DotLiquid.Block.RenderAll(List`1 list, Context context, TextWriter result)
--- End of stack trace from previous location where exception was thrown ---
   at DotLiquid.Context.HandleError(Exception ex)
   at DotLiquid.Block.RenderAll(List`1 list, Context context, TextWriter result)
   at DotLiquid.Tags.If.<>c__DisplayClass11_0.<Render>b__0()
   at DotLiquid.Context.Stack(Hash newScope, Action callback)
   at DotLiquid.Tags.If.Render(Context context, TextWriter result)
   at DotLiquid.Block.RenderAll(List`1 list, Context context, TextWriter result)
--- End of stack trace from previous location where exception was thrown ---
   at DotLiquid.Context.HandleError(Exception ex)
   at DotLiquid.Block.RenderAll(List`1 list, Context context, TextWriter result)
   at DotLiquid.Document.Render(Context context, TextWriter result)
   at DotLiquid.Template.RenderInternal(TextWriter result, RenderParameters parameters)
   at DotLiquid.Template.Render(TextWriter writer, RenderParameters parameters)
   at DotLiquid.Template.Render(RenderParameters parameters)
   at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render().
Client Proxy for OpenAPI (Swagger) Client was generated.
Re-Adding service instance complete!

And it seems that this yaml definition is the source ot it:

    JobEvent:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/Uuid4'
        job_id:
          $ref: '#/components/schemas/Uuid4'
        driver_id:
          $ref: '#/components/schemas/Uuid4'
        latitude:
          $ref: '#/components/schemas/GeoCoordinate'
        longitude:
          $ref: '#/components/schemas/GeoCoordinate'
        type:
          enum:
            - on_the_way
            - arrived
            - set_up
            - set_down
            - captured_weightg
            - cashed_up
            - initial_weighed
            - final_weigehd
            - delay
            - status_updated
            - customer_signed
            - position_update
            - message
            - trash_type_changed
            - disposal_plant_changed
            - container_type_changed
            - container_amount_changed
          example: arrived
          description: |
            * on_the_way - driver is on the way to his destination
            * arrived - driver has arrived at his destination
            * set_up - container has been set up
            * set_down - container has been set down
            * captured_weight - weight has been captured by the vehicle
            * cashed_up - payment process has been handeled
            * initial_weighed - initial weight has been taken with load scale
            * final_weighed - weight has been taken with load scale
            * delay - processing delays
            * status_updated - the job status (started, parking ...) has been updated
            * customer_signed - customer has signed
            * message - a message has been sent from the driver app
            * position_updated - driver position update
            * trash_type_changed - driver has changed the trash type
            * disposal_plant_changed - driver has chanegd the disposal plant
            * container_type_changed - driver has changed the container type
            * container_amount_changed - driver has changed the container amount
        created_at:
          $ref: '#/components/schemas/DateTime'
        updated_at:
          $ref: '#/components/schemas/DateTime'
      required:
        - id
        - latitude
        - longitude
        - type
        - created_at
      discriminator:
        propertyName: type
        mapping:
          on_the_way: '#/components/schemas/DrivingJobEvent'
          arrived: '#/components/schemas/DrivingJobEvent'
          set_up: '#/components/schemas/SetContainerJobEvent'
          set_down: '#/components/schemas/SetContainerJobEvent'
          captured_weight: '#/components/schemas/CapturedWeightJobEvent'
          cashed_up: '#/components/schemas/CashedUpJobEvent'
          final_weighed: '#/components/schemas/FinalWeighedJobEvent'
          initial_weighed: '#/components/schemas/InitialWeighedJobEvent'
          delay: '#/components/schemas/DelayJobEvent'
          status_updated: '#/components/schemas/StatusUpdatedJobEvent'
          customer_signed: '#/components/schemas/CustomerSignedJobEvent'
          position_updated: '#/components/schemas/PositionUpdatedJobEvent'
          message: '#/components/schemas/MessageJobEvent'
          trash_type_changed: '#/components/schemas/TrashTypeChangedJobEvent'
          container_type_changed: '#/components/schemas/ContainerTypeChangedJobEvent'
          container_amount_changed: '#/components/schemas/ContainerAmountChangedJobEvent'
          disposal_plant_changed: '#/components/schemas/DisposalPlantChangedJobEvent'

    DrivingJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                destination:
                  enum:
                    - customer
                    - disposal_plant
                    - depot
                  description: |
                    * customer - on the way to/arrived at the customer
                    * disposal_plant - on the way to/arrived at the disposal_plant
                    * depot - on the way to/arrived at the depot
              required:
                - destination
          required:
            - paylaod

    SetContainerJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                container_id:
                  $ref: '#/components/schemas/Uuid4'
                is_filled:
                  type: boolean
                  example: true
                  description: Is this container filled or empty
              required:
                - container_id
                - is_filled
          required:
            - payload

    CapturedWeightJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            playload:
              type: array
              items:
                type: object
                properties:
                  weight:
                    type: number
                    format: float
                    example: 253.5
                    description: Weight in kg.
                required:
                  - weight
          required:
            - paylaod

    CashedUpJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                payment_method:
                  enum:
                    - cash
                    - by_card
                    - none
                  description: |
                    * cash - payed cash
                    * by_card - payed by ec or credit card
                    * none - not paid, see additional_info
                  example: cash
                additional_info:
                  type: string
              required:
                - payment_method
          required:
            - payload

    FinalWeighedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                items:
                  type: array
                  minItems: 1
                  maxItems: 6
                  items:
                    type: object
                    properties:
                      weight:
                        type: number
                        format: float
                        example: 2.4
                        description: Weight in tons
                      certificate_number:
                        type: string
                        description: The weighing certificate's number
                        example: NHDBKD-232
                      certificate_image:
                        type: string
                        description: URL to image
                        example: https://xxxxxx-media-provider.de/123e4567-e89b-12d3-a456-426614174000.jpg
                      foreign_weighing:
                        type: boolean
                        example: false
                        description: Has weighing been done by another company?
                    required:
                      - weight
                      - certificate_number
                      - foreign_weighing
              required:
                - items
          required:
            - paylaod

    DelayJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                reason:
                  enum:
                    - traffic
                    - pause
                    - waiting
                  example: traffic
                  description: |
                    * traffic - much traffic or traffic jam
                    * pause - driver has set the job to pause
                    * waiting - driver is waiting for something
                additional_info:
                  type: string
                  example: traffic jam in the city
                  description: Optional additional information from driver
                amount:
                  type: integer
                  example: 30
                  description: Amount of delay time in minutes.
              required:
                - reason
                - amount
          required:
            - paylaod

    InitialWeighedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - description: Driver has done an initial weighing at the disposal plant.

    StatusUpdatedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                status:
                  enum:
                    - started
                    - resumed
                    - paused
                    - cancelled
                    - finished
                  description: General status info events.
              required:
                - status
          required:
            - paylaod

    TrashTypeChangedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                value:
                  allOf:
                    - $ref: '#/components/schemas/Uuid4'
                    - description: The new trash type.
          required:
            - playload

    DisposalPlantChangedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                value:
                  allOf:
                    - $ref: '#/components/schemas/Uuid4'
                    - description: The new disposal plant.
          required:
            - playload

    ServiceChangedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                value:
                  allOf:
                    - $ref: '#/components/schemas/Uuid4'
                    - description: The new service.
          required:
            - playload

    ContainerTypeChangedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                value:
                  allOf:
                    - $ref: '#/components/schemas/Uuid4'
                    - description: The new container type.
          required:
            - playload

    ContainerAmountChangedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                value:
                  type: integer
                  description: The new container amount.
          required:
            - playload

    PositionUpdatedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - description: |
            This event is just to announce the current position and is fired
            regularly in a given interval.

    CustomerSignedJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              type: object
              properties:
                name:
                  type: string
                  example: John Doe
                  description: Name os signer
                image:
                  type: string
                  example: https://xxxxxx-media-server.de/image-xyz.jpg
                  description: Download URL of customer signature image.

    MessageJobEvent:
      allOf:
        - $ref: '#/components/schemas/JobEvent'
        - type: object
          properties:
            payload:
              $ref: '#/components/schemas/JobMessage'
          required:
            - payload


when i delete the "mapping" here:
mapping:
on_the_way: '#/components/schemas/DrivingJobEvent'
arrived: '#/components/schemas/DrivingJobEvent'
set_up: '#/components/schemas/SetContainerJobEvent'
set_down: '#/components/schemas/SetContainerJobEvent'
captured_weight: '#/components/schemas/CapturedWeightJobEvent'
cashed_up: '#/components/schemas/CashedUpJobEvent'
final_weighed: '#/components/schemas/FinalWeighedJobEvent'
initial_weighed: '#/components/schemas/InitialWeighedJobEvent'
delay: '#/components/schemas/DelayJobEvent'
status_updated: '#/components/schemas/StatusUpdatedJobEvent'
customer_signed: '#/components/schemas/CustomerSignedJobEvent'
position_updated: '#/components/schemas/PositionUpdatedJobEvent'
message: '#/components/schemas/MessageJobEvent'
trash_type_changed: '#/components/schemas/TrashTypeChangedJobEvent'
container_type_changed: '#/components/schemas/ContainerTypeChangedJobEvent'
container_amount_changed: '#/components/schemas/ContainerAmountChangedJobEvent'
disposal_plant_changed: '#/components/schemas/DisposalPlantChangedJobEvent'

generation works fine. But thats not the goal of the definition.

Is it a bug or have i done something wrong in the definition?

Regards
Thomas

Need options with "name" and replacing node name

Using this part

        "review" : {
          "type" : "array",
          "xml" : {
            "name" : "reviews",
            "wrapped" : true
          },
          "items" : {
            "$ref" : "#/definitions/BlaBla"
          }
        }

will generate field with name review and attribute

[Newtonsoft.Json.JsonProperty("**review**" ,...)]
public System.Collections.Generic.IEnumerable review{ get; set; }

It will be nice that if another options will exists like

  • using name value for attribute name
  • using name value for property name
  • using name value for attribute and property name
[Newtonsoft.Json.JsonProperty("**reviews**" ,...)]
public System.Collections.Generic.IEnumerable review{ get; set; }

Case Sensitive file system prevents detection of configured specification endpoints

I have two versions of the same repository on my PC - one is set up within a folder that has case sensitivity activated and was created by git in WSL2.
The other was cloned within a folder with deactivated case sensitivity (the windows default) using git for windows in a powershell.

Within the windows variety, I can right click on a previously configured specification endpoint and I get the context-menu entry Update Unchase OpenApi….
In the other one this menu point never appears and I can only create new endpoints. Double clicking Connected Services shows a green check mark and the word Configured, for the case insensitive version, but nothing if the file system is case sensitive.

As .Net 5 moves to be compatible with other operating systems and development for .Net is not windows exclusive any more, it would be cool if this tool could handle file names in a case sensitive way.

Compatibility

When using Autowrapper (https://github.com/proudmonkey/AutoWrapper) on service, the json comes back with additional fields that do not show in swagger json that wraps the response object.

So when the connected service builds, it builds for the response object but not the wrapper put on by Autowrapper. Has anyone experienced this or found a quick workaround? I am trying not to modify the generated class.

thanks,
Greg

Updating connected service on build

Is it possible to update the connected service on build (and optionally force through any notification messages)? My use case is a client library which generates from an endpoint on build.

Virus in TrendMicro detection

I installed the extension and when I publish my code, TrendMicro is saying the backdoor trojans are embedded in exe file and a script runs to try to turn off my system restore.

image
image

Can't generate Client or Controller

I am getting this error whenever I am trying to generate a Client
Warning:Error: Unable to cast object of type 'NSwag.OpenApiResponse' to type 'NJsonSchema.JsonSchema'..
this is the full text

Adding service instance for "https://name-of-domain/swagger.json"...
Adding Nuget Packages for OpenAPI (Swagger) CSharp Client...
Nuget Package "Newtonsoft.Json" for OpenAPI (Swagger) already installed.
Nuget Package "System.Net.Http" for OpenAPI (Swagger) already installed.
Nuget Package "System.ComponentModel.Annotations" for OpenAPI (Swagger) already installed.
Nuget Packages for OpenAPI (Swagger) CSharp Client were installed.
Generating NSwag-file for OpenAPI (Swagger)...
NSwag-file "OpenAPI.nswag" for OpenAPI (Swagger) was generated.
Generating Client Proxy for OpenAPI (Swagger) Client...
Warning:Error: Unable to cast object of type 'NSwag.OpenApiResponse' to type 'NJsonSchema.JsonSchema'..
Client Proxy for OpenAPI (Swagger) Client was generated.
Adding service instance complete!

I'm getting the same error when using NSwagStudio

LE: My project is using swagger: "2.0",

Could not find file specified

Fresh install into a fairly well seasoned copy of Community Edition 2017, opened a new project, "add..", "Connected service", left everything as default, added service name and URL, hit next, and got standard .net error for newtonsoft being missing.


Connected services

Cannot Access
"HTTPS://{{MY URL - REMOVED}}". Could not load file or assembly 'NewtonSoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4ge6b2a6aeed' or one of its dependencies. The system cannot find the file specified

BUG : Unable to inject baseUrl in constructor

Describe the bug

I am unable to inject baseUrl in constructor while generating client from application in .net framework 4.6.1 using Swashbuckle v.5.6.0.

I have selected the all the option related to baseUrl but it can not work

BaseUrl

but It generated the following code

CrmCode

Assemblies affected

Which assemblies and versions are known to be affected?

Steps to reproduce

The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error
    ...

Expected result

A clear and concise description of what you expected to happen.
What would happen if there wasn't a bug.

Actual result

What is actually happening.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional detail

Add any other context about the problem here.
Optional, details of the root cause if known.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.