Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c1ccd43
test: add snapshot test pinning current generate output
Arkptz May 27, 2026
5e7f1aa
feat: add tag_rules module with regex-based tag matching
Arkptz May 27, 2026
b970591
feat: add operation_id module with camelCase derivation and collision…
Arkptz May 27, 2026
e44b0bb
feat(cli): add operationId and tag strategy CLI flags
Arkptz May 27, 2026
73bfb41
feat: add envelope module for discriminator-based response splitting
Arkptz May 27, 2026
3e2ee39
feat(generate): integrate tag rules strategy into builder
Arkptz May 27, 2026
5607d8a
feat(cli): add envelope detection CLI flags
Arkptz May 27, 2026
44ed4ae
feat(generate): integrate operationId strategy into builder
Arkptz May 27, 2026
67668ed
feat(generate): integrate envelope detection into build()
Arkptz May 27, 2026
c06fee0
fix(output): sort maps for deterministic YAML output
Arkptz May 27, 2026
1596285
test(integration): add end-to-end test for operationId, tags, and env…
Arkptz May 27, 2026
e04e083
docs: document operationId, tags, and envelope features
Arkptz May 27, 2026
efd7c8f
fix(test): normalize CRLF in snapshot comparison, add .gitattributes …
Arkptz May 28, 2026
2d6ce37
fix(envelope): merge all error bodies in infer_api_error, not just first
Arkptz May 28, 2026
eb3ffc9
fix(envelope): pin discriminator field to boolean enum:[false] in Api…
Arkptz May 28, 2026
d339fe2
fix(cli): stop splitting --redact-patterns on comma, fail invalid reg…
Arkptz May 28, 2026
3b3769c
docs(changelog): add bugfix entries from MEXC integration testing
Arkptz May 28, 2026
708a32d
docs: update --redact-patterns usage — one regex per flag, no comma s…
Arkptz May 28, 2026
582b9d7
fix(cli): show correct value name and help text for --redact-patterns
Arkptz May 28, 2026
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Normalize line endings to LF for all text files.
# This prevents CRLF/LF mismatches on Windows CI.
* text=auto eol=lf
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- *(generate)* add `--operation-id-strategy {none,path,template}` flag for stable operationId generation
- *(generate)* add `--operation-id-overrides <path>` for per-operation overrides via YAML
- *(generate)* add `--operation-id-template <string>` for custom operationId templates
- *(generate)* add `--tag-strategy {legacy,none,path-segment,rules}` flag
- *(generate)* add `--tag-rules <path>` for regex-based tag assignment from YAML
- *(generate)* add `--tag-segment-index <N>` to use a specific path segment as tag
- *(generate)* add `--envelope-discriminator <field>` for discriminator-based response splitting
- *(generate)* add `--envelope-error-shape <path>` for hand-supplied ApiError schema
- *(generate)* add `--envelope-success-component-suffix <string>` (default `Success`)
- *(output)* sort paths and component schemas alphabetically for deterministic YAML output

### Fixed

- *(envelope)* `infer_api_error` now merges all error bodies, not just the first — an outlier `msg: 0` no longer overrides thousands of `msg: "string"` samples
- *(envelope)* inferred `ApiError` schema now includes the discriminator field pinned with `enum: [false]`
- *(cli)* `--redact-patterns` no longer splits on `,` — regex quantifiers like `{32,}` now work correctly (pass multiple patterns via repeated flags)
- *(cli)* invalid `--redact-patterns` regex now hard-fails under `--strict` instead of silently skipping redaction

> Found and fixed by integration testing against a 3.1 GB MEXC capture in mexc-reversed-sdk.

## [0.6.0](https://github.com/Arkptz/mitm2openapi/compare/v0.5.2...v0.6.0) - 2026-05-27

### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Credit to [@alufers](https://github.com/alufers) for the original tool that pion
- **Auto-detection** — heuristic format detection from file content
- **Battle-tested** — integration tests against Swagger Petstore and OWASP crAPI with `oasdiff` verification
- **Cross-platform** — Linux, macOS, Windows pre-built binaries
- **operationId generation** — `--operation-id-strategy path` derives stable camelCase names (e.g. `getFairPrice`, `placeOrder`); override per-operation via YAML
- **Tag rules** — `--tag-rules file.yaml` assigns one tag per operation by regex; supports `path-segment`, `none`, and `legacy` modes
- **Envelope detection** — `--envelope-discriminator success` splits MEXC-style `{success: bool}` envelopes into `oneOf(SuccessSchema, ApiError)` with shared `components/schemas/ApiError`
- **Deterministic output** — paths and schemas sorted alphabetically for byte-stable diffs across runs

## Installation

Expand Down
11 changes: 10 additions & 1 deletion book/src/usage/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ mitm2openapi generate [OPTIONS] -i <INPUT> -t <TEMPLATES> -o <OUTPUT> -p <PREFIX
| `--report <PATH>` | | Write structured JSON processing report |
| `--skip-options` | off | Filter out OPTIONS requests from output |
| `--max-examples <N>` | `5` | Maximum examples per endpoint per status code |
| `--redact-patterns <PATTERNS>` | | Comma-separated regex patterns to redact from examples |
| `--redact-patterns <PATTERN>` | | Regex pattern to redact from examples (repeat flag for multiple) |
| `--redact-fields <FIELDS>` | | Comma-separated field names to redact from examples |
| `--operation-id-strategy <STRATEGY>` | `none` | Strategy for operationId generation: `none`, `path`, `template` |
| `--operation-id-template <STRING>` | | Template with `{method}` and `{path}` placeholders (requires `template`) |
| `--operation-id-overrides <PATH>` | | YAML file with per-operation overrides |
| `--tag-strategy <STRATEGY>` | `legacy` | Tag assignment strategy: `legacy`, `none`, `path-segment`, `rules` |
| `--tag-segment-index <N>` | | Path segment index for tag (requires `path-segment`) |
| `--tag-rules <PATH>` | | YAML rules file (auto-sets strategy to `rules`) |
| `--envelope-discriminator <FIELD>` | | JSON field name for discriminating success vs error |
| `--envelope-error-shape <PATH>` | | YAML file with hand-supplied ApiError schema |
| `--envelope-success-component-suffix <STRING>` | `Success` | Suffix for success component names |

## Common flag details

Expand Down
87 changes: 85 additions & 2 deletions book/src/usage/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ mitm2openapi generate \
-t templates.yaml \
-o openapi.yaml \
-p "https://api.example.com" \
--redact-patterns 'eyJ[\w-]+,sk-[a-zA-Z0-9]+' \
--redact-patterns 'eyJ[\w-]+' \
--redact-patterns 'sk-[a-zA-Z0-9]+' \
--redact-fields 'password,token,secret,authorization'
```

`--redact-patterns` accepts comma-separated regexes matched against string values.
`--redact-patterns` takes one regex per flag — repeat the flag for multiple patterns.
Regexes with quantifiers like `{32,}` work correctly.
`--redact-fields` accepts comma-separated field names whose values are replaced with
`"[REDACTED]"`.

Expand Down Expand Up @@ -251,3 +253,84 @@ mitm2openapi generate \
The generated `openapi.yaml` is a valid OpenAPI 3.0 document that can be opened in
[Swagger UI](https://github.com/swagger-api/swagger-ui), imported into Postman, or used
as a contract for API testing.

## Generating stable operationIds

Use `--operation-id-strategy path` to generate camelCase operationIds that openapi-generator converts to readable Rust method names:

```sh
mitm2openapi generate -i capture.har -t templates.yaml -o openapi.yaml -p https://api.example.com \
--operation-id-strategy path
```

This produces ids like `listUsers`, `getUser`, `createOrder`, `placeOrder`.

Override specific operations with a YAML file:

```yaml
# overrides.yaml
"GET /api/v1/contract/fair_price/{symbol}": getFairPrice
"POST /api/v1/private/order/place": placeOrder
```

```sh
mitm2openapi generate ... --operation-id-strategy path --operation-id-overrides overrides.yaml
```

## Organizing operations with tags

Tags group operations into modules (one Rust source file per tag in openapi-generator). Use regex-based rules:

```yaml
# tag-rules.yaml
rules:
- match: "^/api/v1/contract/"
tag: Contract
- match: "^/api/v1/private/"
tag: Private
default: Market
```

```sh
mitm2openapi generate ... --tag-rules tag-rules.yaml
```

Or use a fixed path segment as the tag:

```sh
mitm2openapi generate ... --tag-strategy path-segment --tag-segment-index 2
```

## MEXC-style envelope APIs

MEXC and similar exchange APIs always return HTTP 200 with a `success` boolean:

```json
{"success": true, "data": {"price": 42000.5}}
{"success": false, "code": 1, "message": "Invalid symbol"}
```

Use `--envelope-discriminator` to split captured bodies into typed schemas:

```sh
mitm2openapi generate \
-i capture.har -t templates.yaml -o openapi.yaml \
-p https://api.example.com \
--operation-id-strategy path \
--tag-rules tag-rules.yaml \
--envelope-discriminator success
```

The generated spec will include:

- A shared `components/schemas/ApiError` (inferred from all error bodies)
- Per-operation `{OperationId}Success` schemas
- `oneOf(SuccessSchema, ApiError)` for operations with mixed bodies

Supply your own error schema instead of inferring:

```sh
mitm2openapi generate ... \
--envelope-discriminator success \
--envelope-error-shape api-error.yaml
```
Loading
Loading