Class OpenAPIContractBuilder

java.lang.Object
io.vertx.openapi.contract.OpenAPIContractBuilder

public class OpenAPIContractBuilder extends Object
Builder for OpenAPIContracts.

In the simplest case (you only have one contract) you must either provide a path to your openapi-contract in json or yaml format or an already parsed openapi-spec as a JsonObject. See setContractPath(String) and setContract(JsonObject).
If your contract is split across different files you must load the main contract as described above and additionally provide the referenced contract parts. See putAdditionalContractPartPath(String, String), setAdditionalContractPartPaths(Map), putAdditionalContractPart(String, JsonObject), setAdditionalContractParts(Map).

  • Constructor Details

    • OpenAPIContractBuilder

      public OpenAPIContractBuilder(Vertx vertx)
  • Method Details

    • setContractPath

      public OpenAPIContractBuilder setContractPath(String contractPath)
      Sets the path to the contract. Either provide the path to the contract or the parsed contract, not both. Overrides the contract set by setContract(JsonObject).
      Parameters:
      contractPath - The path to the contract
      Returns:
      The builder, for a fluent interface
    • setContract

      public OpenAPIContractBuilder setContract(JsonObject contract)
      Sets the contract. Either provide the contract or the path to the contract, not both. Overrides the contract set by setContractPath(String).
      Parameters:
      contract - The parsed contract
      Returns:
      The builder, for a fluent interface
    • putAdditionalContractPartPath

      public OpenAPIContractBuilder putAdditionalContractPartPath(String ref, String path)
      Puts an additional contract part path that is referenced by the main contract. This method can be called multiple times to add multiple referenced additional contract parts. Overrides a previously added additional contract part when the same reference is used.
      Parameters:
      ref - The unique reference of the additional contract part.
      path - The path to the contract part.
      Returns:
      The builder, for a fluent interface
    • setAdditionalContractPartPaths

      public OpenAPIContractBuilder setAdditionalContractPartPaths(Map<String,String> contractPartPaths)
      Uses the additional contract part paths from the provided map to resolve referenced contract parts. Replaces all previously put additional contract part paths by putAdditionalContractPartPath(String, String). If the same reference is used it overrides the additional contract part added by putAdditionalContractPart(String, JsonObject) or setAdditionalContractParts(Map).
      Parameters:
      contractPartPaths - A map that contains all additional contract part paths.
      Returns:
      The builder, for a fluent interface.
    • putAdditionalContractPart

      public OpenAPIContractBuilder putAdditionalContractPart(String ref, JsonObject contractPart)
      Puts an additional contract part that is referenced by the main contract. This method can be called multiple times to add multiple referenced additional contract parts.
      Parameters:
      ref - The unique reference of the additional contract part.
      contractPart - The additional contract part.
      Returns:
      The builder, for a fluent interface
    • setAdditionalContractParts

      public OpenAPIContractBuilder setAdditionalContractParts(Map<String, JsonObject> contractParts)
      Uses the additional contract parts from the provided map to resolve referenced additional contract parts. Replaces all previously put additional contract parts by putAdditionalContractPart(String, JsonObject). If the same reference is used also replaces the additional contract part paths added by putAdditionalContractPartPath(String, String) or setAdditionalContractPartPaths(Map).
      Parameters:
      contractParts - A map that contains additional contract parts.
      Returns:
      The builder, for a fluent interface.
    • mediaTypeRegistry

      public OpenAPIContractBuilder mediaTypeRegistry(MediaTypeRegistry registry)
    • build

      public Future<OpenAPIContract> build()
      Builds the contract.
      Returns:
      The contract.