Skip to content

Commit

Permalink
fix(type-safe-api): mock data generation for recursive references
Browse files Browse the repository at this point in the history
The mock data generation library we were using previously stackoverflowed when recursive references
were used (which is perfectly valid in openapi). We replace this library with our own
implementation, which additionally better conforms to the spec by taking into account
min/max/pattern etc constraints.

Fixes #545
  • Loading branch information
cogwirrel committed Oct 12, 2023
1 parent 0eec5ef commit 1c23ac7
Show file tree
Hide file tree
Showing 16 changed files with 859 additions and 30 deletions.
20 changes: 20 additions & 0 deletions packages/pdk/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/pdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/type-safe-api/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/type-safe-api/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ install_packages() {
[email protected] \
[email protected] \
@redocly/[email protected] \
@7nohe/[email protected] \
[email protected] \
@faker-js/[email protected] \
@openapitools/[email protected] \
[email protected] \
@types/[email protected] \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ spec_path=''
output_path=''
locale='en'
max_array_length='3'
seed='1337'
while [[ "$#" -gt 0 ]]; do case $1 in
--spec-path) spec_path="$2"; shift;;
--output-path) output_path="$2"; shift;;
--locale) locale="$2"; shift;;
--max-array-length) max_array_length="$2"; shift;;
--seed) seed="$2"; shift;;
esac; shift; done

echo "Generating Mock Data..."
Expand All @@ -28,21 +30,26 @@ cd $tmp_dir

log "mock-data :: tmp_dir :: $tmp_dir"

# Copy the script directory into the temp directory
cp -r $script_dir/* .

# Install dependencies
install_packages

outdir="$working_dir/$output_path/mocks"

log "mock-data :: deleting outdir :: $outdir"
rm -rf $outdir
mkdir -p $outdir

# Generate
log "mock-data :: generate"
run_command openapi-json \
--input "$working_dir/$spec_path" \
--output "$working_dir/$output_path/mocks" \
--locale $locale \
--max-array-length $max_array_length
run_command ts-node generate-mock-data.ts \
--specPath="$working_dir/$spec_path" \
--outputPath="$working_dir/$output_path/mocks" \
--locale="$locale" \
--maxArrayLength="$max_array_length" \
--seed="$seed"

echo "Mock data generation done!"

Expand Down
Loading

0 comments on commit 1c23ac7

Please sign in to comment.