File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -590,6 +590,7 @@ func server(cmd *cobra.Command, args []string) {
590
590
591
591
var err error
592
592
var data []byte
593
+ dataType := strings .Trim (strings .ToLower (filepath .Ext (uri )), "." )
593
594
594
595
// Load either from an HTTP URL or from a local file depending on the passed
595
596
// in value.
@@ -715,6 +716,21 @@ func server(cmd *cobra.Command, args []string) {
715
716
log .Printf ("Health check" )
716
717
})
717
718
719
+ // Another custom handler to return the exact swagger document given to us
720
+ http .HandleFunc ("/__schema" , func (w http.ResponseWriter , req * http.Request ) {
721
+ if ! viper .GetBool ("disable-cors" ) {
722
+ corsOrigin := req .Header .Get ("Origin" )
723
+ if corsOrigin == "" {
724
+ corsOrigin = "*"
725
+ }
726
+ w .Header ().Set ("Access-Control-Allow-Origin" , corsOrigin )
727
+ }
728
+
729
+ w .Header ().Set ("Content-Type" , fmt .Sprintf ("application/%v; charset=utf-8" , dataType ))
730
+ w .WriteHeader (http .StatusOK )
731
+ fmt .Fprint (w , string (data ))
732
+ })
733
+
718
734
// Register our custom HTTP handler that will use the router to find
719
735
// the appropriate OpenAPI operation and try to return an example.
720
736
http .Handle ("/" , handler (rr ))
You can’t perform that action at this time.
0 commit comments