Skip to content

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:

    1. Go to https://console.choreo.dev/, and sign in using your preferred method.
    2. Enter a unique organization name. For example, Stark Industries.
    3. Read and accept the privacy policy and terms of use.
    4. 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:

  1. Go to https://console.choreo.dev/ and sign in. This opens the project home page.
  2. If you already have one or more components in your project, click + Create. Otherwise, proceed to the next step.
  3. Click the Service card.
  4. 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.

  5. Click the GitHub tab.

  6. 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.

  7. Under Connect Your Repository, enter the following information:

    Field Value
    Organization Your GitHub account
    GitHub Repository choreo-samples
    Branch main
  8. Select Prism Mock as the buildpack.

  9. Select prism-mock-service as the Project Directory.
  10. 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:

  1. In the left navigation menu, click Build.
  2. 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:

  1. In the left navigation menu, click Deploy.
  2. On the Set Up card, click Configure & Deploy.
  3. 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.