Skip to content

Commit 3228cf6

Browse files
fix: replacement value evaluation (#1950)
1 parent ebed550 commit 3228cf6

File tree

17 files changed

+1249
-405
lines changed

17 files changed

+1249
-405
lines changed

__tests__/respect/inputs-with-cli-and-env/__snapshots__/inputs-with-cli-and-env.test.ts.snap

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,74 @@ exports[`should use inputs from CLI and env 1`] = `
109109
    ✓ schema check
110110
111111
112+
✓ GET /museum-hours - step test-default-input
113+
114+
    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/museum-hours?organizationId=acme-inc
115+
    Request Headers:
116+
      accept: application/json, application/problem+json
117+
      authorization: Basic Og==
118+
119+
120+
    Response status code: 200
121+
    Response time: <test> ms
122+
    Response Body:
123+
      [
124+
       {
125+
       "date": "2023-09-11",
126+
       "timeOpen": "09:00",
127+
       "timeClose": "18:00"
128+
       },
129+
       {
130+
       "date": "2023-09-12",
131+
       "timeOpen": "09:00",
132+
       "timeClose": "18:00"
133+
       },
134+
       {
135+
       "date": "2023-09-13",
136+
       "timeOpen": "09:00",
137+
       "timeClose": "18:00"
138+
       },
139+
       {
140+
       "date": "2023-09-14",
141+
       "timeOpen": "09:00",
142+
       "timeClose": "18:00"
143+
       },
144+
       {
145+
       "date": "2023-09-15",
146+
       "timeOpen": "10:00",
147+
       "timeClose": "16:00"
148+
       },
149+
       {
150+
       "date": "2023-09-18",
151+
       "timeOpen": "09:00",
152+
       "timeClose": "18:00"
153+
       },
154+
       {
155+
       "date": "2023-09-19",
156+
       "timeOpen": "09:00",
157+
       "timeClose": "18:00"
158+
       },
159+
       {
160+
       "date": "2023-09-20",
161+
       "timeOpen": "09:00",
162+
       "timeClose": "18:00"
163+
       },
164+
       {
165+
       "date": "2023-09-21",
166+
       "timeOpen": "09:00",
167+
       "timeClose": "18:00"
168+
       },
169+
       {
170+
       "date": "2023-09-22",
171+
       "timeOpen": "10:00",
172+
       "timeClose": "16:00"
173+
       }
174+
      ]
175+
176+
    ✓ status code check - $statusCode in [200, 400, 404]
177+
    ✓ content-type check
178+
    ✓ schema check
179+
112180
────────────────────────────────────────────────────────────────────────────────
113181
114182
Running workflow inputs-with-cli-and-env.yaml / events-crud
@@ -162,8 +230,8 @@ exports[`should use inputs from CLI and env 1`] = `
162230
  Summary for inputs-with-cli-and-env.yaml
163231
  
164232
  Workflows: 2 passed, 2 total
165-
  Steps: 3 passed, 3 total
166-
  Checks: 13 passed, 13 total
233+
  Steps: 4 passed, 4 total
234+
  Checks: 16 passed, 16 total
167235
  Time: <test>ms
168236
169237

__tests__/respect/inputs-with-cli-and-env/inputs-with-cli-and-env.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ workflows:
2323
properties:
2424
AUTH_TOKEN:
2525
type: string
26+
organizationId:
27+
type: string
28+
default: acme-inc
2629
description: >-
2730
This workflow demonstrates how to get the museum opening hours and buy tickets.
2831
parameters:
@@ -44,6 +47,12 @@ workflows:
4447
workflowId: $sourceDescriptions.tickets-from-museum-api.workflows.get-museum-tickets
4548
outputs:
4649
ticketId: $outputs.ticketId
50+
- stepId: test-default-input
51+
operationId: museum-api.getMuseumHours
52+
parameters:
53+
- in: query
54+
name: organizationId
55+
value: $inputs.env.organizationId
4756
- workflowId: events-crud
4857
inputs:
4958
type: object

__tests__/respect/local-json-server/local-json-server.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
import { spawn } from 'child_process';
22
import { getParams, getCommandOutput } from '../utils';
33
import { join } from 'path';
4+
import * as fs from 'fs';
5+
6+
const dbPath = join(__dirname, 'fake-db.json');
47

58
describe('local-json-server', () => {
69
let serverProcess: any;
10+
let originalData: string | undefined;
711

812
beforeAll(async () => {
913
// Start json-server
1014
serverProcess = spawn('npm', ['run', 'json-server'], { detached: true });
15+
16+
// Store original state of fake-bd.json
17+
originalData = fs.readFileSync(dbPath, 'utf8');
1118
});
1219

1320
afterAll(() => {
1421
// Kill the process group to ensure child processes are cleaned up
1522
process.kill(-serverProcess.pid);
23+
24+
// Restore original state
25+
if (originalData) {
26+
fs.writeFileSync(dbPath, originalData);
27+
}
1628
});
1729

1830
test('local-json-server test case', () => {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should replace values in the request body 1`] = `
4+
"────────────────────────────────────────────────────────────────────────────────
5+
6+
Running workflow replacements.arazzo.yaml / replacements
7+
8+
✓ GET /special-events/{eventId} - step first-step
9+
10+
    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/special-events/dad4bce8-f5cb-4078-a211-995864315e39
11+
    Request Headers:
12+
      accept: application/json, application/problem+json
13+
      authorization: Basic Og==
14+
15+
16+
    Response status code: 200
17+
    Response time: <test> ms
18+
    Response Body:
19+
      {
20+
       "eventId": "6744a0da-4121-49cd-8479-f8cc20526495",
21+
       "name": "Time Traveler Tea Party",
22+
       "location": "Temporal Tearoom",
23+
       "eventDescription": "Sip tea with important historical figures.",
24+
       "dates": [
25+
       "2023-11-18",
26+
       "2023-11-25",
27+
       "2023-12-02"
28+
       ],
29+
       "price": 60
30+
      }
31+
32+
    ✓ status code check - $statusCode in [200, 400, 404]
33+
    ✓ content-type check
34+
    ✓ schema check
35+
36+
✓ POST /tickets - step step-with-json-replacements
37+
38+
    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/tickets
39+
    Request Headers:
40+
      content-type: application/json
41+
      accept: application/json, application/problem+json
42+
      authorization: Basic Og==
43+
    Request Body:
44+
      {
45+
       "eventId": "my-custom-event-id",
46+
       "name": "Time Traveler Tea Party",
47+
       "location": "Time Traveler Tea Party",
48+
       "eventDescription": "Sip tea with important historical figures.",
49+
       "dates": [
50+
       "2025-01-01"
51+
       ],
52+
       "price": 60
53+
      }
54+
55+
56+
    Response status code: 400
57+
    Response time: <test> ms
58+
    Response Body:
59+
      {
60+
       "type": "object",
61+
       "title": "Error validating body. data must have required property 'ticketType', data must have required property 'ticketDate', data must have required property 'email', data/eventId must match format \\"uuid\\""
62+
      }
63+
64+
    ✓ status code check - $statusCode in [201, 400, 404]
65+
    ✓ content-type check
66+
    ✓ schema check
67+
68+
✓ PATCH /special-events/{eventId} - step step-with-form-urlencoded-replacements
69+
70+
    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/special-events/dad4bce8-f5cb-4078-a211-995864315e39
71+
    Request Headers:
72+
      content-type: application/x-www-form-urlencoded
73+
      accept: application/json, application/problem+json
74+
      authorization: Basic Og==
75+
    Request Body:
76+
      "name=Time+Traveler+Tea+Party&location=New+York"
77+
78+
79+
    Response status code: 400
80+
    Response time: <test> ms
81+
    Response Body:
82+
      {
83+
       "type": "object",
84+
       "title": "Media type \\"application/x-www-form-urlencoded\\" is not supported"
85+
      }
86+
87+
    ✓ status code check - $statusCode in [200, 400, 404]
88+
    ✓ content-type check
89+
    ✓ schema check
90+
91+
✓ PATCH /special-events/{eventId} - step step-with-form-urlencoded-replacements-2
92+
93+
    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/special-events/dad4bce8-f5cb-4078-a211-995864315e39
94+
    Request Headers:
95+
      content-type: application/x-www-form-urlencoded
96+
      accept: application/json, application/problem+json
97+
      authorization: Basic Og==
98+
    Request Body:
99+
      "name=Time+Traveler+Tea+Party&location=Jakarta"
100+
101+
102+
    Response status code: 400
103+
    Response time: <test> ms
104+
    Response Body:
105+
      {
106+
       "type": "object",
107+
       "title": "Media type \\"application/x-www-form-urlencoded\\" is not supported"
108+
      }
109+
110+
    ✓ status code check - $statusCode in [200, 400, 404]
111+
    ✓ content-type check
112+
    ✓ schema check
113+
114+
115+
  Summary for replacements.arazzo.yaml
116+
  
117+
  Workflows: 1 passed, 1 total
118+
  Steps: 4 passed, 4 total
119+
  Checks: 12 passed, 12 total
120+
  Time: <test>ms
121+
122+
123+
┌──────────────────────────────────────────────────────────────────┬────────────┬─────────┬─────────┬──────────┐
124+
│ Filename │ Workflows │ Passed │ Failed │ Warnings │
125+
├──────────────────────────────────────────────────────────────────┼────────────┼─────────┼─────────┼──────────┤
126+
│ ✓ replacements.arazzo.yaml │ 1 │ 1 │ - │ - │
127+
└──────────────────────────────────────────────────────────────────┴────────────┴─────────┴─────────┴──────────┘
128+
129+
130+
"
131+
`;

0 commit comments

Comments
 (0)