-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Description
Description
Hello, at the moment swagger-codegen has incomplete validation. Body of the request is validated normally, but path validation doesn't work at all.
The root cause of the problem is that controller (or controller interface) doesn't have annotation @validated. There is workaround if I extends controller directly, but then a need to repeat all parameters annotations to make it works.
Good decision for me is to use delegates, but then I can't manually add @validated annotation to controller bean.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
swagger: '2.0'
info:
version: 0.0.1
title: swagger-codegen-validation
paths:
'/swagger/validation/{id}':
post:
consumes:
- application/json
produces:
- application/json
parameters:
- in: path
name: id
required: true
type: string
pattern: '\d*'
- in: body
name: RequestBody
required: true
schema:
$ref: '#/definitions/SwaggerRequestBody'
responses:
default:
schema:
type: object
properties:
answer:
type: string
definitions:
SwaggerRequestBody:
type: object
properties:
name:
type: string
required:
- name
swagger-codegen-maven plugin configuration
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- specify the swagger yaml -->
<inputSpec>${project.basedir}/src/main/resources/swagger.yaml
</inputSpec>
<!-- target to generate -->
<output>${project.basedir}/target/generated-sources/swagger</output>
<!-- pass any necessary config options -->
<configOptions>
<dateLibrary>java8</dateLibrary>
<serializableModel>true</serializableModel>
<generateApis>true</generateApis>
<generateApiTests>false</generateApiTests>
<generateModels>true</generateModels>
<generateModelTests>false</generateModelTests>
<basePackage>${default.package}</basePackage>
<configPackage>${default.package}.config</configPackage>
<sourceFolder>api</sourceFolder>
<useTags>true</useTags>
<delegatePattern>true</delegatePattern>
</configOptions>
<library>spring-boot</library>
<apiPackage>${default.package}.controller</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
<invokerPackage>${default.package}.handler</invokerPackage>
<ignoreFileOverride>${project.basedir}/.swagger-codegen-ignore</ignoreFileOverride>
</configuration>
</execution>
</executions>
</plugin>
Suggest a fix/enhancement
Add @validated annotation to spring controller's moustache if useValidation flag is true
scrun, pavellikin, cnuonline, Alex-Wir, hleb-kastseika and 1 more
Metadata
Metadata
Assignees
Labels
No labels