Skip to content

Commit eae483a

Browse files
authored
Merge pull request #286 from mendixlabs/merge/268-openapi-import
feat: import consumed REST client from OpenAPI 3.0 spec
2 parents 0eb2ad1 + 3c92104 commit eae483a

36 files changed

Lines changed: 9903 additions & 8615 deletions

.claude/skills/mendix/rest-client.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,60 @@
22

33
Use this skill when integrating with external REST APIs from Mendix.
44

5-
## Two Approaches
5+
## Three Approaches
66

7-
Mendix offers two ways to call REST APIs from microflows. Choose based on the use case:
7+
Mendix offers three ways to call REST APIs from microflows. Choose based on the use case:
88

99
| Approach | When to Use | Artifacts |
1010
|----------|-------------|-----------|
11-
| **REST Client + SEND REST REQUEST** | Structured APIs with multiple operations, reusable across microflows, Studio Pro UI support | REST client document + microflow |
11+
| **OpenAPI import** | API has an OpenAPI 3.0 spec — auto-generate from the spec | REST client document generated in one command |
12+
| **REST Client (manual)** | No spec available, or need fine-grained control | REST client document + microflow |
1213
| **REST CALL (inline)** | One-off calls, quick prototyping, dynamic URLs, low-level HTTP control | Microflow only |
1314

14-
Both can be combined with **Data Transformers** (Mendix 11.9+) and **Import/Export Mappings** to map between JSON and entities.
15+
Both REST Client approaches can be combined with **Data Transformers** (Mendix 11.9+) and **Import/Export Mappings** to map between JSON and entities.
1516

1617
---
1718

18-
## Approach 1: REST Client (Recommended)
19+
## Approach 0: OpenAPI Import (Fastest)
20+
21+
If the API has an OpenAPI 3.0 spec (JSON or YAML), generate the REST client in one command:
22+
23+
```sql
24+
-- From a local file (relative to the .mpr file)
25+
create or modify rest client CapitalModule.CapitalAPI (
26+
OpenAPI: 'specs/capital.json'
27+
);
28+
29+
-- From a URL
30+
create or modify rest client PetStoreModule.PetStoreAPI (
31+
OpenAPI: 'https://petstore3.swagger.io/api/v3/openapi.json'
32+
);
33+
34+
-- Override the base URL (replaces servers[0].url from the spec)
35+
create or modify rest client PetStoreModule.PetStoreStaging (
36+
OpenAPI: 'https://petstore3.swagger.io/api/v3/openapi.json',
37+
BaseUrl: 'https://staging.petstore.example.com/api/v3'
38+
);
39+
```
40+
41+
This generates:
42+
- All operations with correct HTTP method, path, parameters, headers, body, and response type
43+
- Resource groups based on OpenAPI `tags`
44+
- Basic auth if the spec declares it at the top level
45+
- The spec stored inside the document for Studio Pro parity
46+
47+
`BaseUrl` is optional. When omitted, `servers[0].url` from the spec is used. When provided, it overrides that value — useful when the spec points at production but you need to import against staging or a different version.
48+
49+
**Preview without writing:**
50+
```sql
51+
describe contract operation from openapi 'specs/capital.json';
52+
```
53+
54+
**After import:** the REST client is ready to use with `SEND REST REQUEST`. No manual operation definition needed.
55+
56+
---
57+
58+
## Approach 1: REST Client (Manual)
1959

2060
Define the API once as a REST client document, then call its operations from microflows.
2161

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1515
- **Shared URL utilities**`internal/pathutil` package with `NormalizeURL()`, `URIToPath()`, and `PathFromURL()` for reuse across components
1616
- **@anchor sequence flow annotation** — optional `@anchor(from: X, to: Y)` annotation on microflow statements that pins the side of the activity box a SequenceFlow attaches to (top / right / bottom / left). Split (`if`) statements support the combined form `@anchor(to: X, true: (from: ..., to: ...), false: (from: ..., to: ...))` so the incoming and per-branch outgoing anchors survive describe → exec round-trip. When omitted, the builder derives the anchor from the visual flow direction (existing behaviour is unchanged). Keeps the flow diagram stable across patches when an agent-generated microflow is applied back to a project
1717
- **@anchor loop form**`LOOP`/`WHILE` statements accept `@anchor(iterator: (...), tail: (...))` in the grammar so authoring tools can forward-propagate the intent. Today the builder deliberately does not translate those into SequenceFlows: Studio Pro rejects edges between a `LoopedActivity` and its body statements with CE0709 ("Sequence flow is not accepted by origin or destination"), since the iterator icon is drawn implicitly from the loop geometry. Reserving the grammar slot keeps scripts forward-compatible with any future Mendix capability
18+
- **OpenAPI import for REST clients**`CREATE REST CLIENT` now accepts `OpenAPI: 'path/or/url'` to auto-generate a consumed REST service document from an OpenAPI 3.0 spec (JSON or YAML); operations, path/query parameters, request bodies, response types, resource groups (tags), and Basic auth are derived automatically; spec content is stored in `OpenApiFile` for Studio Pro parity (#207)
19+
- **DESCRIBE CONTRACT OPERATION FROM OPENAPI** — Preview what would be generated from an OpenAPI spec without writing to the project
1820

1921
### Changed
2022

cmd/mxcli/lsp_completions_gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)