swagger-api / swagger-api/swagger-codegen

[Java] redundant override in child class which causes ConstraintDeclarationException

Open
#10,495 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

in version 2.4.15 the following feature were aded:
added parent if it was not assigned by parser on allOf composed model (#10366 )

the result of that is generation of child class which extends parent class and duplicates a method which annotated with @Valid which resulted with the following:

Caused by: javax.validation.ConstraintDeclarationException: HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: OfferInputForAddSubscriber#getExpirationDate(), OfferInputBase#getExpirationDate().
    at org.hibernate.validator.internal.metadata.aggregated.rule.ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.apply(ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.java:24)
    at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.assertCorrectnessOfConfiguration(ExecutableMetaData.java:461)
    at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:377)
    at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BuilderDelegate.build(BeanMetaDataImpl.java:788)
    at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BeanMetaDataBuilder.build(BeanMetaDataImpl.java:648)
    at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:204)
    at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanMetaData(BeanMetaDataManager.java:166)
    at org.hibernate.validator.internal.engine.ValidatorImpl.buildNewLocalExecutionContext(ValidatorImpl.java:772)
    at org.hibernate.validator.internal.engine.ValidatorImpl.access$200(ValidatorImpl.java:85)
    at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.doValidate(ValidatorImpl.java:704)
    at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.indexedValue(ValidatorImpl.java:678)
    at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:26)
    at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:16)
    at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues(ValueExtractorHelper.java:42)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedContainerElementsForCurrentGroup(ValidatorImpl.java:648)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:595)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:406)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:626)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:587)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:406)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:626)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:587)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:406)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:173)
Swagger-codegen version

2.4.15

Swagger declaration file content or url
swagger: '2.0'
info:
  version: 1.0.0
  title: Server common definitions
paths: { }
definitions:
  OfferInputBase:
    allOf:
      - $ref: '#/definitions/OfferBase'
      - type: object
        description: |
          Offer details in input tasks
        properties:
          expirationDate:
            description: |
              Future expiration date of added offers
            type: string
            format: date-time
  OfferInputForAddSubscriber:
    allOf:
      - $ref: '#/definitions/OfferInputBase'
    description: |
      Offers attached to the subscriber when a subscriber is added
  OfferBase:
    type: object
    description: |
      Base object for offer definition
    properties:
      id:
        type: integer
        description: |
          Unique identifier of the offer in the catalog
        format: int64
        minimum: 1
        maximum: 999999999
      instance:
        type: integer
        description: |
          Offer attachment instance
        format: int64
        minimum: 1
        maximum: 999999999999999999
    required:
      - id
      - instance
Command line used for generation

we use maven in order to generate code

Steps to reproduce

generate the yaml, the generated code will include getExpirationDate() methods in parent & child with @Valid annotation which will cause the exception I mentioned above. it is enough to generate this method only in the parent.

Related issues/PRs

(#10366 ) - the pr which cause this issue. i downgraded to 2.4.14 and it worked there.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the change from related PR #10366 and the generated Java classes produced from the supplied Swagger definition. Run the Maven generation command with the example YAML and inspect the parent and child getExpirationDate() methods. Done means the method is generated only in the parent and validation no longer raises ConstraintDeclarationException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.