Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
90 stars 38 forks source link

fix: getting first available content type for parametersV2 method #133

Closed elenaferr0 closed 9 months ago

elenaferr0 commented 9 months ago

I added another check in the parametersV2 method so that if there is a content type which is not multipart or form url encoded it is added to the request. For example, I would expect the following swagger:

{
  "swagger": "2.0",
  "info": {
    "description": "",
    "version": "",
    "title": "Test swagger"
  },
  "host": "localhost:8081",
  "basePath": "/",
  "tags": [
    {
      "name": "Tests",
      "description": "Test Controller"
    }
  ],
  "paths": {
    "/test": {
      "patch": {
        "tags": [
          "Tests"
        ],
        "description": "Description",
        "operationId": "operationId",
        "consumes": [
          "application/json-patch+json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  },
  "definitions": {}
}

to generate the following dart code:

@RestApi()
abstract class TestsClient {
  factory TestsClient(Dio dio, {String? baseUrl}) = _TestsClient;

  /// Description
  @Headers(<String, String>{'Content-Type': 'application/json-patch+json'})
  @PATCH('/test')
  Future<void> operationId();
}

But instead generates this (the @Headers annotation is missing):

@RestApi()
abstract class TestsClient {
  factory TestsClient(Dio dio, {String? baseUrl}) = _TestsClient;

  /// Description
  @PATCH('/test')
  Future<void> operationId();
}

I also fixed the parser request_tests for v2 (callingactualRestClient.last in that scenario always returns the same element, therefore not all the list element were properly compared). The basic paths check 3.0 test has the same issue, if you switch from

expect(actualRestClients.last, expectedRestClients.last);

to

expect(actualRestClients[i], expectedRestClients[i]);

the test fails, it seems that the returnType is different but I didn't manage to understand why.