Forum Discussion

more-urgen-jest's avatar
more-urgen-jest
Occasional Contributor
3 years ago
Solved

c# openapi parameter schema object

is it possible to define a parameter using a ref to a schema? e.g.:

 

 

    "/path/to/here": {
      "get": {
        "responses": {
          "200": {
            "$ref": "#/components/responses/Response"
          }
        },
        "operationId": "get-to-here",
        "description": "Get to here",
        "parameters": [
          {
            "schema": {
              "$ref": "#/components/schemas/Request"
            },
            "in": "query",
            "name": "Request",
            "description": "Request for getting here",
            "required": true
          }
        ],
        "tags": [
          "Here"
        ]
      }
    }

 

 

 

this generates a C# abstract controller as expected via the openapi generator:

 

 

        public abstract Task<IActionResult> GetToHere([FromQuery (Name = "Request")][Required()]Request request);

 

 

 

but the NSwag generator, via a service reference, generates:

 

 

        public async Task<Response> GetToHereAsync(Request request, CancellationToken cancellationToken)
        {
            if (request == null)
                throw new System.ArgumentNullException("request");
    
            var urlBuilder_ = new System.Text.StringBuilder();
            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/path/to/here?");
            urlBuilder_.Append(System.Uri.EscapeDataString("Request") + "=").Append(System.Uri.EscapeDataString(ConvertToString(request, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            urlBuilder_.Length--;

 

 

 

rather than adding the primitives in the request object as separate query parameters.

the request is defined as:

 

 

      "Request": {
        "title": "Request",
        "x-stoplight": {
          "id": "blah"
        },
        "type": "object",
        "x-examples": {
          "example": {
            "$ref": "#/components/examples/RequestExample"
          },
          "example Names": {
            "$ref": "#/components/examples/RentalSuburbRangeRequestNames"
          }
        },
        "properties": {
          "Id": {
            "type": "string"
          },
          "Name": {
            "type": "string"
          },
          "OtherName": {
            "type": "string"
          }
        }
      }

 

 

 

any hints much appreciated
  • You can get the status of individual assertions from the Assertion Test Step with the following script in the Groovy Test Step:

    def testStep = testRunner.testCase.getTestStepByName("Assertion") //change to your name
    def list = testStep.getAssertionEntryList()
     
    for( assertion in list)
    {
      //log.info(assertion.getProperties())
      log.info("Assertion: " + assertion)
      log.info("Assertion: " + assertion.status)
    }