Test

<back to all web services

DeclarativeCollectiveValidationTest

<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


// @DataContract
class EmptyResponse implements JsonSerializable
{
    public function __construct(
        // @DataMember(Order=1)
        /** @var ResponseStatus|null */
        public ?ResponseStatus $responseStatus=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
        return empty($o) ? new class(){} : $o;
    }
}

class DeclarativeChildValidation implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $name=null,
        // @Validate(Validator="MaximumLength(20)")
        /** @var string|null */
        public ?string $value=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['name'])) $this->name = $o['name'];
        if (isset($o['value'])) $this->value = $o['value'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->name)) $o['name'] = $this->name;
        if (isset($this->value)) $o['value'] = $this->value;
        return empty($o) ? new class(){} : $o;
    }
}

class FluentChildValidation implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $name=null,
        /** @var string|null */
        public ?string $value=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['name'])) $this->name = $o['name'];
        if (isset($o['value'])) $this->value = $o['value'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->name)) $o['name'] = $this->name;
        if (isset($this->value)) $o['value'] = $this->value;
        return empty($o) ? new class(){} : $o;
    }
}

class DeclarativeCollectiveValidationTest implements JsonSerializable
{
    public function __construct(
        // @Validate(Validator="NotEmpty")
        // @Validate(Validator="MaximumLength(20)")
        /** @var string */
        public string $site='',

        /** @var array<DeclarativeChildValidation>|null */
        public ?array $declarativeValidations=null,
        /** @var array<FluentChildValidation>|null */
        public ?array $fluentValidations=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['site'])) $this->site = $o['site'];
        if (isset($o['declarativeValidations'])) $this->declarativeValidations = JsonConverters::fromArray('DeclarativeChildValidation', $o['declarativeValidations']);
        if (isset($o['fluentValidations'])) $this->fluentValidations = JsonConverters::fromArray('FluentChildValidation', $o['fluentValidations']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->site)) $o['site'] = $this->site;
        if (isset($this->declarativeValidations)) $o['declarativeValidations'] = JsonConverters::toArray('DeclarativeChildValidation', $this->declarativeValidations);
        if (isset($this->fluentValidations)) $o['fluentValidations'] = JsonConverters::toArray('FluentChildValidation', $this->fluentValidations);
        return empty($o) ? new class(){} : $o;
    }
}

PHP DeclarativeCollectiveValidationTest DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /json/reply/DeclarativeCollectiveValidationTest HTTP/1.1 
Host: test.servicestack.net 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"site":"String","declarativeValidations":[{"name":"String","value":"String"}],"fluentValidations":[{"name":"String","value":"String"}]}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}