Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119653 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9768 invoked from network); 2 Mar 2023 17:11:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Mar 2023 17:11:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6CA4418033A for ; Thu, 2 Mar 2023 09:11:01 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 2 Mar 2023 09:11:00 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 808C35C0038 for ; Thu, 2 Mar 2023 12:11:00 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Thu, 02 Mar 2023 12:11:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1677777060; x=1677863460; bh=Jbgq/7MypL G2q/eARQKQajrk8EorpF42KhzAIJjv7dg=; b=jtuT1QtDbNsv4Y/CFPq7ver8YL k2IWoFbqCz2gCt9GvqbIqZ/H+0fTQS2AVgol0lx9Eo4aE2/VwLPu0i5CRguTJgLm EUQMpmYNGfPDT/qnae+v2pt1LJDTxcF8N236NXY2RB44quhevItudPWxidWT76yk wc+lZ5/MjWABZtMilRQL1qMmgfPFPUPVppVXvnVpV9rOz3SvrZyqElzvIrZziqng 6T2dEGa8BqarU3wLgdeff4wYk2rpxHF/exgRPxHVyWKleJP6kJEFc2S1HIx7KunL vjVfSBCyMC2JfNEWoAa0OeVZnMrLaoo4IsHoaXa3sgv9NNMLfRpcBd4j9p4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1677777060; x= 1677863460; bh=Jbgq/7MypLG2q/eARQKQajrk8EorpF42KhzAIJjv7dg=; b=K Dd/dcPPey3WYOI+tPzlIHUl9ExPmzcawFHBP9rgzPgk368EUwasL6J1hWUM2UQj9 2yleC67UMcXRrOdlaDJvunj5PAFWJ/sMipLBtt6p1VvuSpCgEGVgyz0LJsfuOjz0 PhfwvO7v0RurGN8pvQpoGr1a24Udp7kjJC2jv9qjgcXDD4G0o40rVe7Tn700ML2a 9o6U3beg9O7wsdeupgPOf9hBk+O2CpoCiKROn3FbGtscYgMrOS0jAzj+ANmBladX W7B+LBAdnjhim73oFtdenNg5S3UwO5eWKnRdZeotfKBzUREhrKAuhai/4du/X39C U98tg8C1QaA/xUoaMY2Rg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeljedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhephfektdffgffhkeeiudehvdehfefgfeehuefgvdel teetkeetgfetjeeiledtleeknecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehg rghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3FD441700089; Thu, 2 Mar 2023 12:11:00 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-183-gbf7d00f500-fm-20230220.001-gbf7d00f5 Mime-Version: 1.0 Message-ID: <65dbe7f1-a6d0-4b06-833c-f1c579a2ca91@app.fastmail.com> In-Reply-To: References: Date: Thu, 02 Mar 2023 11:10:40 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC Idea - json_validate() validate schema From: larry@garfieldtech.com ("Larry Garfield") On Thu, Mar 2, 2023, at 6:34 AM, Jakub Zelenka wrote: > On Thu, Mar 2, 2023 at 12:00=E2=80=AFPM Rowan Tommins > wrote: > >> On Wed, 1 Mar 2023 at 11:44, juan carlos morales < >> dev.juan.morales@gmail.com> >> wrote: >> >> > I am thinking about enhancing this function to also be able to >> > validate against a JSON SCHEMA, giving us something like this: >> > >> > json_validate(string $json, int $depth =3D 512, int $flags =3D 0, s= tring >> > $json_schema =3D null): bool >> > >> >> >> Functionally, I think this is sounds great. My only concern is that J= SON >> Schema is a bit of a moving target. Unlike XSD, which has only ever h= ad two >> revisions, 10 years apart (1.0 from 2001, and 1.1 from 2012), JSON Sc= hema >> is in active development, with "Draft-07", "2019-09", and "2020-12" a= ll >> seeing deployment as stable releases, and work in progress on a new >> version: https://github.com/json-schema-org/json-schema-spec/mileston= e/7 >> >> That raises two questions: >> >> * Which existing version(s) of the specification will be implemented?= For >> instance, if I have a schema written for 2019-09 rather than 2020-12,= will >> I be able to use this validator? >> > > The plan is to support draft-04 and all later ones. So yeah you should= be > able to support both once they are implemented. I'm starting with draf= t-04 > and will add others in the order they were created. > > >> * How will new versions of the specification be added to the parser? = If PHP >> 8.4 is release in November 2024, and JSON Schema 2025-01 is published= two >> months later, will I need to wait for PHP 8.5 to use the new specific= ation? >> >> > It would be a feature so the next minor. > > >> I guess the combination of those leads to a third question: will supp= ort >> for some versions be *removed* in later PHP versions, so that each PHP >> version will have a minimum and maximum schema version it supports? >> >> > It's possible that we might decide to stop supporting some drafts if t= he > maintenance burden is too big and usage small but I wouldn't see that = as > something that happens often. But essentially you are right that there= will > be minimum (draft-04 initially) and maximum (latest implemented draft). > > >> That's the big disadvantage of anything shipped in core, rather than = in an >> extension or library - there is no way to make even minor changes out= side >> of PHP's release cycle. >> >> > The changes are going to be first added to PECL jsond which will suppo= rt > PHP 7.2+ for some time. I will most likely keep it updated for later d= rafts > additions so it could be still used for older versions of PHP. > > >> I wonder if there's some way this can be made pluggable - ship the co= re >> mechanisms needed by the validator in core, but make them accessible = to >> libraries to implement specific specifications in an efficient way. T= his is >> the approach taken by the MongoDB PHP driver - there's a stable exten= sion >> providing efficient low-level routines, then a decoupled PHP library = which >> can be installed at the project level, and follow a much more agile r= elease >> process. I'm not sure what it would look like in this case, but may be >> worth considering. >> >> > This might be quite technically challenging and also significantly > impacting performance of parsing so I wouldn't see this happening - at > least not initially. > > Regards > > Jakub This may be a place where good OO design helps. Thinking aloud: $schema =3D new JsonSchemaDraft4($schema_string); $schema->validate($json_string): bool; $otherSchema =3D new JsonSchemaDraft5($other_schema); etc. If there's a common JasonSchema interface for them all, it would also be= possible to polyfill the classes in user-space that way. The C-provide= d classes could of course share whatever underlying code makes sense for= them to share. --Larry Garfield