1

I am writing a reactive application using webflux with springdoc-openapi(v 1.4.3). Below is the router class

@Configuration
public class AppRouter {
  @RouterOperation(path = "/app", produces = {
      MediaType.APPLICATION_JSON_VALUE},
      beanClass = Apphandler.class, method = RequestMethod.GET, beanMethod = "getApp",
      operation = @Operation(operationId = "getApp", responses = {
          @ApiResponse(responseCode = "200", description = "successful operation",
              content = @Content(schema = @Schema(implementation = AppResponse.class)))
      },
          parameters = {
              @Parameter(in =  ParameterIn.HEADER, name = "Authorization ",required = true),
              @Parameter(in =  ParameterIn.QUERY, name = "id",required = true),
              @Parameter(in =  ParameterIn.QUERY, name = "idType")
              
      }
      ))
  @Bean
  public RouterFunction<ServerResponse> route(Apphandler handler) {
    return RouterFunctions.route(GET("/app"), handler::getApp);
  }

}

Corresponding to above api definition below swagger response is coming enter image description here

pom contains the below dependency for openapi

<dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webflux-core</artifactId>
            <version>1.4.3</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webflux-ui</artifactId>
            <version>1.4.3</version>
        </dependency>

Below queries:

Q1. I have made id and authorization as required=true but even when I am running without providing them from swagger it is not giving any warning message. Ideally it should give some warning message. How to get that message

Q2. id value needs to follow some REGEX pattern like [a-zA-Z0-9]{5,15}.How to add this regex check. Also if I am providing id which does not follow this pattern should give some warning message? How to achieve it?

Q3. How to add enum for parameter?

2
  • There is no router class Commented Feb 23, 2023 at 11:08
  • Really sorry. I was updating the question yesterday.seems there something unusual happened. I will update it once again. Is there any option to get the previous version of question?? Commented Feb 23, 2023 at 11:55

2 Answers 2

1

If you want to generate swagger documentation indicating that idField is an enumerated, you can use the schema property of the @Parameter annotation:

@Parameter(in = ParameterIn.QUERY, name = "idType", schema = @Schema(implementation = EIndType.class))

Where EIndType is the enum where you define all the possible values:

public enum EIndType {
  SITEGEOID("siteGeoId"),
  SITERKST("siteRkst"),
  CITYGEOID("cityGeoId"),
  CITYRKST("cityRkst");

  private final String value;

  public String getValue() {
     return value;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I have just added few more question. can you give your feedback on them?
0

I got the answer Q1 answer

@Parameter(in =  ParameterIn.HEADER, name = "Authorization ",required = true,schema =@Schema(minLength = 1))

Q2 answer

@Parameter(in =  ParameterIn.QUERY, name = "id",required = true,schema = @Schema(minLength = 5,maxLength = 15,pattern = "[a-zA-Z0-9]{5,15}"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.