Giter VIP home page Giter VIP logo

laminas-json-server's People

Contributors

arueckauer avatar devkpv avatar geerteltink avatar ghostwriter avatar internalsystemerror avatar koopzington avatar malinink avatar michalbundyra avatar ocramius avatar powerkiki avatar renovate[bot] avatar samsonasik avatar webit4me avatar weierophinney avatar xerkus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laminas-json-server's Issues

PHP 8.0 support

Feature Request

Q A
New Feature yes

Summary

To be prepared for the december release of PHP 8.0, this repository has some additional TODOs to be tested against the new major version.

In order to make this repository compatible, one has to follow these steps:

  • Modify composer.json to provide support for PHP 8.0 by adding the constraint ~8.0.0
  • Modify composer.json to drop support for PHP less than 7.3
  • Modify composer.json to implement phpunit 9.3 which supports PHP 7.3+
  • Modify .travis.yml to ignore platform requirements when installing composer dependencies (simply add --ignore-platform-reqs to COMPOSER_ARGS env variable)
  • Modify .travis.yml to add PHP 8.0 to the matrix (NOTE: Do not allow failures as PHP 8.0 has a feature freeze since 2020-08-04!)
  • Modify source code in case there are incompatibilities with PHP 8.0

Wrong return values in Service Mapping Description (SMD)

Bug Report

The Service Mapping Description (SMD) detects wrong return values under certain (unclear) circumstances.

Q A
PHP 7.4
laminas/laminas-json-server 3.3

Summary

The return value types are kind of multiplied (see below).

I have the following Dummy class, which describes return values via phpdoc as follows.

<?php

declare(strict_types=1);

/**
 * Dummy
 */
class Dummy
{
    /**
     * Method a
     *
     * @param int $x
     * @param float $y
     * @return array
     */
    public function a(int $x, float $y): array
    {
        return ['a'];
    }

    /**
     * Method b
     *
     * @param int|float $x
     * @param string $y
     * @param int|float $z
     * @return object
     */
    public function b($x, $y, $z = 0.0): object
    {
        return (object)['name' => 'b'];
    }

    /**
     * Method c
     *
     * @param int $x
     * @param int $y
     * @param int $z
     * @return array
     */
    public function c(int $x, int $y = 0, int $z = 0): array
    {
        return ['name' => 'c'];
    }

    /**
     * Method d
     *
     * @param int|float $x
     * @param float $y
     * @return array
     */
    public function d(int $x, float $y): array
    {
        return ['d'];
    }
}

The auto-generated Service Mapping Description (SMD) looks like follows.

{
    "transport": "POST",
    "envelope": "JSON-RPC-2.0",
    "contentType": "application\/json",
    "SMDVersion": "2.0",
    "services": {
        "dummy.a": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.a",
            "parameters": [
                {
                    "type": "integer",
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "float",
                    "name": "y",
                    "optional": false
                }
            ],
            "returns": "array"
        },
        "dummy.b": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.b",
            "parameters": [
                {
                    "type": [
                        "integer",
                        "float"
                    ],
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "string",
                    "name": "y",
                    "optional": false
                },
                {
                    "type": [
                        "integer",
                        "float"
                    ],
                    "name": "z",
                    "optional": true,
                    "default": 0
                }
            ],
            "returns": [
                "object",
                "object",
                "object",
                "object",
                "object",
                "object"
            ]
        },
        "dummy.c": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.c",
            "parameters": [
                {
                    "type": "integer",
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "integer",
                    "name": "y",
                    "optional": true,
                    "default": 0
                },
                {
                    "type": "integer",
                    "name": "z",
                    "optional": true,
                    "default": 0
                }
            ],
            "returns": [
                "array",
                "array",
                "array"
            ]
        },
        "dummy.d": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.d",
            "parameters": [
                {
                    "type": [
                        "integer",
                        "float"
                    ],
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "float",
                    "name": "y",
                    "optional": false
                }
            ],
            "returns": [
                "array",
                "array"
            ]
        }
    },
    "methods": {
        "dummy.a": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.a",
            "parameters": [
                {
                    "type": "integer",
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "float",
                    "name": "y",
                    "optional": false
                }
            ],
            "returns": "array"
        },
        "dummy.b": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.b",
            "parameters": [
                {
                    "type": [
                        "integer",
                        "float"
                    ],
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "string",
                    "name": "y",
                    "optional": false
                },
                {
                    "type": [
                        "integer",
                        "float"
                    ],
                    "name": "z",
                    "optional": true,
                    "default": 0
                }
            ],
            "returns": [
                "object",
                "object",
                "object",
                "object",
                "object",
                "object"
            ]
        },
        "dummy.c": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.c",
            "parameters": [
                {
                    "type": "integer",
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "integer",
                    "name": "y",
                    "optional": true,
                    "default": 0
                },
                {
                    "type": "integer",
                    "name": "z",
                    "optional": true,
                    "default": 0
                }
            ],
            "returns": [
                "array",
                "array",
                "array"
            ]
        },
        "dummy.d": {
            "envelope": "JSON-RPC-2.0",
            "transport": "POST",
            "name": "dummy.d",
            "parameters": [
                {
                    "type": [
                        "integer",
                        "float"
                    ],
                    "name": "x",
                    "optional": false
                },
                {
                    "type": "float",
                    "name": "y",
                    "optional": false
                }
            ],
            "returns": [
                "array",
                "array"
            ]
        }
    }
}

Current behavior

The return values seems to be multiplied. It looks like there is a relation to the params.

Method Return Conclusion
dummy.a array Ok
dummy.b array of 6 objects strange, why 6 objects?
dummy.c array of 3 arrays strange, why 3 arrays?
dummy.d array of 2 arrays strange, why 2 arrays?

How to reproduce

  • follow the laminas-json-server as described in the documentation
  • create a service class like the one above
  • consume the service map description via the endpoint "GET /json-rpc"

Expected behavior

The return values should not be multiplied.

[Json/Server] Return the invalid parameters list

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7544
User: @dreadnought78
Created On: 2015-05-23T22:04:16Z
Updated At: 2015-11-06T23:57:01Z
Body
If the user forgot or send some required parameter with a wrong name the server returns the error ERROR_INVALID_PARAMS.

This request added a invalid parameters list in the json response.

Result before

{
    "error":{
        "code":-32602,
        "message":"Invalid params",
        "data":null
    },
    "id":"8",
    "jsonrpc":"2.0"
}

Result after

{
    "error":{
        "code":-32602,
        "message":"Invalid param(s): [estimatedMonths, location, specieId, coatTypeId]",
        "data":null
    },
    "id":"8",
    "jsonrpc":"2.0"
}

*Please do not consider this pull request if this implementation has not been made before for security reasons.



Originally posted by @GeeH at zendframework/zend-json#25

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Detected dependencies

composer
composer.json
  • php ^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0
  • laminas/laminas-http ^2.15.1
  • laminas/laminas-json ^3.3.0
  • laminas/laminas-server ^2.11.0
  • laminas/laminas-coding-standard ^2.4.0
  • phpunit/phpunit ^9.5.26
  • psalm/plugin-phpunit ^0.18.0
  • vimeo/psalm ^5.0.0
github-actions
.github/workflows/continuous-integration.yml
.github/workflows/docs-build.yml
.github/workflows/release-on-milestone-closed.yml

  • Check this box to trigger a request for Renovate to run again on this repository

Component maintenance: PHP update

Component maintenance

Q A
Documentation no
Bugfix no
BC Break no
New Feature no
RFC no
QA yes

In preparation of bringing this component in compliance with the JSON-RPC 2.0 specs, I would like to update this component to a currently supported PHP version including language features (strict types, type declarations).

Planned changes/updates

@Xerkus suggested the following schedule. If possible, each point will be provided in a separate PR

to achieve green CI at each step and make reviews easier.

  • php 7.2
  • phpunit 8 and test suite update
  • strict types, typehints, strict types error fixes
  • coding standard
  • phpstan and fixes

This issue serves as a task list and an overview of the progress.

No changes in functionality

This "project" will not introduce features, bugfixes or BC breaks. Necessary functionality changes will be handled separately afterwards.

EDIT:

Additional changes

List of additional changes required. Initially these points resulted from the code review in #3 and will be added on if required.

PR against dev-4.0

  • Drop fluent setters
  • Avoid yoda conditions
  • Drop Json::encode & Json::decode in favor of native json_encode and json_decode (add ext-json to composer.json)
  • Drop PHPDocs which do not add valuable information (such as duplicating type declarations)
  • ExceptionInterface should extend Throwable
  • Apply laminas/laminas-coding-standard 2.0
  • Handle array arguments more generic, probably iterable (e.g. Smd::addServices(array $services))
  • Smd::addService(Smd\Service $service) drop array support and argument type check [BC]
  • JSON-RPC SMD: Use argument type declarations as param types (deprecating type hints in PHPDocs)
  • Server::getSmd() Return should be changed to ?string as you get a result or nothing.
  • Cache::saveSmd() Return should be void. Regardless of whether caching attempt was successful just carry on.
  • Cache::deleteSmd() Operation result is irrelevant for the consumer. Return nothing. :void
  • Client::__construct() QA: rename $server to $serverAddress to better reflect its meaning
  • Server::handle() Not sure about the reason for false instead of null here ($request parameter). This should be changed at some point i think
  • Server::__call Design: return null; should be used when method is not : void. A change to be done when static analysis tool introduced.
  • Server::handleRequest() QA: if (! $request->isMethodError() && '' === $request->getMethod()) { Method error check block from below can be merged with this block:
    if ($request->isMethodError() || empty($request->getMethod())) {
    Alternatively blocks can be swapped and condition simplified to check only for empty method.
  • Add strict typing to laminas-server, update used version in here as well as update usages (method signatures).

PR against master

  • Bugfix Smd::getDescription() returns $description instead of self

Psalm integration

Feature Request

Q A
QA yes

Summary

As decided during the Technical-Steering-Committee Meeting on August 3rd, 2020, Laminas wants to implement vimeo/psalm in all packages.

Implementing psalm is quite easy.

Required

  • Create a .psalm.xml.dist in the project root
  • Copy and paste the contents from this psalm.xml.dist
  • Run $ composer require vimeo/psalm
  • Run $ vendor/bin/psalm --set-baseline=psalm-baseline.xml
  • Add a composer script static-analysis with the command psalm --shepherd --stats
  • Add a new line to script: in .travis.yml: - if [[ $TEST_COVERAGE == 'true' ]]; then composer static-analysis ; fi
  • Remove phpstan from the project (phpstan.neon.dist, .travis.yml entry, composer.json require-dev and scripts)
Optional
  • Fix as many psalm errors as possible.

Question: Why are assertions of a method in `ClientTest` disabled?

What is the reason, that the assertions of ClientTest::testLastRequestAndResponseAreSetAfterRpcMethodCall() are commented out?

Could not find any hints in Git history (change was made prior to what is available in Git history).

Tests are green locally (PHP 7.2, Windows 10), if I re-active them.

//$this->assertInstanceOf('Zend\\Json\\Server\\Request', $this->jsonClient->getLastRequest());
//$this->assertInstanceOf('Zend\\Json\\Server\\Response', $this->jsonClient->getLastResponse());

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.