Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/generators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ All available generators, across languages and inputs:

| **Inputs** | [`payloads`](./payloads.md) | [`parameters`](./parameters.md) | [`headers`](./headers.md) | [`types`](./types.md) | [`channels`](./channels.md) | [`client`](./client.md) | [`models`](./models.md) | [`custom`](./custom.md) |
|---|---|---|---|---|---|---|---|---|
| AsyncAPI | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| OpenAPI | ✔️ | ✔️ | ✔️ | ✔️ | ➗ | ➗ | ✔️ | ✔️ |
| AsyncAPI | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| OpenAPI | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ |
| JSON Schema | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |

| **Languages** | [`payloads`](./payloads.md) | [`parameters`](./parameters.md) | [`headers`](./headers.md) | [`types`](./types.md) | [`channels`](./channels.md) | [`client`](./client.md) | [`models`](./models.md) | [`custom`](./custom.md) |
|---|---|---|---|---|---|---|---|---|
| TypeScript | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| TypeScript | | | | | | | | |
33 changes: 31 additions & 2 deletions docs/generators/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default {
};
```

The `models` preset provides native integration with [AsyncAPI Modelina](https://modelina.org) for generating TypeScript models directly from AsyncAPI and OpenAPI documents. This generator exposes Modelina's full capabilities, giving you complete control over model generation.
The `models` preset provides native integration with [AsyncAPI Modelina](https://modelina.org) for generating TypeScript models directly from AsyncAPI, OpenAPI, and JSON Schema documents. This generator exposes Modelina's full capabilities, giving you complete control over model generation.

This is supported through the following inputs: `asyncapi`, `openapi`
This is supported through the following inputs: `asyncapi`, `openapi`, `jsonschema`

It supports the following languages; [`typescript`](#typescript)

Expand Down Expand Up @@ -161,6 +161,35 @@ export default {
};
```

### JSON Schema Input

```js
export default {
inputType: 'jsonschema',
inputPath: 'user-schema.json',
language: 'typescript',
generators: [
{
preset: 'models',
options: {
modelType: 'class',
enumType: 'enum'
},
renderers: [
{
class: {
additionalContent: ({ content, model }) => {
return `${content}\n\n // Custom validation method\n public validate(): boolean {\n return true;\n }`;
}
}
}
],
outputPath: './src/models'
}
]
};
```

## Languages

### TypeScript
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/payloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Each language has a set of constraints which means that some typed model types a

| | Circular models | Enums | Tuples | Arrays | Nested Arrays | Dictionaries | Json Serialization | Validation |
|---|---|---|---|---|---|---|---|---|
| **TypeScript** | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| **TypeScript** | | | | | | | | |

### TypeScript

Expand Down
14 changes: 7 additions & 7 deletions docs/inputs/asyncapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ There is a lot of overlap with existing tooling, however the idea is to form the

| **Presets** | AsyncAPI |
|---|---|
| [`payloads`](../generators/payloads.md) | ✔️ |
| [`parameters`](../generators/parameters.md) | ✔️ |
| [`headers`](../generators/headers.md) | ✔️ |
| [`types`](../generators/types.md) | ✔️ |
| [`channels`](../generators/channels.md) | ✔️ |
| [`client`](../generators/client.md) | ✔️ |
| [`custom`](../generators/custom.md) | ✔️ |
| [`payloads`](../generators/payloads.md) | |
| [`parameters`](../generators/parameters.md) | |
| [`headers`](../generators/headers.md) | |
| [`types`](../generators/types.md) | |
| [`channels`](../generators/channels.md) | |
| [`client`](../generators/client.md) | |
| [`custom`](../generators/custom.md) | |

## Basic AsyncAPI Document Structure

Expand Down
208 changes: 208 additions & 0 deletions docs/inputs/jsonschema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
---
sidebar_position: 3
---

# JSON Schema

JSON Schema input support enables you to generate TypeScript models directly from JSON Schema documents. This is particularly useful when you have standalone JSON Schema files that define your data structures.

## Supported Generators

The JSON Schema input type supports the following generators:

| Preset | JSON Schema |
|-----------|---------|
| [`models`](../generators/models.md) | ✅ |
| [`custom`](../generators/custom.md) | ✅ |

## Configuration

### Basic Configuration

```js
export default {
inputType: 'jsonschema',
inputPath: './user-schema.json',
language: 'typescript',
generators: [
{
preset: 'models',
outputPath: './src/models'
}
]
};
```

### Advanced Configuration with Modelina Options

```js
export default {
inputType: 'jsonschema',
inputPath: './complex-schema.json',
language: 'typescript',
generators: [
{
preset: 'models',
outputPath: './src/models',
options: {
modelType: 'class',
enumType: 'enum',
mapType: 'record',
rawPropertyNames: false,
useJavascriptReservedKeywords: false
},
renderers: [
{
class: {
property: ({ content, property }) => {
return `/** ${property.property.description || 'Auto-generated property'} */\n${content}`;
}
}
}
]
}
]
};
```

## Examples

### Simple User Schema

**Input: `user-schema.json`**
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "User",
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 0
}
},
"required": ["id", "name", "email"]
}
```

**Configuration: `codegen.mjs`**
```js
export default {
inputType: 'jsonschema',
inputPath: './user-schema.json',
language: 'typescript',
generators: [
{
preset: 'models',
outputPath: './src/models'
}
]
};
```

**Generated Output: `src/models/User.ts`**
```typescript
export class User {
private _id: string;
private _name: string;
private _email: string;
private _age?: number;

constructor(input: {
id: string,
name: string,
email: string,
age?: number,
}) {
this._id = input.id;
this._name = input.name;
this._email = input.email;
this._age = input.age;
}

get id(): string { return this._id; }
get name(): string { return this._name; }
get email(): string { return this._email; }
get age(): number | undefined { return this._age; }

public marshal(): string {
return JSON.stringify({
id: this.id,
name: this.name,
email: this.email,
age: this.age,
});
}

public static unmarshal(json: string): User {
const obj = JSON.parse(json);
return new User(obj);
}
}
```

### Complex Schema with Definitions

**Input: `complex-schema.json`**
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"zipCode": { "type": "string" }
},
"required": ["street", "city", "zipCode"]
}
},
"type": "object",
"properties": {
"person": {
"type": "object",
"properties": {
"name": { "type": "string" },
"address": { "$ref": "#/definitions/Address" }
},
"required": ["name"]
}
}
}
```

This will generate both `Person` and `Address` classes with proper type relationships.

## File Format Support

### JSON Format
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"example": { "type": "string" }
}
}
```

### YAML Format
```yaml
$schema: "http://json-schema.org/draft-07/schema#"
type: object
properties:
example:
type: string
```
14 changes: 7 additions & 7 deletions docs/inputs/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Input support; `openapi`

| **Presets** | OpenAPI |
|---|---|
| [`payloads`](../generators/payloads.md) | ✔️ |
| [`parameters`](../generators/parameters.md) | ✔️ |
| [`headers`](../generators/headers.md) | ✔️ |
| [`types`](../generators/types.md) | ✔️ |
| [`channels`](../generators/channels.md) | |
| [`client`](../generators/client.md) | |
| [`custom`](../generators/custom.md) | ✔️ |
| [`payloads`](../generators/payloads.md) | |
| [`parameters`](../generators/parameters.md) | |
| [`headers`](../generators/headers.md) | |
| [`types`](../generators/types.md) | |
| [`channels`](../generators/channels.md) | |
| [`client`](../generators/client.md) | |
| [`custom`](../generators/custom.md) | |

## Basic Usage

Expand Down
2 changes: 1 addition & 1 deletion docs/protocols/amqp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_position: 99

| **Languages** | Publish exchange | Publish queue | Subscribe queue | Subscribe exchange |
|---|---|---|---|---|
| TypeScript | ✔️ | ✔️ | ✔️ | |
| TypeScript | | | | |

All of this is available through [AsyncAPI](../inputs/asyncapi.md).

Expand Down
2 changes: 1 addition & 1 deletion docs/protocols/eventsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_position: 99

| **Languages** | [client](#client) | [server](#server) |
|---|---|---|
| TypeScript | ✔️ | ✔️ |
| TypeScript | | |

All of this is available through [AsyncAPI](../inputs/asyncapi.md).

Expand Down
50 changes: 25 additions & 25 deletions docs/protocols/http_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ All of this is available through [AsyncAPI](../inputs/asyncapi.md). Require HTTP

| **Feature** | Is supported? |
|---|---|
| Download | |
| Upload | |
| Offset based Pagination | |
| Cursor based Pagination | |
| Page based Pagination | |
| Time based Pagination | |
| Keyset based Pagination | |
| Retry with backoff | |
| OAuth2 Authorization code | ✔️ |
| OAuth2 Implicit | ✔️ |
| OAuth2 password | ✔️ |
| OAuth2 Client Credentials | ✔️ |
| Username/password Authentication | ✔️ |
| Bearer Authentication | ✔️ |
| Basic Authentication | ✔️ |
| API Key Authentication | ✔️ |
| XML Based API | |
| JSON Based API | ✔️ |
| POST | ✔️ |
| GET | ✔️ |
| PATCH | ✔️ |
| DELETE | ✔️ |
| PUT | ✔️ |
| HEAD | ✔️ |
| OPTIONS | ✔️ |
| Download | |
| Upload | |
| Offset based Pagination | |
| Cursor based Pagination | |
| Page based Pagination | |
| Time based Pagination | |
| Keyset based Pagination | |
| Retry with backoff | |
| OAuth2 Authorization code | |
| OAuth2 Implicit | |
| OAuth2 password | |
| OAuth2 Client Credentials | |
| Username/password Authentication | |
| Bearer Authentication | |
| Basic Authentication | |
| API Key Authentication | |
| XML Based API | |
| JSON Based API | |
| POST | |
| GET | |
| PATCH | |
| DELETE | |
| PUT | |
| HEAD | |
| OPTIONS | |
Loading
Loading