-
Notifications
You must be signed in to change notification settings - Fork 2
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
Validates OpenAPI Specification on upload and redesigns spec entry #45
base: main
Are you sure you want to change the base?
Conversation
This will require users to enter specs a bit differently, since there is a couple of problems with the way we're handling this at the moment: Before ------ ``` // Request body as JSON: { "spec": { "openapi": "3.0.0" } } // etc. ``` This will break under certain circumstances as param mapping will not accept this in Phoenix (since server lists can be maps with multiple keys). It also omits the whole "we know whether this is YAML or JSON at runtime". After ----- ``` // Request body as JSON: { "json": " {\"openapi\": \"3.0.0\"}" } // etc. ``` This allows for knowing what spec we're parsing and will also open up other entrypoints more easily (e.g. fetching from a URL, uploading directly etc.)
...or: how I figured out my editor at home is misconfigured
Pull Request Test Coverage Report for Build e734412cf822148dbb96ea1d3b2287972fedebfd-PR-45
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to do the job.
Just a few tiny questions, but mostly around code specs, so nothing blocking.
@doc """ | ||
parses a given string to a map | ||
""" | ||
@spec parse_to_map(any(), :yaml | :json) :: :error | any() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the doc says string, shouldn't it be also in the spec?
@spec parse_to_map(any(), :yaml | :json) :: :error | any() | |
@spec parse_to_map(String.t(), :yaml | :json) :: :error | any() |
@spec parse(String.t(), :yaml | :json) :: Specification.t() | ||
@spec parse(term(), :yaml | :json) :: Specification.t() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for this spec change?
Also shouldn't parse/2 and parse_to_map/2 have the same definition for the inputs?
""" | ||
@spec parse(String.t(), :yaml | :json) :: Specification.t() | ||
@spec parse(term(), :yaml | :json) :: Specification.t() | ||
def parse(str, atom) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function could now be shortened to something like this:
def parse(str, atom) do
str
|> parse_to_map(atom)
|> case do
{:ok, decoded} ->
decoded |> build_specification()
{:error, _err} ->
Specification.unsupported()
end
end
@spec build_specification(map()) :: Specification.t() | ||
@spec build_specification(any()) :: Specification.t() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above about spec changes.
@@ -69,6 +69,7 @@ defmodule MimicryApi.ProxyControllerTest do | |||
end | |||
|
|||
@tag server: "simple.yaml" | |||
@tag :focus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a local test leftover?
@tag :focus |
This will require users to enter specs a bit differently, since there is
a couple of problems with the way we're handling this at the moment:
Before
This will break under certain circumstances as param mapping will not
accept this in Phoenix (since server lists can be maps with multiple
keys). It also omits the whole "we know whether this is YAML or JSON at
runtime".
After
This allows for knowing what spec we're parsing and will also open up
other entrypoints more easily (e.g. fetching from a URL, uploading
directly etc.)
Bonus
This now also validates the OpenAPI specification given using the https://github.com/mimicry-tech/openapi-validator.
Fixes #15