@@ -701,3 +701,182 @@ select postgrest_openapi_spec('{test}')->'paths'->'/non_auto_updatable' ? 'delet
701701 f
702702(1 row)
703703
704+ -- Functions
705+ -- GET operation object
706+ -- shows the function name as tag
707+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_products_by_size'->'get'->'tags');
708+ jsonb_pretty
709+ ----------------------------------
710+ [ +
711+ "(rpc) get_products_by_size"+
712+ ]
713+ (1 row)
714+
715+ -- uses a reference for the 200 HTTP code response
716+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_products_by_size'->'get'->'responses'->'200');
717+ jsonb_pretty
718+ ----------------------------------------------------------------
719+ { +
720+ "$ref": "#/components/responses/rpc.get_products_by_size",+
721+ "description": "OK" +
722+ }
723+ (1 row)
724+
725+ -- uses a reference for the 206 HTTP code response on `RETURNS SET OF` functions
726+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_products_by_size'->'get'->'responses'->'206');
727+ jsonb_pretty
728+ ----------------------------------------------------------------
729+ { +
730+ "$ref": "#/components/responses/rpc.get_products_by_size",+
731+ "description": "Partial Content" +
732+ }
733+ (1 row)
734+
735+ -- uses a reference for error responses
736+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_products_by_size'->'get'->'responses'->'default');
737+ jsonb_pretty
738+ ----------------------------------------------------
739+ { +
740+ "$ref": "#/components/responses/defaultError",+
741+ "description": "Error" +
742+ }
743+ (1 row)
744+
745+ -- shows the first line of the comment on the table as summary
746+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_products_by_size'->'get'->'summary');
747+ jsonb_pretty
748+ --------------------------------
749+ "Get Products By Size summary"
750+ (1 row)
751+
752+ -- shows the second line of the comment on the table as description
753+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_products_by_size'->'get'->'description');
754+ jsonb_pretty
755+ -----------------------------------------------------------------
756+ "Get Products By Size description\nthat spans\nmultiple lines."
757+ (1 row)
758+
759+ -- uses references for common parameters on `RETURNS <composite type>` functions
760+ select value
761+ from jsonb_array_elements(postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_attribute'->'get'->'parameters')
762+ where value->>'$ref' not like '#/components/parameters/rpcParam.get_attribute.%';
763+ value
764+ -----------------------------------------------
765+ {"$ref": "#/components/parameters/select"}
766+ {"$ref": "#/components/parameters/order"}
767+ {"$ref": "#/components/parameters/limit"}
768+ {"$ref": "#/components/parameters/offset"}
769+ {"$ref": "#/components/parameters/or"}
770+ {"$ref": "#/components/parameters/and"}
771+ {"$ref": "#/components/parameters/not.or"}
772+ {"$ref": "#/components/parameters/not.and"}
773+ {"$ref": "#/components/parameters/range"}
774+ {"$ref": "#/components/parameters/preferGet"}
775+ (10 rows)
776+
777+ -- uses references for common parameters on `RETURNS TABLE` functions
778+ select value
779+ from jsonb_array_elements(postgrest_openapi_spec('{test}')->'paths'->'/rpc/returns_table'->'get'->'parameters')
780+ where value->>'$ref' not like '#/components/parameters/rpcParam.returns_table.%';
781+ value
782+ -----------------------------------------------
783+ {"$ref": "#/components/parameters/select"}
784+ {"$ref": "#/components/parameters/order"}
785+ {"$ref": "#/components/parameters/limit"}
786+ {"$ref": "#/components/parameters/offset"}
787+ {"$ref": "#/components/parameters/or"}
788+ {"$ref": "#/components/parameters/and"}
789+ {"$ref": "#/components/parameters/not.or"}
790+ {"$ref": "#/components/parameters/not.and"}
791+ {"$ref": "#/components/parameters/range"}
792+ {"$ref": "#/components/parameters/preferGet"}
793+ (10 rows)
794+
795+ -- uses references for common parameters on functions with INOUT/OUT parameters
796+ select value
797+ from jsonb_array_elements(postgrest_openapi_spec('{test}')->'paths'->'/rpc/returns_inout_out'->'get'->'parameters')
798+ where value->>'$ref' not like '#/components/parameters/rpcParam.returns_inout_out.%';
799+ value
800+ -----------------------------------------------
801+ {"$ref": "#/components/parameters/select"}
802+ {"$ref": "#/components/parameters/order"}
803+ {"$ref": "#/components/parameters/limit"}
804+ {"$ref": "#/components/parameters/offset"}
805+ {"$ref": "#/components/parameters/or"}
806+ {"$ref": "#/components/parameters/and"}
807+ {"$ref": "#/components/parameters/not.or"}
808+ {"$ref": "#/components/parameters/not.and"}
809+ {"$ref": "#/components/parameters/range"}
810+ {"$ref": "#/components/parameters/preferGet"}
811+ (10 rows)
812+
813+ -- does not use a reference for the 206 HTTP code response on functions that do not return `SET OF`
814+ select postgrest_openapi_spec('{test}')->'paths'->'/rpc/get_attribute'->'get'->'responses' ? '206' as value;
815+ value
816+ -------
817+ f
818+ (1 row)
819+
820+ -- does not use a reference for common parameters (except for prefer headers) on functions that do not return composite types
821+ select value
822+ from jsonb_array_elements(postgrest_openapi_spec('{test}')->'paths'->'/rpc/returns_simple_type'->'get'->'parameters')
823+ where value->>'$ref' not like '#/components/parameters/rpcParam.returns_simple_type.%';
824+ value
825+ -----------------------------------------------
826+ {"$ref": "#/components/parameters/preferGet"}
827+ (1 row)
828+
829+ -- shows a function with a single unnamed parameter of accepted types
830+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/single_unnamed_json_param'->'get'->'tags');
831+ jsonb_pretty
832+ ---------------------------------------
833+ [ +
834+ "(rpc) single_unnamed_json_param"+
835+ ]
836+ (1 row)
837+
838+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/single_unnamed_jsonb_param'->'get'->'tags');
839+ jsonb_pretty
840+ ----------------------------------------
841+ [ +
842+ "(rpc) single_unnamed_jsonb_param"+
843+ ]
844+ (1 row)
845+
846+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/single_unnamed_text_param'->'get'->'tags');
847+ jsonb_pretty
848+ ---------------------------------------
849+ [ +
850+ "(rpc) single_unnamed_text_param"+
851+ ]
852+ (1 row)
853+
854+ select jsonb_pretty(postgrest_openapi_spec('{test}')->'paths'->'/rpc/single_unnamed_xml_param'->'get'->'tags');
855+ jsonb_pretty
856+ --------------------------------------
857+ [ +
858+ "(rpc) single_unnamed_xml_param"+
859+ ]
860+ (1 row)
861+
862+ -- does not show a function with a single unnamed parameter of non-accepted types
863+ select postgrest_openapi_spec('{test}')->'paths' ? '/rpc/single_unnamed_unrecognized_param' as value;
864+ value
865+ -------
866+ f
867+ (1 row)
868+
869+ -- does not show a function with unnamed parameters
870+ select postgrest_openapi_spec('{test}')->'paths' ? '/rpc/unnamed_params' as value;
871+ value
872+ -------
873+ f
874+ (1 row)
875+
876+ -- does not show a function with named and unnamed parameters
877+ select postgrest_openapi_spec('{test}')->'paths' ? '/rpc/named_and_unnamed_params' as value;
878+ value
879+ -------
880+ f
881+ (1 row)
882+
0 commit comments