@@ -141,6 +141,9 @@ export class CodeGenConfig {
141
141
httpClient : "" ,
142
142
routeTypes : "" ,
143
143
routeName : "" ,
144
+ jsonldContextDataContract : "" ,
145
+ jsonldEntityDataContract : "" ,
146
+ jsonldUtils : "" ,
144
147
} ;
145
148
schemaParsers : Record < string , ( ...args : unknown [ ] ) => MonoSchemaParser > = { } ;
146
149
toJS = false ;
@@ -180,6 +183,20 @@ export class CodeGenConfig {
180
183
181
184
successResponseStatusRange = [ 200 , 299 ] ;
182
185
186
+ /** JSON-LD specific configuration options */
187
+ jsonLdOptions = {
188
+ /** Generate context interfaces */
189
+ generateContext : true ,
190
+ /** Enforce strict JSON-LD typing */
191
+ strictTyping : false ,
192
+ /** Prefix for entity interfaces */
193
+ entityPrefix : "" ,
194
+ /** Suffix for context interfaces */
195
+ contextSuffix : "Context" ,
196
+ /** Generate utility types for JSON-LD */
197
+ generateUtils : true ,
198
+ } ;
199
+
183
200
extractingOptions : Partial < ExtractingOptions > = {
184
201
requestBodySuffix : [ "Payload" , "Body" , "Input" ] ,
185
202
requestParamsSuffix : [ "Params" ] ,
@@ -390,6 +407,18 @@ export class CodeGenConfig {
390
407
"relative-json-pointer" : ( ) => this . Ts . Keyword . String ,
391
408
regex : ( ) => this . Ts . Keyword . String ,
392
409
} ,
410
+ // JSON-LD specific types
411
+ "jsonld-iri" : ( ) => this . Ts . Keyword . String ,
412
+ "jsonld-literal" : ( schema ) => this . getJsonLdLiteralType ( schema ) ,
413
+ "jsonld-node" : ( ) => "JsonLdNode" ,
414
+ "jsonld-context" : ( ) =>
415
+ this . Ts . UnionType ( [
416
+ this . Ts . Keyword . String ,
417
+ this . Ts . Keyword . Object ,
418
+ this . Ts . ArrayType (
419
+ this . Ts . UnionType ( [ this . Ts . Keyword . String , this . Ts . Keyword . Object ] ) ,
420
+ ) ,
421
+ ] ) ,
393
422
} ;
394
423
395
424
templateInfos = [
@@ -403,6 +432,15 @@ export class CodeGenConfig {
403
432
{ name : "httpClient" , fileName : "http-client" } ,
404
433
{ name : "routeTypes" , fileName : "route-types" } ,
405
434
{ name : "routeName" , fileName : "route-name" } ,
435
+ {
436
+ name : "jsonldContextDataContract" ,
437
+ fileName : "jsonld-context-data-contract" ,
438
+ } ,
439
+ {
440
+ name : "jsonldEntityDataContract" ,
441
+ fileName : "jsonld-entity-data-contract" ,
442
+ } ,
443
+ { name : "jsonldUtils" , fileName : "jsonld-utils" } ,
406
444
] ;
407
445
408
446
templateExtensions = [ ".eta" , ".ejs" ] ;
@@ -439,6 +477,51 @@ export class CodeGenConfig {
439
477
this . componentTypeNameResolver = new ComponentTypeNameResolver ( this , [ ] ) ;
440
478
}
441
479
480
+ /** Helper method to determine JSON-LD literal type */
481
+ getJsonLdLiteralType = ( schema : any ) : string => {
482
+ if ( schema && typeof schema === "object" ) {
483
+ // Check for @type in schema to determine literal type
484
+ if ( schema [ "@type" ] ) {
485
+ const type = schema [ "@type" ] ;
486
+ switch ( type ) {
487
+ case "xsd:string" :
488
+ case "http://www.w3.org/2001/XMLSchema#string" :
489
+ return this . Ts . Keyword . String ;
490
+ case "xsd:integer" :
491
+ case "xsd:int" :
492
+ case "http://www.w3.org/2001/XMLSchema#integer" :
493
+ case "http://www.w3.org/2001/XMLSchema#int" :
494
+ return this . Ts . Keyword . Number ;
495
+ case "xsd:boolean" :
496
+ case "http://www.w3.org/2001/XMLSchema#boolean" :
497
+ return this . Ts . Keyword . Boolean ;
498
+ case "xsd:dateTime" :
499
+ case "http://www.w3.org/2001/XMLSchema#dateTime" :
500
+ return this . Ts . Keyword . String ; // or Date if preferred
501
+ default :
502
+ return this . Ts . Keyword . String ;
503
+ }
504
+ }
505
+
506
+ // Fallback to primitive type detection
507
+ if ( schema . type ) {
508
+ switch ( schema . type ) {
509
+ case "string" :
510
+ return this . Ts . Keyword . String ;
511
+ case "number" :
512
+ case "integer" :
513
+ return this . Ts . Keyword . Number ;
514
+ case "boolean" :
515
+ return this . Ts . Keyword . Boolean ;
516
+ default :
517
+ return this . Ts . Keyword . String ;
518
+ }
519
+ }
520
+ }
521
+
522
+ return this . Ts . Keyword . String ;
523
+ } ;
524
+
442
525
update = ( update : Partial < GenerateApiConfiguration [ "config" ] > ) => {
443
526
objectAssign ( this , update ) ;
444
527
} ;
0 commit comments