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

Support custom primitive type formats #66

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

McSym28
Copy link
Contributor

@McSym28 McSym28 commented Aug 6, 2024

This PR allows processing of custom formats for primitive types (boolean, integer, number and string). All non-null formats will be stored in a tuple ({:string, "custom"}).

Examples:

  • Date/time in non-standard format: DD.MM.YYYY
  • Boolean values as strings: Y/N or 1/0
  • Timestamp integers

The new callback OpenAPI.Renderer.render_type/2 (with the default implementation in OpenAPI.Renderer.Util.to_type/2) is added to allow users to customize the formats' processing.

Comment on lines -384 to +386
defp render_return_type([], _type_overrides), do: quote(do: :ok)
defp render_return_type(_state, []), do: quote(do: :ok)
Copy link
Contributor Author

@McSym28 McSym28 Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for going outside of this PR's limits, but shouldn't this clause check for the empty list on the second argument?

Comment on lines 12 to 13
@type integer_format :: String.t()
@type number_format :: String.t()
Copy link
Contributor Author

@McSym28 McSym28 Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't decided whether to add all the Decided to add integer and number formats mentioned in the OpenAPI specification (for "symmetry" with string formats):

  • int32 and int64 for integer type
  • float and double for number type

Comment on lines +55 to +59
| {:boolean, boolean_format}
| :integer
| {:integer, integer_format}
| :number
| {:number, number_format}
Copy link
Contributor Author

@McSym28 McSym28 Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need an atom-type or should we use :generic as a second tuple element as the "default" value?

@McSym28 McSym28 marked this pull request as ready for review August 6, 2024 15:59
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.

1 participant