SpringdocCompatPlugin
SpringdocCompatPlugin fixes compatibility issues in OpenAPI documents generated by SpringDoc that do not conform to the OpenAPI specification.
In some versions, SpringDoc outputs non-compliant structures that cause parsing and validation failures. SpringdocCompatPlugin automatically fixes these issues during the beforeValidate stage:
- Flatten nested
extensions: SpringDoc nests extension fields (likex-*) inside an extraextensionsobject instead of placing them directly on the parent object. The plugin recursively flattens them back into their parent objects. - Fill missing parameter
schema: SpringDoc sometimes generatesparameterswithout aschemafield (and nocontentdefined), which violates the OpenAPI specification. The plugin automatically addsschema: {}to these parameters. - Remove empty
info.contact.email: when no contact is configured, SpringDoc emits"email": "", which fails OpenAPI'sformat: "email"validation and rejects the whole document. The plugin removes the empty field and leaves the other contact fields untouched.
Configuration
import { defineConfig } from "@keq-request/cli"
import { SpringdocCompatPlugin } from '@keq-request/cli/plugins'
export default defineConfig({
outdir: "./src/apis",
modules: {
userService: "file:///absolute/path/to/user-service-swagger.json",
},
plugins: [new SpringdocCompatPlugin()],
})If you encounter any of the following errors during validation, your OpenAPI document was generated by SpringDoc and has compatibility issues — adding this plugin will resolve them:
"Property extensions is not expected to be here"- Validation errors caused by parameters missing
schema format must match format "email"(emptyinfo.contact.email)
Options
| Option | Type | Default | Description |
|---|---|---|---|
ensureJsonBody | boolean | false | Deprecated: Use rendering.emptyJsonRequestBodyMode: 'empty-object' instead. Ensure application/json requests always carry a body |
ensureJsonBody
This option has been replaced by rendering.emptyJsonRequestBodyMode. Use rendering.emptyJsonRequestBodyMode: 'empty-object' to achieve the same effect.
import { defineConfig } from "@keq-request/cli"
export default defineConfig({
outdir: "./src/apis",
modules: {
userService: "file:///absolute/path/to/user-service-swagger.json",
},
rendering: {
emptyJsonRequestBodyMode: 'empty-object', // [!code highlight]
},
})rendering.emptyJsonRequestBodyMode also supports additional options: 'strict', 'omit', 'null'. See the configuration docs for details.
Historical notes (deprecated usage)
Spring Boot uses Jackson as the default JSON deserializer. When a request has Content-Type: application/json but carries no body, Jackson throws an error. With ensureJsonBody enabled, the generated code automatically sends an empty object {}.
import { defineConfig } from "@keq-request/cli"
import { SpringdocCompatPlugin } from '@keq-request/cli/plugins'
export default defineConfig({
outdir: "./src/apis",
modules: {
userService: "file:///absolute/path/to/user-service-swagger.json",
},
plugins: [new SpringdocCompatPlugin({ ensureJsonBody: true })],
})