OrvalOrval

Effect

Generate Effect schemas from OpenAPI

Generate Effect Schema schemas from your OpenAPI specification for runtime validation.

Configuration

Set the client option to effect:

orval.config.ts
import { defineConfig } from 'orval';

export default defineConfig({
  petstore: {
    output: {
      client: 'effect',
      mode: 'single',
      target: './src/api/schemas',
    },
    input: {
      target: './petstore.yaml',
    },
  },
});

Generated Output

Orval generates an Effect schema for each model in your OpenAPI specification:

import { Schema as S } from 'effect';

export const CreatePetsBody = S.Struct({
  id: S.Number,
  name: S.String,
  tag: S.optional(S.String),
});

Effect Version

Orval reads the effect version installed in your project and emits Effect 3 or Effect 4 Schema syntax to match. When no effect package is found, it emits Effect 4. Set override.effect.version to pin the target.

Usage

Decoding Data

import { Schema as S } from 'effect';
import { CreatePetsBody } from './src/api/schemas';

const pet = { id: 1, name: 'Buddy', tag: 'dog' };
const parsedPet = S.decodeUnknownSync(CreatePetsBody)(pet);
// => { id: 1, name: "Buddy", tag: "dog" }

Type Inference

import { Schema as S } from 'effect';
import { CreatePetsBody } from './src/api/schemas';

type Pet = S.Schema.Type<typeof CreatePetsBody>;

const pet: Pet = { id: 1, name: 'Buddy', tag: 'dog' };

Safe Decoding

import { Exit, Schema as S } from 'effect';

const result = S.decodeUnknownExit(CreatePetsBody)(unknownData);

if (Exit.isSuccess(result)) {
  console.log(result.value);
} else {
  console.error(result.cause);
}

With Effect 3, use S.decodeUnknownEither and Either.isRight instead.

Combining with HTTP Clients

See the Client with Effect guide for using Effect schemas with React Query, SWR, or other HTTP clients.

On this page