Expose a Prism-Based Mock Server Using an OpenAPI Specification¶
Choreo supports deploying Prism-based mock servers using OpenAPI specifications. With the Choreo Prism mock service component, you can serve multiple mock servers, each based on a different OpenAPI specification, as separate endpoints.
By default, these mock servers serve static content generated from the examples in the configured OpenAPI Specification (OAS).
Prerequisites¶
Before you try out this guide, complete the following:
-
If you are signing in to the Choreo Console for the first time, create an organization as follows:
- Go to https://console.choreo.dev/, and sign in using your preferred method.
- Enter a unique organization name. For example,
Stark Industries
. - Read and accept the privacy policy and terms of use.
- Click Create.
This creates the organization and opens the Project Home page of the default project created for you.
-
Fork the Choreo samples repository, which contains the Prism mock service artifacts for this guide.
Step 1: Create a Prism mock service component¶
To create a Prism mock service component, follow these steps:
- Go to https://console.choreo.dev/ and sign in. This opens the project home page.
- If you already have one or more components in your project, click + Create. Otherwise, proceed to the next step.
- Click the Service card.
-
Enter a display name, a unique name, and a description for the service component.
Info
In the Component Name field, you must specify a name to uniquely identify the component in various contexts. The value is editable only at the time you create the component. You cannot change the name after you create the component.
-
Click the GitHub tab.
-
To allow Choreo to connect to your GitHub account, click Authorize with GitHub. If you have not already connected your GitHub repository to Choreo, enter your GitHub credentials and select the repository you created in the prerequisites section to install the Choreo GitHub App.
Alternatively, you can paste the Choreo samples repository URL in the Provide Repository URL field to connect to it without requiring authorization from the Choreo Apps GitHub application. However, authorizing the repository with the Choreo GitHub App is necessary if you want to enable Auto Deploy for the component.
Note
The Choreo GitHub App requires the following permissions:
- Read and write access to code and pull requests.
- Read access to issues and metadata.
You can revoke access if you do not want Choreo to have access to your GitHub account. However, write access is exclusively utilized for sending pull requests to a user repository. Choreo will not directly push any changes to a repository.
-
Under Connect Your Repository, enter the following information:
Field Value Organization Your GitHub account GitHub Repository choreo-samples
Branch main
-
Select Prism Mock as the buildpack.
- Select
prism-mock-service
as the Project Directory. - Click Create. This creates the component and takes you to the Overview page of the component.
Step 2: Build and deploy the component¶
Now that you have successfully created the Prism mock service, it's time to build and deploy it.
Step 2.1: Build¶
To build the service, follow these steps:
- In the left navigation menu, click Build.
-
On the Build page, click Build Latest. This builds the service from the latest commit.
Note
Building the service component may take a while. You can track the progress via the logs in the Build Details pane. Once the build process is complete, the build status changes to Success.
Step 2.2: Deploy¶
To deploy the service, follow these steps:
- In the left navigation menu, click Deploy.
- On the Set Up card, click Configure & Deploy.
-
Review the Endpoint Details and click Deploy.
Note
Deploying the service component may take a while. Once deployed, the Development environment card indicates the Deployment Status as Active.
Once you have successfully deployed the service, you can test, manage, and observe it like any other component type in Choreo.
Serve dynamic content¶
The Prism mock service can serve dynamic content according to the schema definitions in the OpenAPI specification. To use the Prism mock service with dynamic content, clients must add the prefer:dynamic=true
header in the request.
To generate meaningful dynamic responses, you can use the x-faker
attribute in schema definitions of the OpenAPI specification. For more information on dynamically generated responses with the x-faker
attribute, see the Prism documentation.