Giter VIP home page Giter VIP logo

Comments (4)

byjg avatar byjg commented on June 28, 2024

Could you be more specific by providing some example?

from php-swagger-test.

Onekone avatar Onekone commented on June 28, 2024

Now thinking about it, title is a little bit misleading, but anyway

Let's assume we have this as a swagger-json file (actual host is unavailable to the global internet, so I replaced it).

  "swagger": "2.0",
  "schemes": [
    "http"
  ],
  "info": {
    "version": "1.0.0",
    "title": "Library"
  },
  "host": "books.example.com",
  "tags": [
    {
      "name": "Books",
      "description": "Receiving information about books"
    }
  ],
  "paths": {
    "bookinfo": {
      "get": {
        "tags": [
          "Library"
        ],
        "summary": "Returns information of one book",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "book",
            "in": "query",
            "description": "Book ID",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "type": "object",
              "properties": {
                "success": {
                  "type": "boolean"
                },
                "data": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/Book"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Book": {
      "type": "object",
      "properties": {
        "tag_id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "where_is": {
          "type": "string"
        },
        "taking_date": {
          "type": "string"
        },
        "image_url": {
          "type": "string"
        }
      }
    }
  }
}

However, properties of Book model are actually nullable (as far as actual API and DB connected to it are concerned, it's valid that it can be either a string or null), but if you execute such test

public function testGetBook()
    {
        $this->request
            ->withMethod('GET')
            ->withPath('/bookinfo');
        try {
            $this->assertRequest($this->request);
            $response = $this->request->send();
        } catch (\Exception $e) {
            $this->fail('Failed - ' . $e->getMessage());
        }
    }

And if it returns null as one of the properties of an object in response array, it causes test to throw out an exception.

From looking through source code of your module, method assertRequest uses instance of SwaggerSchema it creates itself (which has such flag disabled by default), even if request was specified to use another schema and/or with AllowNullValues flag enabled, and there is no way to enable it within SwaggerTestInstance.

Overriding $this->swaggerSchema causes other issues (can replicate them if needed), so that is not an option for me

from php-swagger-test.

byjg avatar byjg commented on June 28, 2024

Hello, for some unexplained reason I missed your answer. I am sorry for that. So, for this issue I am adding the possibility of you override the SwaggerSchema.

Your code now could be:

<?php
public function testGetBook()
{
    $schema = new SwaggerSchema(.......)

    $this->request
        ->withSwaggerSchema($schema)
        ->withMethod('GET')
        ->withPath('/bookinfo');
    try {
        $response = $this->assertRequest($this->request);
    } catch (\Exception $e) {
        $this->fail('Failed - ' . $e->getMessage());
    }
}

You do not need to call send() because the assertRequest() already do this.

from php-swagger-test.

byjg avatar byjg commented on June 28, 2024

Merged to branch oas30

from php-swagger-test.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.