Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths with multiple results ignored #11

Open
miroslav-mastny-regosys opened this issue Sep 5, 2023 · 1 comment
Open

Paths with multiple results ignored #11

miroslav-mastny-regosys opened this issue Sep 5, 2023 · 1 comment

Comments

@miroslav-mastny-regosys
Copy link

miroslav-mastny-regosys commented Sep 5, 2023

Endpoints with multiple results are ignored and appropriate code is not generated. No (reason/warning) message is showed, it's very confusing.

Nice solution is used by nswag. For response 200 generate correct result (function result type) and typed exception for others (any exception with json object is welcomed).

------------ sample: json multiple responses ----------------

    "responses": {
      "200": {
        "description": "OK result - array of type 'Source' instances",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Sources"
            }
          }
        }
      },
      "default": {
        "description": "Processing error (unexpected)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Errors"
            }
          }
        }
      }
    }

------------- sample: nswag implementation -----------------

  ProcessResponse(client_, response_);

  var status_ = (int)response_.StatusCode;
  if (status_ == 200)
  {
      var objectResponse_ = await ReadObjectResponseAsync<System.Collections.Generic.ICollection<Source>>(response_, headers_, cancellationToken).ConfigureAwait(false);
      if (objectResponse_.Object == null)
      {
          throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
      }
      return objectResponse_.Object;
  }
  else
  {
      var objectResponse_ = await ReadObjectResponseAsync<System.Collections.Generic.ICollection<Error>>(response_, headers_, cancellationToken).ConfigureAwait(false);
      if (objectResponse_.Object == null)
      {
          throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
      }
      throw new ApiException<System.Collections.Generic.ICollection<Error>>("Processing error (unexpected)", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
  }

---------- the end -----------------------

@wlandgraf
Copy link
Contributor

Good suggestion. If you already have a proposal about how to implement this, please send a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants