Swagger ignored the required field for generated code

Viewed 233

I have element like this:

@ApiModel(description = "...")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class MissionContext   {
  @JsonProperty("missionName")
  private String missionName;
....
  @ApiModelProperty(required = true, value = "")
  public String getMissionName() {
    return missionName;
  }
...
}

Ok, this looks nice and this mission name should be required in the body in the post request, but it isn't.

My openapi 3.0.0 definition:

    MissionContext:
      type: object
      description: text
      properties:
        missionName:
          type: string
      required: [ missionName ]

Part to generate code

 <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>${openapi.generator.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <apiPackage>com.fake</apiPackage>
              <generateSupportingFiles>false</generateSupportingFiles>
              <generatorName>spring</generatorName>
              <inputSpec>${project.basedir}/src/etc/file.yaml</inputSpec>
              <configOptions>
                <interfaceOnly>true</interfaceOnly>
                <modelPackage>portal</modelPackage>
                <skipDefaultInterface>true</skipDefaultInterface>
                <useBeanValidation>false</useBeanValidation>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>

Jackson bean - default configuration without any added modules etc.

Could anyone help me? How to response bad request without a mission name in the body request?

0 Answers
Related