Skip to content

Commit

Permalink
Allow extensions in all OpenApi structures
Browse files Browse the repository at this point in the history
Swagger documentation is outdated (https://swagger.io/docs/specification/openapi-extensions/).

Reading OpenApi sepcification (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md)
one can see that almost all objects can be extended with custom extensions.
  • Loading branch information
albertored committed Mar 23, 2022
1 parent 838594d commit f62061e
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 63 deletions.
6 changes: 4 additions & 2 deletions lib/open_api_spex/components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ defmodule OpenApiSpex.Components do
:headers,
:securitySchemes,
:links,
:callbacks
:callbacks,
:extensions
]

@type schemas_map :: %{String.t() => Schema.t() | Reference.t()}
Expand All @@ -47,6 +48,7 @@ defmodule OpenApiSpex.Components do
headers: %{String.t() => Header.t() | Reference.t()} | nil,
securitySchemes: %{String.t() => SecurityScheme.t() | Reference.t()} | nil,
links: %{String.t() => Link.t() | Reference.t()} | nil,
callbacks: %{String.t() => Callback.t() | Reference.t()} | nil
callbacks: %{String.t() => Callback.t() | Reference.t()} | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/contact.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule OpenApiSpex.Contact do
defstruct [
:name,
:url,
:email
:email,
extensions: nil
]

@typedoc """
Expand All @@ -17,6 +18,7 @@ defmodule OpenApiSpex.Contact do
@type t :: %__MODULE__{
name: String.t() | nil,
url: String.t() | nil,
email: String.t() | nil
email: String.t() | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/discriminator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule OpenApiSpex.Discriminator do
@enforce_keys :propertyName
defstruct [
:propertyName,
:mapping
:mapping,
:extensions
]

@typedoc """
Expand All @@ -21,7 +22,8 @@ defmodule OpenApiSpex.Discriminator do
"""
@type t :: %__MODULE__{
propertyName: String.t(),
mapping: %{String.t() => String.t()} | nil
mapping: %{String.t() => String.t()} | nil,
extensions: %{String.t() => any()} | nil
}

@doc """
Expand Down
6 changes: 4 additions & 2 deletions lib/open_api_spex/encoding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defmodule OpenApiSpex.Encoding do
:headers,
:style,
:explode,
:allowReserved
:allowReserved,
:extensions
]

@typedoc """
Expand All @@ -22,6 +23,7 @@ defmodule OpenApiSpex.Encoding do
headers: %{String.t() => Header.t() | Reference.t()} | nil,
style: Parameter.style() | nil,
explode: boolean | nil,
allowReserved: boolean | nil
allowReserved: boolean | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule OpenApiSpex.Example do
:summary,
:description,
:value,
:externalValue
:externalValue,
:extensions
]

@typedoc """
Expand All @@ -18,6 +19,7 @@ defmodule OpenApiSpex.Example do
summary: String.t() | nil,
description: String.t() | nil,
value: any,
externalValue: String.t() | nil
externalValue: String.t() | nil,
extensions: %{String.t() => any()} | nil
}
end
19 changes: 18 additions & 1 deletion lib/open_api_spex/extendable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,31 @@ end

defimpl OpenApiSpex.Extendable,
for: [
OpenApiSpex.Components,
OpenApiSpex.Contact,
OpenApiSpex.Discriminator,
OpenApiSpex.Encoding,
OpenApiSpex.Example,
OpenApiSpex.ExternalDocumentation,
OpenApiSpex.Header,
OpenApiSpex.Info,
OpenApiSpex.License,
OpenApiSpex.Link,
OpenApiSpex.MediaType,
OpenApiSpex.OAuthFlow,
OpenApiSpex.OAuthFlows,
OpenApiSpex.OpenApi,
OpenApiSpex.Operation,
OpenApiSpex.Parameter,
OpenApiSpex.PathItem,
OpenApiSpex.RequestBody,
OpenApiSpex.Response,
OpenApiSpex.Schema,
OpenApiSpex.SecurityScheme,
OpenApiSpex.Tag
OpenApiSpex.Server,
OpenApiSpex.ServerVariable,
OpenApiSpex.Tag,
OpenApiSpex.Xml
] do
def to_map(struct = %{extensions: e}) do
struct
Expand Down
6 changes: 4 additions & 2 deletions lib/open_api_spex/external_documentation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule OpenApiSpex.ExternalDocumentation do
@enforce_keys :url
defstruct [
:description,
:url
:url,
:extensions
]

@typedoc """
Expand All @@ -16,6 +17,7 @@ defmodule OpenApiSpex.ExternalDocumentation do
"""
@type t :: %__MODULE__{
description: String.t() | nil,
url: String.t()
url: String.t(),
extensions: %{String.t() => any()} | nil
}
end
4 changes: 3 additions & 1 deletion lib/open_api_spex/header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule OpenApiSpex.Header do
:schema,
:example,
:examples,
:extensions,
style: :simple
]

Expand All @@ -34,6 +35,7 @@ defmodule OpenApiSpex.Header do
explode: boolean | nil,
schema: Schema.t() | Reference.t() | nil,
example: any,
examples: %{String.t() => Example.t() | Reference.t()} | nil
examples: %{String.t() => Example.t() | Reference.t()} | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/license.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule OpenApiSpex.License do
@enforce_keys :name
defstruct [
:name,
:url
:url,
:extensions
]

@typedoc """
Expand All @@ -16,6 +17,7 @@ defmodule OpenApiSpex.License do
"""
@type t :: %__MODULE__{
name: String.t(),
url: String.t() | nil
url: String.t() | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule OpenApiSpex.Link do
:parameters,
:requestBody,
:description,
:server
:server,
:extensions
]

@typedoc """
Expand All @@ -34,6 +35,7 @@ defmodule OpenApiSpex.Link do
parameters: %{String.t() => any} | nil,
requestBody: any,
description: String.t() | nil,
server: Server.t() | nil
server: Server.t() | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/media_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule OpenApiSpex.MediaType do
:schema,
:example,
:examples,
:encoding
:encoding,
:extensions
]

@typedoc """
Expand All @@ -20,6 +21,7 @@ defmodule OpenApiSpex.MediaType do
schema: Schema.t() | Reference.t() | nil,
example: any,
examples: %{String.t() => Example.t() | Reference.t()} | nil,
encoding: %{String => Encoding.t()} | nil
encoding: %{String => Encoding.t()} | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/oauth_flow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule OpenApiSpex.OAuthFlow do
:authorizationUrl,
:tokenUrl,
:refreshUrl,
:scopes
:scopes,
:extensions
]

@typedoc """
Expand All @@ -18,6 +19,7 @@ defmodule OpenApiSpex.OAuthFlow do
authorizationUrl: String.t() | nil,
tokenUrl: String.t() | nil,
refreshUrl: String.t() | nil,
scopes: %{String.t() => String.t()} | nil
scopes: %{String.t() => String.t()} | nil,
extensions: %{String.t() => any()} | nil
}
end
6 changes: 4 additions & 2 deletions lib/open_api_spex/oauth_flows.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule OpenApiSpex.OAuthFlows do
:implicit,
:password,
:clientCredentials,
:authorizationCode
:authorizationCode,
:extensions
]

@typedoc """
Expand All @@ -20,6 +21,7 @@ defmodule OpenApiSpex.OAuthFlows do
implicit: OAuthFlow.t() | nil,
password: OAuthFlow.t() | nil,
clientCredentials: OAuthFlow.t() | nil,
authorizationCode: OAuthFlow.t() | nil
authorizationCode: OAuthFlow.t() | nil,
extensions: %{String.t() => any()} | nil
}
end
Loading

0 comments on commit f62061e

Please sign in to comment.