{"record":{"id":"922c6f8a0371e0e9","repo":"OpenAPITools/openapi-generator","slug":"usespringsecuritypreauthorize-is-only-supported-wi","errorCode":null,"errorMessage":"useSpringSecurityPreAuthorize is only supported with the spring-boot library","messagePattern":"useSpringSecurityPreAuthorize is only supported with the spring-boot library","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java","lineNumber":657,"sourceCode":"\n        convertPropertyToBooleanAndWriteBack(USE_ENUM_CASE_INSENSITIVE, this::setUseEnumCaseInsensitive);\n        convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);\n        convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT3, this::setUseSpringBoot3);\n        convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4);\n\n        if (isUseSpringBoot4()) {\n            setUseSpringBoot3(false);\n        }\n        if (isNotEmpty(clientRegistrationId)) {\n            if (!SPRING_HTTP_INTERFACE.equals(library)) {\n                throw new IllegalArgumentException(CLIENT_REGISTRATION_ID + \" is only supported with the \" + SPRING_HTTP_INTERFACE + \" library\");\n            }\n            if (!isUseSpringBoot4()) {\n                throw new IllegalArgumentException(CLIENT_REGISTRATION_ID + \" requires \" + USE_SPRING_BOOT4 + \"=true because @ClientRegistrationId is provided by Spring Security 7\");\n            }\n        }\n        if (useSpringSecurityPreAuthorize && !SPRING_BOOT.equals(library)) {\n            throw new IllegalArgumentException(USE_SPRING_SECURITY_PRE_AUTHORIZE\n                    + \" is only supported with the \" + SPRING_BOOT + \" library\");\n        }\n\n        if (isUseSpringBoot3() || isUseSpringBoot4()) {\n            if (AnnotationLibrary.SWAGGER1.equals(getAnnotationLibrary())) {\n                throw new IllegalArgumentException(AnnotationLibrary.SWAGGER1.getPropertyName() + \" is not supported with Spring Boot > 3.x\");\n            }\n            useJakartaEe = true;\n            applyJakartaPackage();\n        }\n        if(isUseJackson3() && !isUseSpringBoot4()){\n            throw new IllegalArgumentException(\"useJackson3 is only available with Spring Boot >= 4\");\n        }\n        if(this.useJackson3){\n            this.applyJackson3Package();\n        } else {\n            this.applyJackson2Package();\n        }","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java#L639-L675","documentation":"Thrown during Spring generator option processing when useSpringSecurityPreAuthorize=true but the active library is not spring-boot. The option makes templates emit @PreAuthorize annotations from Spring Security, and those are only wired into the server-stub templates of the spring-boot library. HTTP-interface or other client libraries cannot carry method-level security metadata.","triggerScenarios":"-g spring with --library=spring-http-interface (or any library other than spring-boot) combined with -DuseSpringSecurityPreAuthorize=true.","commonSituations":"Switching a project from the spring-boot library to spring-http-interface and leaving the security option in the generator config; pasting a full option list from a server project into a client generation job; CI pipelines that share one options file across generators.","solutions":["Remove useSpringSecurityPreAuthorize when generating spring-http-interface clients (security belongs to the server).","Or keep the option and set --library=spring-boot, the only library that supports it.","Audit shared generator configs for server-only options before reusing them for clients."],"exampleFix":"// before (openapi-generator-maven-plugin config)\n<library>spring-http-interface</library>\n<configOptions>\n  <useSpringSecurityPreAuthorize>true</useSpringSecurityPreAuthorize>\n</configOptions>\n\n// after\n<library>spring-http-interface</library>\n<!-- option removed -->","handlingStrategy":"validation","validationCode":"# bash: reject server-only options on client libraries\nif [ \"$USE_SPRING_SECURITY_PRE_AUTHORIZE\" = \"true\" ] && [ \"$LIBRARY\" != \"spring-boot\" ]; then\n  echo \"useSpringSecurityPreAuthorize requires library=spring-boot\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    config.setUseSpringSecurityPreAuthorize(true); // only when library == spring-boot\n    new DefaultGenerator().opts(input).generate();\n} catch (IllegalArgumentException e) {\n    // configuration error: surface message, correct options; never retry unchanged\n}","preventionTips":["Maintain separate option presets for server (spring-boot) and client (spring-http-interface) generation.","Add a config linter step that rejects known library-unsupported option combinations.","Document which options are template-scoped when onboarding new generators."],"tags":["spring","security","configuration","openapi-generator"],"backgroundTag":"incompatible-generator-options","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}