-
Notifications
You must be signed in to change notification settings - Fork 182
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
Sharing common definitions #243
Comments
Your solution seems fine to me. The idea is that the swagger dsl is just sugar over a function pipeline, so you are free to call into your own functions at any point to make use of shared definitions. |
@mbuhot thanks. Only problem with this solution is the following: If I have a module with defmodule ControllerHelpers do
@moduledoc """
Conveniences for building controllers.
"""
use PhoenixSwagger
@doc """
Returns map of common swagger definitions.
These definitions (data structures) are not specific to any controller or
business domain logic.
"""
def swagger_definitions_common do
%{
ErrorResource:
swagger_schema do
title("Error")
description(
"Error objects provide additional information about problems encountered while performing an operation."
)
properties do
code(:string, "An application-specific error code, expressed as a string value.",
required: true
)
detail(
:string,
"A human-readable explanation specific to this occurrence of the problem",
required: true
)
id(:string, "A unique identifier for this particular occurrence of the problem",
required: true
)
status(
:string,
"The HTTP status code applicable to this problem, expressed as a string value",
required: true
)
title(:string, "Error title, usually HTTP reason phrase", required: true)
source(
Schema.new do
properties do
parameter(
:string,
"A string indicating which URI query parameter caused the error",
default: nil,
required: false
)
pointer(
:string,
"A JSON Pointer [RFC6901] to the associated entity in the request document",
default: nil,
required: false
)
end
end
)
end
end,
Error: JsonApi.single(:ErrorResource)
}
end
end I haven't find a cause of this problem but two possibles problems are: 1.) name of the function is not expected Will investigate further and document it here. |
@mbuhot I've attached as PR with documentation about extracting common schemas. If you have a time, please have a look at it. |
Is there an idiomatic way how to share Schemas not specific to any controller ? Like
Error
definition. I found a way how to do it, but not sure if there is a better way/solution.I have a
swagger_definitions_common
in different module and I just import the function and call it to give me the Error schema for current controller.The text was updated successfully, but these errors were encountered: