> ## Documentation Index
> Fetch the complete documentation index at: https://os.inttegro.dev/simile/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAPI authoring standard

> Use OpenAPI as the complete HTTP contract and HCL as an optional behavior overlay.

When OpenAPI is selected as the service's contract source, OpenAPI describes the complete public
HTTP contract. HCL describes selected observable behavior that does not belong in that contract.
Smithy and semantic TypeScript are equally supported alternatives; see
[Contract sources and HCL](https://os.inttegro.dev/simile/contract-sources-and-hcl.md) before choosing a format.

The relationship is asymmetric: the selected contract is required and independently executable;
HCL is optional and must agree with it. This page covers the OpenAPI form of that model.

```mermaid theme={null}
flowchart TD
  OpenAPI[OpenAPI\nmethods, paths, schemas, responses, webhooks] --> Compiler
  HCL[Optional HCL\noutcomes, scenarios, effects, emissions] --> Compiler
  Compiler --> Check{Do both sources agree?}
  Check -->|yes| Artifact[Compiled service]
  Check -->|no| Failure[Compilation error]
```

## What OpenAPI owns

OpenAPI is the authority for:

* HTTP methods and paths;
* request body presence, media types, and schemas;
* response statuses, media types, and schemas;
* public examples and tags;
* callback and top-level webhook wire contracts; and
* `operationId`, when a provider wants HCL to target an operation.

With only OpenAPI, Simile can run every normalized operation, validate a supported request body,
and synthesize a response permitted by the contract. This baseline is intentionally useful: a
provider should not have to rewrite its API before developers can emulate it.

## What HCL adds

HCL can:

* select a status already declared by the operation;
* publish exact, schema-checked named outcomes;
* select outcomes from public request values;
* group outcomes into opaque test scenarios;
* map Simile's protocol-error categories to declared service responses; and
* declare backends, transactional consequences, and post-response work;
* attach one or more webhook occurrences to a committed effect; and
* supply a minimal webhook contract only when the public API source omits it.

HCL cannot add a route, replace a request schema, invent a response status, or contradict OpenAPI.
It targets an operation by its exact `operationId`, which is why an operation needs an ID only when
HCL refers to it.

## A minimal overlay

Suppose OpenAPI already declares `POST /orders`, `operationId: createOrder`, and a `201` response.
The provider can choose that response and declare observable follow-up work:

```hcl theme={null}
backend "queue" "orders" {}

async "dispatch_order" {
  action "queue.orders" "publish" {
    body = response.order
  }
}

behavior "createOrder" {
  response { status = 201 }
}

effect "commit_order" {
  operations = ["createOrder"]
  async      = ["dispatch_order"]
}
```

The compiler verifies that `createOrder` exists, `201` is declared, and the backend reference
resolves. `behavior` selects the public HTTP result, `effect` owns its synchronous consequences,
and `async` owns work dispatched outside the response-critical path. The service supervisor applies
this compiled plan without reopening HCL.

## Exact outcomes without private rules

OpenAPI examples are the lowest-maintenance source of exact output. If a reusable failure family
or scenario needs more control, HCL can provide a body that is checked against the selected
OpenAPI response schema:

```hcl theme={null}
error_set "payment_errors" {
  outcome "card_declined" {
    status       = 402
    content_type = "application/json"
    body = {
      error = {
        code    = "card_declined"
        message = "The payment method was declined"
      }
    }
  }
}

behavior "createPayment" {
  error_sets = ["payment_errors"]
}

scenario "payment_declined" {
  select "createPayment" {
    outcome = "card_declined"
  }
}
```

The scenario exposes the result a tester needs without embedding the provider's private decline
decision. That distinction is essential because distributed HCL is inspectable.

## Why not put everything in HCL

A second full API language would create drift. Providers would have to maintain methods, paths,
schemas, and examples twice, while ordinary OpenAPI tooling could not see the emulator's contract.
Keeping HCL additive makes source ownership clear and allows OpenAPI-only services to remain
first-class.

The same boundary applies to webhooks. OpenAPI owns a reusable outbound method and payload schema.
HCL owns when an operation emits that message, how its body is projected from public request or
response data, and any explicit causal dependencies between sibling occurrences. See
[Webhook delivery](https://os.inttegro.dev/simile/webhook-delivery.md) for the complete model.

The complete block grammar, value types, defaults, and name-resolution rules are defined in the
[Simile HCL language specification](https://os.inttegro.dev/simile/hcl-language-specification.md). Use the
[HCL glossary](https://os.inttegro.dev/simile/hcl-glossary.md) when a term such as outcome, scenario, fault, or effect needs a
precise definition.

When ordinary OpenAPI Schema cannot express a public relationship between fields, Simile provides
the executable `x-simile-constraints` extension. See the
[OpenAPI extension reference](https://os.inttegro.dev/simile/openapi-extensions.md) for its clause glossary and authoring rules.

## Why not infer behavior from route names

`POST /orders` suggests creation to a human, but it does not prove what is stored, what identity is
assigned, or what happens later. Simile refuses to turn naming conventions into state or effect
semantics. Approximation is permitted only in bounded payload generation heuristics, where it is
reported and never becomes a validation rule.

Continue with [Outcome fidelity](https://os.inttegro.dev/simile/outcome-fidelity.md) for response selection or
[Dependencies and effects](https://os.inttegro.dev/simile/dependencies-and-effects.md) for backend declarations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.