@@ -303,7 +303,7 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
303303 } ) ;
304304
305305 describe ( 'x-protobuf-type extension' , ( ) => {
306- it ( 'should apply type mapping for int32 ' , ( ) => {
306+ it ( 'should apply x-protobuf- type directly to schema type ' , ( ) => {
307307 const spec : any = {
308308 openapi : '3.1.0' ,
309309 info : { title : 'Test API' , version : '1.0.0' } ,
@@ -342,12 +342,11 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
342342 const result = processor . process ( ) ;
343343
344344 const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
345- expect ( schema . properties . count . type ) . toBe ( 'integer' ) ;
346- expect ( schema . properties . count . format ) . toBe ( 'int32' ) ;
345+ expect ( schema . properties . count . type ) . toBe ( 'int32' ) ;
347346 expect ( schema . properties . count [ 'x-protobuf-type' ] ) . toBeUndefined ( ) ;
348347 } ) ;
349348
350- it ( 'should apply type mapping for int64 ' , ( ) => {
349+ it ( 'should apply x-protobuf- type for schema-level override ' , ( ) => {
351350 const spec : any = {
352351 openapi : '3.1.0' ,
353352 info : { title : 'Test API' , version : '1.0.0' } ,
@@ -380,12 +379,11 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
380379 const result = processor . process ( ) ;
381380
382381 const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
383- expect ( schema . type ) . toBe ( 'integer' ) ;
384- expect ( schema . format ) . toBe ( 'int64' ) ;
382+ expect ( schema . type ) . toBe ( 'int64' ) ;
385383 } ) ;
386384
387385
388- it ( 'should use custom type when not in mapping ' , ( ) => {
386+ it ( 'should use custom type directly ' , ( ) => {
389387 const spec : any = {
390388 openapi : '3.1.0' ,
391389 info : { title : 'Test API' , version : '1.0.0' } ,
@@ -419,7 +417,6 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
419417
420418 const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
421419 expect ( schema . type ) . toBe ( 'CustomType' ) ;
422- expect ( schema . format ) . toBeUndefined ( ) ;
423420 } ) ;
424421
425422 it ( 'should apply type override in request bodies' , ( ) => {
@@ -456,7 +453,7 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
456453 schema : {
457454 type : 'object' ,
458455 properties : {
459- field : { 'x-protobuf-type' : 'int64 ' }
456+ field : { 'x-protobuf-type' : 'uint64 ' }
460457 }
461458 }
462459 }
@@ -479,12 +476,10 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
479476
480477 const requestBody = result . components ! . requestBodies ! [ 'TestRequest' ] as any ;
481478 const requestSchema = requestBody . content [ 'application/json' ] . schema ;
482- expect ( requestSchema . properties . field . type ) . toBe ( 'integer' ) ;
483- expect ( requestSchema . properties . field . format ) . toBe ( 'int64' ) ;
479+ expect ( requestSchema . properties . field . type ) . toBe ( 'uint64' ) ;
484480
485481 const schema = result . components ! . schemas ! [ 'RequestSchema' ] as any ;
486- expect ( schema . properties . count . type ) . toBe ( 'integer' ) ;
487- expect ( schema . properties . count . format ) . toBe ( 'int32' ) ;
482+ expect ( schema . properties . count . type ) . toBe ( 'int32' ) ;
488483 } ) ;
489484
490485 it ( 'should apply name override in responses' , ( ) => {
@@ -621,5 +616,165 @@ describe('VendorExtensionProcessor - Basic Tests', () => {
621616 expect ( schema . oneOf ) . toHaveLength ( 2 ) ;
622617 expect ( schema . oneOf [ 0 ] . title ) . toBeUndefined ( ) ;
623618 } ) ;
619+
620+ it ( 'should handle bool protobuf type' , ( ) => {
621+ const spec : any = {
622+ openapi : '3.1.0' ,
623+ info : { title : 'Test API' , version : '1.0.0' } ,
624+ paths : {
625+ '/test' : {
626+ get : {
627+ responses : {
628+ '200' : {
629+ description : 'Success' ,
630+ content : {
631+ 'application/json' : {
632+ schema : { $ref : '#/components/schemas/TestSchema' }
633+ }
634+ }
635+ }
636+ }
637+ }
638+ }
639+ } ,
640+ components : {
641+ schemas : {
642+ 'TestSchema' : {
643+ type : 'object' ,
644+ properties : {
645+ enabled : { 'x-protobuf-type' : 'bool' }
646+ }
647+ }
648+ }
649+ }
650+ } ;
651+
652+ const processor = new VendorExtensionProcessor ( spec ) ;
653+ const result = processor . process ( ) ;
654+
655+ const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
656+ expect ( schema . properties . enabled . type ) . toBe ( 'bool' ) ;
657+ expect ( schema . properties . enabled [ 'x-protobuf-type' ] ) . toBeUndefined ( ) ;
658+ } ) ;
659+
660+ it ( 'should handle bytes protobuf type' , ( ) => {
661+ const spec : any = {
662+ openapi : '3.1.0' ,
663+ info : { title : 'Test API' , version : '1.0.0' } ,
664+ paths : {
665+ '/test' : {
666+ get : {
667+ responses : {
668+ '200' : {
669+ description : 'Success' ,
670+ content : {
671+ 'application/json' : {
672+ schema : { $ref : '#/components/schemas/TestSchema' }
673+ }
674+ }
675+ }
676+ }
677+ }
678+ }
679+ } ,
680+ components : {
681+ schemas : {
682+ 'TestSchema' : {
683+ type : 'object' ,
684+ properties : {
685+ data : { 'x-protobuf-type' : 'bytes' }
686+ }
687+ }
688+ }
689+ }
690+ } ;
691+
692+ const processor = new VendorExtensionProcessor ( spec ) ;
693+ const result = processor . process ( ) ;
694+
695+ const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
696+ expect ( schema . properties . data . type ) . toBe ( 'bytes' ) ;
697+ expect ( schema . properties . data [ 'x-protobuf-type' ] ) . toBeUndefined ( ) ;
698+ } ) ;
699+
700+ it ( 'should handle double protobuf type' , ( ) => {
701+ const spec : any = {
702+ openapi : '3.1.0' ,
703+ info : { title : 'Test API' , version : '1.0.0' } ,
704+ paths : {
705+ '/test' : {
706+ get : {
707+ responses : {
708+ '200' : {
709+ description : 'Success' ,
710+ content : {
711+ 'application/json' : {
712+ schema : { $ref : '#/components/schemas/TestSchema' }
713+ }
714+ }
715+ }
716+ }
717+ }
718+ }
719+ } ,
720+ components : {
721+ schemas : {
722+ 'TestSchema' : {
723+ type : 'object' ,
724+ properties : {
725+ value : { 'x-protobuf-type' : 'double' }
726+ }
727+ }
728+ }
729+ }
730+ } ;
731+
732+ const processor = new VendorExtensionProcessor ( spec ) ;
733+ const result = processor . process ( ) ;
734+
735+ const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
736+ expect ( schema . properties . value . type ) . toBe ( 'double' ) ;
737+ expect ( schema . properties . value [ 'x-protobuf-type' ] ) . toBeUndefined ( ) ;
738+ } ) ;
739+
740+ it ( 'should handle uint64 protobuf type' , ( ) => {
741+ const spec : any = {
742+ openapi : '3.1.0' ,
743+ info : { title : 'Test API' , version : '1.0.0' } ,
744+ paths : {
745+ '/test' : {
746+ get : {
747+ responses : {
748+ '200' : {
749+ description : 'Success' ,
750+ content : {
751+ 'application/json' : {
752+ schema : { $ref : '#/components/schemas/TestSchema' }
753+ }
754+ }
755+ }
756+ }
757+ }
758+ }
759+ } ,
760+ components : {
761+ schemas : {
762+ 'TestSchema' : {
763+ type : 'object' ,
764+ properties : {
765+ count : { 'x-protobuf-type' : 'uint64' }
766+ }
767+ }
768+ }
769+ }
770+ } ;
771+
772+ const processor = new VendorExtensionProcessor ( spec ) ;
773+ const result = processor . process ( ) ;
774+
775+ const schema = result . components ! . schemas ! [ 'TestSchema' ] as any ;
776+ expect ( schema . properties . count . type ) . toBe ( 'uint64' ) ;
777+ expect ( schema . properties . count [ 'x-protobuf-type' ] ) . toBeUndefined ( ) ;
778+ } ) ;
624779 } ) ;
625780} ) ;
0 commit comments