File tree Expand file tree Collapse file tree
packages/quicktype-core/src/language/CJSON Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,10 @@ import { arrayIntercalate } from "collection-utils";
55/* eslint-disable @typescript-eslint/naming-convention */
66
77import { getAccessorName } from "../../attributes/AccessorNames.js" ;
8- import { minMaxValueForType } from "../../attributes/Constraints.js" ;
8+ import {
9+ minMaxLengthForType ,
10+ minMaxValueForType ,
11+ } from "../../attributes/Constraints.js" ;
912import { enumCaseValues } from "../../attributes/EnumValues.js" ;
1013import {
1114 ConvenienceRenderer ,
@@ -2396,6 +2399,10 @@ export class CJSONRenderer extends ConvenienceRenderer {
23962399 minMaxValueForType (
23972400 property . type ,
23982401 ) ?? [ ] ;
2402+ const [ minLength , maxLength ] =
2403+ minMaxLengthForType (
2404+ property . type ,
2405+ ) ?? [ ] ;
23992406 if ( ! property . isOptional ) {
24002407 this . emitLine (
24012408 `if (!cJSON_HasObjectItem(${ object } , "${ jsonName } ")) { cJSON_Delete${ this . sourcelikeToString ( className ) } (x); return NULL; }` ,
@@ -2443,6 +2450,14 @@ export class CJSONRenderer extends ConvenienceRenderer {
24432450 `if (${ value } ->valuedouble > ${ maximum } ) { cJSON_Delete${ this . sourcelikeToString ( className ) } (x); return NULL; }` ,
24442451 ) ;
24452452 }
2453+ if ( minLength !== undefined )
2454+ this . emitLine (
2455+ `if (strlen(${ value } ->valuestring) < ${ minLength } ) { cJSON_Delete${ this . sourcelikeToString ( className ) } (x); return NULL; }` ,
2456+ ) ;
2457+ if ( maxLength !== undefined )
2458+ this . emitLine (
2459+ `if (strlen(${ value } ->valuestring) > ${ maxLength } ) { cJSON_Delete${ this . sourcelikeToString ( className ) } (x); return NULL; }` ,
2460+ ) ;
24462461 if (
24472462 cJSON . cjsonType ===
24482463 "cJSON_Enum"
Original file line number Diff line number Diff line change @@ -608,7 +608,6 @@ export const CJSONLanguage: Language = {
608608 "multi-type-enum.schema" ,
609609 "prefix-items.schema" ,
610610 /* Constraints (min/max and regex) are not supported (for the current implementation, can be added later, should abord parsing and return NULL) */
611- "minmaxlength.schema" ,
612611 "schema-constraints.schema" ,
613612 "optional-const-ref.schema" ,
614613 /* Same unsupported min/max, length and regex constraints, applied to optional properties */
You can’t perform that action at this time.
0 commit comments