swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[JAVA] jaxrs-jersey: validation annotation for referenced schemas are not generated

Open res13 opened this issue 7 years ago • 1 comments

Description

Assuming there is a schema where one type references another which is not from type: object (see yaml file below): swagger-codegen generates a class MyExampleObjectType where the validation annotations are not present on the referencing objects getter. Here I expect the Annotation: @Size(max=11)

Swagger-codegen version

3.0.14

Swagger declaration file content or url
openapi: 3.0.0
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
servers:
  - url: 'https://api.example.com'
paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in Markdown.
      responses:
        '200':
          $ref: '#/components/schemas/MyExampleObjectType'
components:
  schemas:
    MyExampleStringType:
      type: string
      maxLength: 11
    MyExampleObjectType:
      type: object
      properties:
        myExampleString:
          $ref: '#/components/schemas/MyExampleStringType'
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i ref.yaml -l jaxrs-jersey

Steps to reproduce

Download the yaml above to a file ref.yaml and run the build command.

Suggest a fix/enhancement

Generate validation annotations also for referenced schemas.

res13 avatar Nov 29 '19 12:11 res13

Closed as fixed.

gracekarina avatar Apr 16 '21 13:04 gracekarina