diff --git a/examples/ex_2ch/oas_cfg_gen.go b/examples/ex_2ch/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_2ch/oas_cfg_gen.go +++ b/examples/ex_2ch/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_ent/oas_cfg_gen.go b/examples/ex_ent/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_ent/oas_cfg_gen.go +++ b/examples/ex_ent/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_firecracker/oas_cfg_gen.go b/examples/ex_firecracker/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_firecracker/oas_cfg_gen.go +++ b/examples/ex_firecracker/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_github/oas_cfg_gen.go b/examples/ex_github/oas_cfg_gen.go index 43ca257d4..dbaf4bace 100644 --- a/examples/ex_github/oas_cfg_gen.go +++ b/examples/ex_github/oas_cfg_gen.go @@ -89,8 +89,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_gotd/oas_cfg_gen.go b/examples/ex_gotd/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_gotd/oas_cfg_gen.go +++ b/examples/ex_gotd/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_k8s/oas_cfg_gen.go b/examples/ex_k8s/oas_cfg_gen.go index 3d6996817..68add4bc3 100644 --- a/examples/ex_k8s/oas_cfg_gen.go +++ b/examples/ex_k8s/oas_cfg_gen.go @@ -85,8 +85,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_manga/oas_cfg_gen.go b/examples/ex_manga/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_manga/oas_cfg_gen.go +++ b/examples/ex_manga/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_oauth2/oas_cfg_gen.go b/examples/ex_oauth2/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_oauth2/oas_cfg_gen.go +++ b/examples/ex_oauth2/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_openai/oas_cfg_gen.go b/examples/ex_openai/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_openai/oas_cfg_gen.go +++ b/examples/ex_openai/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_petstore/oas_cfg_gen.go b/examples/ex_petstore/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_petstore/oas_cfg_gen.go +++ b/examples/ex_petstore/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_petstore_expanded/oas_cfg_gen.go b/examples/ex_petstore_expanded/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_petstore_expanded/oas_cfg_gen.go +++ b/examples/ex_petstore_expanded/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_route_params/oas_cfg_gen.go b/examples/ex_route_params/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_route_params/oas_cfg_gen.go +++ b/examples/ex_route_params/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_telegram/oas_cfg_gen.go b/examples/ex_telegram/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_telegram/oas_cfg_gen.go +++ b/examples/ex_telegram/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_test_format/oas_cfg_gen.go b/examples/ex_test_format/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_test_format/oas_cfg_gen.go +++ b/examples/ex_test_format/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/examples/ex_tinkoff/oas_cfg_gen.go b/examples/ex_tinkoff/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/examples/ex_tinkoff/oas_cfg_gen.go +++ b/examples/ex_tinkoff/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/gen/_template/cfg.tmpl b/gen/_template/cfg.tmpl index d0931339e..76f4e1e74 100644 --- a/gen/_template/cfg.tmpl +++ b/gen/_template/cfg.tmpl @@ -75,8 +75,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/referenced_path_item/oas_cfg_gen.go b/internal/integration/referenced_path_item/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/referenced_path_item/oas_cfg_gen.go +++ b/internal/integration/referenced_path_item/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/sample_api/oas_cfg_gen.go b/internal/integration/sample_api/oas_cfg_gen.go index 42f851f82..c4393ae3d 100644 --- a/internal/integration/sample_api/oas_cfg_gen.go +++ b/internal/integration/sample_api/oas_cfg_gen.go @@ -106,8 +106,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/sample_api_nc/oas_cfg_gen.go b/internal/integration/sample_api_nc/oas_cfg_gen.go index 6cc672509..e8f0a0fb8 100644 --- a/internal/integration/sample_api_nc/oas_cfg_gen.go +++ b/internal/integration/sample_api_nc/oas_cfg_gen.go @@ -103,8 +103,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/sample_api_no_otel/oas_cfg_gen.go b/internal/integration/sample_api_no_otel/oas_cfg_gen.go index d774e015e..2d50376c4 100644 --- a/internal/integration/sample_api_no_otel/oas_cfg_gen.go +++ b/internal/integration/sample_api_no_otel/oas_cfg_gen.go @@ -67,8 +67,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/sample_err/oas_cfg_gen.go b/internal/integration/sample_err/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/sample_err/oas_cfg_gen.go +++ b/internal/integration/sample_err/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/techempower/oas_cfg_gen.go b/internal/integration/techempower/oas_cfg_gen.go index c71e755dc..ac718ab23 100644 --- a/internal/integration/techempower/oas_cfg_gen.go +++ b/internal/integration/techempower/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_allof/oas_cfg_gen.go b/internal/integration/test_allof/oas_cfg_gen.go index 7176f182a..6ddf5dcad 100644 --- a/internal/integration/test_allof/oas_cfg_gen.go +++ b/internal/integration/test_allof/oas_cfg_gen.go @@ -85,8 +85,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_anyof/oas_cfg_gen.go b/internal/integration/test_anyof/oas_cfg_gen.go index f44747433..4556ee56e 100644 --- a/internal/integration/test_anyof/oas_cfg_gen.go +++ b/internal/integration/test_anyof/oas_cfg_gen.go @@ -85,8 +85,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_enum_naming/oas_cfg_gen.go b/internal/integration/test_enum_naming/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_enum_naming/oas_cfg_gen.go +++ b/internal/integration/test_enum_naming/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_form/oas_cfg_gen.go b/internal/integration/test_form/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_form/oas_cfg_gen.go +++ b/internal/integration/test_form/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_http_requests/oas_cfg_gen.go b/internal/integration/test_http_requests/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_http_requests/oas_cfg_gen.go +++ b/internal/integration/test_http_requests/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_http_responses/oas_cfg_gen.go b/internal/integration/test_http_responses/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_http_responses/oas_cfg_gen.go +++ b/internal/integration/test_http_responses/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_naming_extensions/oas_cfg_gen.go b/internal/integration/test_naming_extensions/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_naming_extensions/oas_cfg_gen.go +++ b/internal/integration/test_naming_extensions/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_parameters/oas_cfg_gen.go b/internal/integration/test_parameters/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_parameters/oas_cfg_gen.go +++ b/internal/integration/test_parameters/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_security/oas_cfg_gen.go b/internal/integration/test_security/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_security/oas_cfg_gen.go +++ b/internal/integration/test_security/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_servers/oas_cfg_gen.go b/internal/integration/test_servers/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_servers/oas_cfg_gen.go +++ b/internal/integration/test_servers/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_single_endpoint/oas_cfg_gen.go b/internal/integration/test_single_endpoint/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_single_endpoint/oas_cfg_gen.go +++ b/internal/integration/test_single_endpoint/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil, diff --git a/internal/integration/test_webhooks/oas_cfg_gen.go b/internal/integration/test_webhooks/oas_cfg_gen.go index 19d9d19e5..e7311e748 100644 --- a/internal/integration/test_webhooks/oas_cfg_gen.go +++ b/internal/integration/test_webhooks/oas_cfg_gen.go @@ -81,8 +81,15 @@ func newServerConfig(opts ...ServerOption) serverConfig { cfg := serverConfig{ NotFound: http.NotFound, MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - w.Header().Set("Allow", allowed) - w.WriteHeader(http.StatusMethodNotAllowed) + status := http.StatusMethodNotAllowed + if r.Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Methods", allowed) + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + status = http.StatusNoContent + } else { + w.Header().Set("Allow", allowed) + } + w.WriteHeader(status) }, ErrorHandler: ogenerrors.DefaultErrorHandler, Middleware: nil,