Class ContractParser

java.lang.Object
com.arc_e_tect.gradle.apionly.transcriberj.model.ContractParser

public final class ContractParser extends Object
Builds a ContractModel from a bundled OpenAPI 3 contract.

Bundled means self-contained: every $ref in a schema points at a schema component in the same document, which is what the API-Only Publisher produces.

  • Method Details

    • parse

      public static ContractModel parse(Path file) throws IOException
      Parses a contract file, read as UTF-8.
      Parameters:
      file - the contract
      Returns:
      the model
      Throws:
      IOException - when the file cannot be read
      ContractModelException - when it is not a bundled OpenAPI 3 contract; the message starts with the file's path
    • parse

      public static ContractModel parse(Path openapi, Path asyncapi) throws IOException
      Parses a contract's two documents into one model.

      A specification library shares fragments between them: an event payload references the schema of a username the HTTP responses use, so that a username means the same thing either way. Both documents are therefore read into one model, keyed by fragment, and a fragment they share is one component of it -- which is what makes it one generated class rather than two of the same name.

      Parameters:
      openapi - the OpenAPI document
      asyncapi - the AsyncAPI document, or null when the contract has none
      Returns:
      the model
      Throws:
      IOException - when a file cannot be read
      ContractModelException - when a document is not what it claims to be
    • parse

      public static ContractModel parse(String text, String source)
      Parses a contract's text.
      Parameters:
      text - the contract, as YAML or JSON
      source - what to call the contract in error messages
      Returns:
      the model
      Throws:
      ContractModelException - when it is not a bundled OpenAPI 3 contract; the message starts with source