swagger-api / swagger-api/swagger-codegen

[JAVA] Correct field validation in list of elements

Open
#10,913 0 comments 0 reactions 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

I have generated class:

@Validated
public class SomeClass extends AnotherSomeClass implements Serializable {
  private static final long serialVersionUID = 1L;
  @JsonProperty("...")
  @Valid
  private List<Element> elements = null;
  ...
}

It uses as a request body for POST controller. When it try to send request to controller without one required field from Element class, I have an error like: "elements[0].someField doesnt exist". Could I validate entity instead of list of entities with swagger codegen? I want to have error like: "someField doesnt exist" without list name and index of the element. Could you provide code example for this?

Swagger-codegen version

0.19.0.2

Command line used for generation

swagger-codegen-maven-plugin 0.19.0.2

<configOptions>
                <sourceFolder>swagger</sourceFolder>
                <library>spring-mvc</library>
                <interfaceOnly>true</interfaceOnly>
                <useBeanValidation>true</useBeanValidation>
                <java8>true</java8>
                <serializableModel>true</serializableModel>
                <useTags>true</useTags>
</configOptions>

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

The report identifies generated SomeClass and Element models, a Spring MVC POST body, and the useBeanValidation configuration in the Maven plugin. Reproduce the missing Element.someField request with swagger-codegen 0.19.0.2, then inspect the generated validation behavior; done requires a documented or tested expected error path, but no repository file or test is named.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.