Forum Discussion

Imre's avatar
Imre
New Member
3 months ago

What is the representation of KeyParValue<string, string> in Open Api schema?

Hi,

I would like to use NSwag Api client generator to generate C# api client from swagger.json file, but I have problem with the KeyParValue<string, string> type mapping. I would like to provide a custom mapping, but I don't know the correct open api schema definition. Could you help me, please?

In the attached screenshot there is the mapping of the IDictionary<string,string> type.

1 Reply

  • Harow435's avatar
    Harow435
    Occasional Visitor

    Hey Dear, you're encountering an issue with the mapping of the IDictionary<string, string> type when using the NSwag API client generator with a Swagger/OpenAPI JSON file. To provide a custom mapping, you need to modify the OpenAPI schema definition.

    Here's a general example of how you might define a custom mapping for IDictionary<string, string> in your Swagger/OpenAPI JSON file:

    "definitions": { "KeyValuePairs": { "type": "object", "additionalProperties": { "type": "string" } } },

    Then, in your endpoint definition or parameter definition, you can refer to this KeyValuePairs type:

    "paths": { "/your/api/endpoint": { "post": { "parameters": [ { "name": "yourParameterName", "in": "body", "schema": { "$ref": "#/definitions/KeyValuePairs" } } ], "responses": { // Your responses here } } } }

    In this example, we define a generic KeyValuePairs type with string values. You can then reference this type in your endpoint parameters or request bodies. This allows you to use the custom mapping for IDictionary<string, string>.

    Make sure to adapt these snippets based on your specific Swagger/OpenAPI JSON structure and the requirements of your API. If you have a specific part of your Swagger JSON that you're struggling with, feel free to share it, and I can provide more tailored assistance.