What is @orval/core?
@orval/core is a powerful tool for generating TypeScript clients from OpenAPI (Swagger) specifications. It helps streamline the process of creating API clients by automating the generation of TypeScript types and functions based on the OpenAPI definitions.
What are @orval/core's main functionalities?
Generate TypeScript API Clients
This feature allows you to generate TypeScript API clients from an OpenAPI specification file. The generated clients can be configured to use different HTTP clients like Axios.
const orval = require('@orval/core');
orval.generate({
input: './path/to/openapi.yaml',
output: './path/to/output',
client: 'axios'
});
Custom Templates
You can provide custom templates to tailor the generated code to your specific needs. This allows for greater flexibility and customization in how the API clients are generated.
const orval = require('@orval/core');
orval.generate({
input: './path/to/openapi.yaml',
output: './path/to/output',
client: 'axios',
templates: './path/to/custom/templates'
});
Mock Server Generation
This feature enables the generation of a mock server based on the OpenAPI specification. It can be useful for testing and development purposes when the actual API is not yet available.
const orval = require('@orval/core');
orval.generate({
input: './path/to/openapi.yaml',
output: './path/to/output',
mock: true
});
Other packages similar to @orval/core
openapi-generator
OpenAPI Generator is a comprehensive tool that supports the generation of API clients, server stubs, and API documentation from OpenAPI specifications. It offers a wide range of language and framework support, making it a versatile alternative to @orval/core.
swagger-codegen
Swagger Codegen is another popular tool for generating API clients, server stubs, and API documentation from OpenAPI (Swagger) specifications. It has a large community and extensive support for various languages and frameworks, similar to OpenAPI Generator.
typescript-fetch
typescript-fetch is a generator for TypeScript clients using the Fetch API. It is more lightweight compared to @orval/core and focuses specifically on generating TypeScript clients that use the Fetch API for making HTTP requests.
Visit orval.dev for docs, guides, API and beer!
Code Generation
orval
is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml
or json
formats.
Generate
, valid
, cache
and mock
in your React, Vue, Svelte and Angular applications all with your OpenAPI specification.
Samples
You can find below some samples