Skip to content

feat: import consumed REST client from OpenAPI 3.0 spec#286

Merged
ako merged 7 commits intomainfrom
merge/268-openapi-import
Apr 23, 2026
Merged

feat: import consumed REST client from OpenAPI 3.0 spec#286
ako merged 7 commits intomainfrom
merge/268-openapi-import

Conversation

@ako
Copy link
Copy Markdown
Collaborator

@ako ako commented Apr 23, 2026

Rebased version of #268 (original PR by @khode-mx — original had merge conflicts against main).

Changes

Summary

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. DESCRIBE CONTRACT OPERATION FROM OPENAPI previews what would be generated without writing to the project.

Closes #207. Supersedes #268.

Co-authored-by: Dennis Kho dennis.kho@mendix.com
🤖 Generated with Claude Code

khode-mx and others added 7 commits April 23, 2026 17:36
Add `OpenAPI: 'path/or/url'` property to `CREATE REST CLIENT` that
auto-generates 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 all derived
from the spec. The spec content is stored in OpenApiFile for Studio Pro
parity. Also adds `DESCRIBE CONTRACT OPERATION FROM OPENAPI` for
previewing the import without writing to the project.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…OR MODIFY

- writer_rest.go: drop the else-branch that wrote OpenApiFile=nil for
  manually-created REST clients; Studio Pro omits this field entirely for
  non-spec services, so writing an explicit null can corrupt existing projects
- cmd_rest_clients.go: preserve the existing UnitID on CREATE OR MODIFY so
  any SEND REST REQUEST microflows that reference the service by ID remain
  valid after a re-import; applies to both the spec-driven and manual paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tizeIdent

- fetchSpecBytes: wrap resp.Body in io.LimitReader(10 MiB) before ReadAll
  to prevent memory exhaustion from oversized or malicious spec URLs
- sanitizeModuleName: add comment explaining intentional PascalCase vs
  snake_case difference relative to openapi.sanitizeIdent (service names
  vs operation names follow different Mendix naming conventions)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Apply go fmt to 7 syntax feature registry files (struct field alignment)
and cmd_odata.go (tabs vs spaces in fetchODataMetadata). These were
reformatted during the OpenAPI import session but not staged at commit time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…kill

Add BaseUrl override example and explanation to both
MDL_QUICK_REFERENCE.md and .claude/skills/mendix/rest-client.md.
The behavior (BaseUrl overrides servers[0].url from the spec) was
already implemented and tested but missing from both doc locations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ests

- cmd_rest_clients.go: propagate ListConsumedRestServices error in both
  createRestClient and createRestClientFromSpec instead of silently
  discarding it with _. A listing failure now returns an error rather
  than silently creating a duplicate on OR MODIFY.
- cmd_rest_openapi_mock_test.go: 6 new mock-based executor tests for
  the OpenAPI import path using an embedded httptest server (no network):
    - Create from spec (verifies name, BaseUrl, operations, OpenApiContent)
    - BaseUrl override (replaces servers[0].url)
    - OR MODIFY preserves existing UnitID
    - Duplicate without OR MODIFY returns error
    - ListConsumedRestServices error propagates
    - DESCRIBE CONTRACT OPERATION FROM OPENAPI previews MDL output

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ako ako merged commit eae483a into main Apr 23, 2026
6 of 8 checks passed
@github-actions
Copy link
Copy Markdown

AI Code Review

Moderate Issues

Missing Test Coverage

  • Missing doctype test examples: The PR adds new MDL syntax (CREATE REST CLIENT with OpenAPI property and DESCRIBE CONTRACT OPERATION FROM OPENAPI) but doesn't include corresponding test examples in mdl-examples/doctype-tests/. Per the checklist: "New executor commands should have MDL examples in mdl-examples/doctype-tests/" and "MDL syntax changes — any PR that adds or modifies MDL syntax must include working examples in mdl-examples/doctype-tests/".

Incomplete Full-Stack Verification

  • While the PR mentions regenerated parser files and passing tests, the visible diff doesn't show:
    • Grammar changes (MDLParser.g4/MDLLexer.g4)
    • AST node additions (mdl/ast/)
    • Visitor implementation (mdl/visitor/)
    • Executor handler (mdl/executor/)
    • Backend implementation (mdl/backend/mpr/)
    • DESCRIBE roundtrip verification (the DESCRIBE should output re-executable MDL)
    • VS Code extension updates (if new LSP capabilities were added beyond completions)

What Looks Good

Documentation Quality

  • Excellent documentation updates in .claude/skills/mendix/rest-client.md with clear examples and explanations
  • CHANGELOG.md properly documents the new feature
  • Examples show usage from local files, URLs, and with BaseUrl overrides
  • Includes preview capability via DESCRIBE CONTRACT OPERATION FROM OPENAPI

Syntax Compliance

  • Follows standard CRUD verbs (CREATE, DESCRIBE)
  • Reads as English: "create rest client OpenAPI: 'specs/capital.json'" is clear and understandable
  • Property format correctly uses colon separators: OpenAPI: 'path/or/url'
  • No keyword overloading - OPENAPI has one specific meaning
  • Consistent with existing MDL patterns for property definitions
  • Diff-friendly - adding the OpenAPI property produces a one-line diff in property lists

Code Consistency

  • LSP completions correctly updated to include OPENAPI keyword
  • Syntax feature definitions updated consistently across cmd/mxcli/syntax/ files
  • PR is properly scoped to a single feature (OpenAPI import for REST clients)
  • All tests pass per PR description (make build && make test)

Recommendation

Request changes to add the missing doctype test examples for the new MDL syntax before approval. Specifically:

  1. Add test examples in mdl-examples/doctype-tests/ showing:

    • CREATE REST CLIENT with OpenAPI property (local file)
    • CREATE REST CLIENT with OpenAPI property (URL)
    • CREATE REST CLIENT with OpenAPI property and BaseUrl override
    • DESCRIBE CONTRACT OPERATION FROM OPENAPI for preview functionality
  2. Verify and potentially add:

    • DESCRIBE roundtrip test showing the command outputs re-executable MDL
    • Any missing LSP capabilities beyond completions (if applicable)
    • VS Code extension updates if new LSP features were added

Once these test examples are added, the PR would be ready for approval as it otherwise follows all MDL syntax guidelines and maintains good documentation standards.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add OpenAPI contract import for Consumed Rest Services

2 participants