dimanche 2 août 2020

How to fetch a schema for a API using the swagger.json URL and mentioned the $ref?

Currenlty I am using RestSharp to perform API testing.. And I wanted to validate API schema. However I wanted check if it was possible since we use swagger to get the schema for the API I am testing using the swagger.json url "$ref": "#/components/schemas/APICall"

Here I am written a simple Restsharp code to hit the swagger.json URL. I want to extract the schema from here..How can I do this

      [Test]
        public void GetSchema()
        {
            var client = new RestClient("http://exampleAPI/swagger/v1/swagger.json");
            var request = new RestRequest(Method.GET);
            var repsonse = client.Execute(request);
            string json = repsonse.Content;
            System.Console.WriteLine(json);
        }


//Here is the part of the Json I get back I am trying to validate the GetAllTags Api schema.. but I am not able to find the response model...
{
  "openapi": "3.0.1",
  "info": {
    "title": "Example Api"
  },
 "path": {
"/api/Tag/GetAllTags": {
      "get": {
        "tags": [
          "Tag"
        ],
        "summary": "GetAllTags method is used to get all tags,
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Tag"
                  }
                }
              }

Aucun commentaire:

Enregistrer un commentaire