-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update use of OpenApi examples to allow developers to output the examples from the endpoints #749
Comments
Looks like there's another feature implied in your second example: that the context has access to the OpenAPI spec. That makes sense to me. It can be passed in the constructor of the Context class. |
Instead of return $.response[200].examples.namedExample1 In order to keep the fluent API, we may need to do: return $.response[200].example("namedExample1") The reason for that is it allows continue decorating the response after selecting its content: return $.response[200].example("namedExample1").header("some-header", "some-value") There are two parts to implementing this feature. The runtime part can be implementing by making a copy of this counterfact/src/server/response-builder.ts Lines 101 to 137 in b8d7ca5
Instead of using the The other part is the ResponseBuilderFactory type: counterfact/src/server/types.d.ts Lines 93 to 109 in f29e143
It will look a lot like |
Various discussion has happened around having Counterfact record/capture network sessions to capture sample JSON data responses that can be returned by default by the generated endpoints instead of
.random()
.After discussing it seems like a separate tool that converts a HAR file to OpenAPI is the best companion (such as https://github.com/jonluca/har-to-openapi). For the Counterfact side, presently, if an example is present, CF will pick one at random. This ticket asks for the ability to give access to the OpenApi examples so a developer can choose to use them as output or even use the examples within a context.
Example 1 (inside an endpoint TS file):
Example 2 (inside a Context):
and then in the context:
The text was updated successfully, but these errors were encountered: