RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.7k stars 1.24k forks source link

Suggestions on how to deal with variables in the path of a REST api? #4020

Open sgutkinMadrid opened 2 years ago

sgutkinMadrid commented 2 years ago

Any suggestions on how to deal with variables in the path of a REST api? Obviously the curly braces in the dotnet code doesn't compile... At this point I am looking for ideas.

Currently the dotnet code generated by Nswag looks like this:

System.Threading.Tasks.Task Get__rest_api_v1_3campaigns{campaignName}_previewAsync(string campaignName, string previewType, string listType, string riid);

JSON sample from https://docs.oracle.com/en/cloud/saas/marketing/responsys-rest-api/swagger.json

/rest/api/v1.3/campaigns/{campaignName}/preview":{ "get":{ "summary":"Preview a Campaign", "description":"Use this endpoint to preview a campaign. The endpoint outputs the campaign in HTML and text.", "operationId":"get /rest/api/v1.3/campaigns/{campaignName}/preview", "responses":{ "default":{ "description":"", "schema":{ "$ref":"#/definitions/previewCampaign-response" } } }, "parameters":[ { "name":"campaignName", "in":"path", "required":true, "type":"string", "description":"Campaign name for preview" }, { "name":"previewType", "in":"query", "type":"string", "description":"This allows you to output only one type of preview. Possible values are html or text. By default, both are output." }, { "name":"listType", "in":"query", "type":"string", "description":"The type of source list you wish to preview. Possible values are ProofList or ProfileList. Default value is ProofList." }, { "name":"riid", "in":"query", "type":"string", "description":"This allows you to preview based on a specific RIID." } ], "x-relation":[ "instances" ], "produces":[ "application/json" ], "tags":[ "Campaigns" ], "x-internal-id":"rest-api-v1.3-campaigns-{campaignName}-preview-get", "x-filename-id":"rest-api-v1.3-campaigns-campaignname-preview-get" } },

dsteinweg commented 2 years ago

I have the same problem. The offending OpenAPI spec in my case is here: https://developers.procore.com/api/v1/resource_groups/full_oas

Which generates code like the following, which doesn't compile (see second parameter, which starts with "custom_field"):

public File2(System.DateTimeOffset? @checked_out_until, string @custom_field_%{custom_field_definition_id}, string? @data, (...)