Skip to content

Commit

Permalink
[Unticketed] Fix UUID default example to not randomize each time (#3532)
Browse files Browse the repository at this point in the history
## Summary

### Time to review: __2 mins__

## Changes proposed
Fix schema field logic for UUID to not default to a randomly generated
UUID every time and either use a static value or whatever the user
passed in

## Context for reviewers
Was seeing on recent PRs that after we added UUID params to the schemas,
they were randomly generating each time.

## Additional information
Generated the file again myself a few times to verify it doesn't change
each run now

---------

Co-authored-by: nava-platform-bot <[email protected]>
  • Loading branch information
chouinar and nava-platform-bot authored Jan 15, 2025
1 parent 412d01e commit 5d3d50b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions api/openapi.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,7 @@ components:
type: string
format: uuid
description: The ID of the saved search
example: !!python/object:uuid.UUID
int: 82637552140693101888240202082641616217
example: 123e4567-e89b-12d3-a456-426614174000
name:
type: string
description: Name of the saved search
Expand Down
8 changes: 6 additions & 2 deletions api/src/api/schemas/extension/schema_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import enum
import typing
import uuid

from apiflask import fields as original_fields
from marshmallow import ValidationError
Expand Down Expand Up @@ -133,7 +132,12 @@ class UUID(original_fields.UUID, MixinField):

def __init__(self, **kwargs: typing.Any):
super().__init__(**kwargs)
self.metadata["example"] = uuid.uuid4()

# Set a default value for the UUID if none supplied
example_value = kwargs.get("metadata", {}).get(
"example", "123e4567-e89b-12d3-a456-426614174000"
)
self.metadata["example"] = example_value


class Date(original_fields.Date, MixinField):
Expand Down

0 comments on commit 5d3d50b

Please sign in to comment.