Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate examples for UUID formatted strings #444

Merged
merged 2 commits into from
May 10, 2022

Conversation

zorbash
Copy link
Contributor

@zorbash zorbash commented Apr 10, 2022

This is a continuation of #266 (comment)
we should generate valid examples for as many formats as possible.

The current behaviour regarding UUIDs is illustrated in the following example:

defmodule SomeSchema do
  require OpenApiSpex

  alias OpenApiSpex.{Schema, Cast}

  OpenApiSpex.schema(%{
    description: "some schema",
    type: :object,
    properties: %{
      id: %Schema{
        type: :string,
        format: :uuid
      }
    }
  })
end

OpenApiSpex.Cast.cast(SomeSchema.schema, OpenApiSpex.Schema.example(SomeSchema))

# => {:ok, %SomeSchema{id: ""}}

The generated example contains an invalid UUID and cast/2 doesn't validate it at all returning a success tuple.

@mbuhot mbuhot merged commit 254a81e into open-api-spex:master May 10, 2022
@zorbash zorbash deleted the example-uuid branch May 10, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants