Skip to content

openapi: relax parameter validation when using openapi annotations #3954

@jknack

Description

@jknack

When an annotation is used to define parameter, we should NOT validate parameter from code.

@Operation(
      summary = "Get a thing",
      parameters =
          @Parameter(
              name = "x-api-key",
              description = "API Key",
              in = ParameterIn.HEADER,
              schema = @Schema(type = "string"),
              required = true))
  private static String getThing(Context context) {
     /* ... */
  }

Resulted in:

[ERROR] Failed to execute goal io.jooby:jooby-maven-plugin:4.0.15:openapi (default) 
on project crunchtime-suite-api: execution of openapi resulted in exception: Parameter 
not found: x-api-key at  position: 0 for annotation: {name=x-api-key, description=API Key, 
in=[Ljava.lang.String;@43cd2f26, schema=org.objectweb.asm.tree.AnnotationNode@7d043960, 
required=true} -> [Help 1]

OpenApi expect parameter to be extracted from context:

private static String getThing(Context context) {
    // read param you defined in annotation
    var apiKey = context.header("x-api-key").value();
    return "works!";
}

Which might or might not be accurate, see #3952.

When user explicitly add a parameter via annotation we are not going to force/validate anything

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions