danielgtaylor / danielgtaylor/apisprout

Request/Response Mocks Defined As OpenAPI Examples

Open
#37 1 comment 1 reaction 0 assignees View on GitHub
enhancement help wanted
Dominant language
Go
Stars
719
Forks
70
PR merge metrics
No merged PRs in 30d

Description

**Issue**
A present Open API 3.0 Examples are returned randomly, the only differentiator is setting a Preferred HTTP response code:
```
// Choose a random example to return.
keys := make([]string, 0, len(mt.Examples))
for k := range mt.Examples {
keys = append(keys, k)
}
selected := keys[rand.Intn(len(keys))]
return mt.Examples[selected].Value.Value, nil
```

**Request**
It would be great if we could define which mocks to return also using path params, query strings, and even request/response payloads. See how Microcks uses this ability: http://microcks.github.io/using/openapi/

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the random selection logic shown for mt.Examples and the OpenAPI 3.0 example behavior described in the issue. Compare the requested path-parameter, query-string, and payload matching with the linked Microcks reference. Done means mocks can be selected deterministically from those request and response details instead of only by random choice.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.