Http-Part Package
The org.apache.juneau.commons.httppart package provides the shared enumerations and exception used to describe HTTP "parts" (query parameters, path variables, headers, form data, and request/response bodies) for OpenAPI-schema-based serialization and parsing.
When to use it
Use these types when you describe or validate an HTTP part against an OpenAPI schema: the schema's type, format and collectionFormat fields map directly onto the enumerations below.
Each enumeration has a fromString method that accepts the schema keyword and returns the matching constant, so you can read a schema fragment without writing a lookup table.
Most applications never touch them directly; they appear when you build an OpenApiSerializer or OpenApiParser, or implement your own part handling.
Example
import org.apache.juneau.commons.httppart.*;
public class HttpPartTypesExample {
public static void main(String[] args) {
// Schema keywords map to enum constants.
HttpPartDataType type = HttpPartDataType.fromString("array");
HttpPartCollectionFormat collection = HttpPartCollectionFormat.fromString("pipes");
HttpPartFormat format = HttpPartFormat.fromString("date-time");
// The constants know which schema keywords they belong to.
boolean isDate = format.isOneOf(HttpPartFormat.DATE, HttpPartFormat.DATE_TIME);
// Where the part lives in the request.
HttpPartType part = HttpPartType.valueOf("QUERY");
System.out.println(type + " " + collection + " " + format + " " + isDate + " " + part);
}
}
The program prints array pipes date-time true QUERY.
Options
| Type | Meaning |
|---|---|
| The possible HTTP part types (e.g. query, header, path, form-data, body). | |
Valid values for a schema's type field (string, number, integer, boolean, array, object, etc.). | |
Valid values for a schema's format field (int32, int64, date-time, byte, binary, etc.). | |
Valid values for a schema's collectionFormat field (csv, ssv, tsv, pipes, multi, etc.). | |
| Thrown when an HTTP part fails schema validation. |
See also
- OpenAPI Support: the schema-based serializers and parsers that use these types.
- OpenAPI Serializers
- OpenAPI Parsers