Smart Mock is Apidog's automatic mock data generation feature. It creates realistic mock responses based on your API specification without requiring any configuration. Simply define your API spec, and Apidog will intelligently generate appropriate mock data for you.In this article, we'll learn how to use Smart Mock with the Pet Store API.
1. What Is Smart Mock?#
Smart Mock automatically generates mock data by analyzing your API specification. It recognizes common field names and generates appropriate dataโno manual configuration needed.Why Use Smart Mock?#
Works immediately: No setup requiredโjust define your API spec
Intelligent: Automatically recognizes field names and generates realistic data
Always valid: Respects your JSON Schema to ensure valid responses
2. How to Use Smart Mock#
Let's see how Smart Mock works with the Pet Store API:Step 1: Open the Endpoint#
1.
Open the Pet Store API in your Apidog project
2.
Navigate to an endpoint (e.g., GET /pets/{id})
3.
Make sure the endpoint has a response schema defined
Step 2: Access the Mock Tab#
1.
Click the "Mock" tab (or switch to DEBUG mode and find the Mock section)
2.
You'll see the mock URL for this endpoint
Step 3: Copy and Use the Mock URL#
1.
Click the mock URL to copy it
2.
The URL will look something like: http://127.0.0.1:4523/m1/{project-id}/0/pets/{id}
3.
Paste it in your browser or use it in your application
4.
Replace path parameters (like {id}) with actual values
Step 4: View the Mock Response#
The mock server will return Smart Mock-generated data. For example:{
"id": "pet_123",
"name": "Buddy",
"species": "DOG",
"breed": "Golden Retriever",
"ageMonths": 24,
"status": "AVAILABLE",
"adoptionFee": 150.00
}
Each time you refresh or make a new request, Smart Mock will generate new data while respecting your schema constraints.
3. How Smart Mock Generates Data#
Smart Mock uses intelligent name matching to generate appropriate data. It recognizes common field names and generates realistic values.Automatic Name Recognition#
Smart Mock automatically recognizes common field names:name, firstName, lastName โ Generates person names
email โ Generates email addresses
phone, phoneNumber โ Generates phone numbers
address, street โ Generates addresses
price, amount, cost โ Generates monetary values
id, userId โ Generates IDs
createdAt, updatedAt โ Generates timestamps
Example: Pet Store API#
In the Pet Store API's GET /pets/{id} response:name โ Smart Mock generates pet names like "Buddy" or "Luna"
species โ Generates species values like "DOG" or "CAT"
breed โ Generates breed names like "Golden Retriever"
ageMonths โ Generates age values
status โ Generates status values like "AVAILABLE"
If a field name doesn't match any pattern, Smart Mock generates a default value based on the field type (string, number, boolean, etc.).
4. Customizing Specific Fields#
Sometimes you want to control specific fields while letting Smart Mock handle the rest. You can do this using the mock field in your response schema.Setting Fixed Values#
1.
Open your endpoint in the Edit tab
2.
Navigate to the Response section
3.
Find the property you want to customize
4.
Enter a value in the Mock field
Example: For the status field, you might set it to "AVAILABLE" to always return this status.Using Dynamic Values#
You can also use Faker.js expressions to generate dynamic data:{{$person.fullName}} โ Generates random full names
{{$internet.email}} โ Generates random email addresses
{{$number.int(min=1,max=100)}} โ Generates numbers in a range
Example: For the name field, you could use {{$person.firstName}} to generate random first names.When you set a value in the mock field, it overrides Smart Mock's automatic generation for that specific field.
5. JSON Schema Constraints#
Smart Mock respects all constraints defined in your JSON Schema. This ensures the generated data is always valid.Common Constraints#
Enum values: If a field has specific allowed values, Smart Mock will pick one of themExample: If status has enum ["AVAILABLE", "PENDING", "ADOPTED"], Smart Mock returns one of these values
Min/Max values: Number fields with min/max constraints generate values within those boundariesExample: If ageMonths has minimum: 1 and maximum: 240, Smart Mock generates ages between 1 and 240
String length: String fields with length constraints generate strings within those limits
Array size: Array fields with item count constraints generate arrays with the appropriate number of elements
6. Key Takeaways#
Smart Mock automatically generates mock data from your API specification
Zero configuration requiredโworks immediately after defining your API spec
Intelligent name matching recognizes common field names and generates appropriate data
Mock field allows you to customize specific fields while using Smart Mock for the rest
JSON Schema constraints ensure all generated data is valid
Easy to useโjust copy the mock URL and start using it
Smart Mock makes it easy to get started with API mocking. Simply define your API specification, and Apidog will generate realistic mock data automatically. In the next article, we'll learn about Mock Expectationsโhow to create custom mock responses with conditions. Modified atย 2025-12-25 09:42:57