-
Notifications
You must be signed in to change notification settings - Fork 0
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
Expose error responses in the spec output #25
Conversation
|
||
module CoreAPI | ||
module Authenticators | ||
class MainAuthenticator < Apia::Authenticator |
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.
this file is the same as before, i just decided to create an /authenticators
directory and move it there, seeing as i wanted to add some more.
|
||
return true if component_schema.present? | ||
|
||
@spec[:components][:schemas].delete(id) | ||
false |
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 schema is blank, then we don't need a $ref for it. This can happen with potential errors when they have no additional fields and thus the detail
property is actually just an empty object.
definition.id.gsub(/\//, "_") | ||
definition.id.gsub(/\//, "") |
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 decided to get rid of the underscores from our ids that we use for component schemas. I thought it looked odd to have camelcase and underscores together. There is no strict format required for these in the spec, but this follows the naming pattern used in the examples.
Dir.glob(File.join(File.dirname(__FILE__), "objects", "*.rb")).each do |file| | ||
Dir.glob(File.join(File.dirname(__FILE__), "objects", "*.rb")).sort.each do |file| |
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.
make rubocop happy
].flatten.join("_").camelize | ||
end | ||
|
||
def add_error_response_schemas |
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 did think about putting this error response stuff into a separate class. But I thought we might as well keep all the response related logic together in one file.
"$ref": "#/components/schemas/CoreAPI_Objects_TimeZone" | ||
"$ref": "#/components/schemas/CoreAPIObjectsTimeZone" |
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.
This is a good example of how the ref naming has changed to remove the underscores
[ | ||
@route_spec[:operationId].sub(":", "_").gsub(":", "").split("/"), | ||
@http_status, | ||
"Response" | ||
].flatten.join("_").camelize |
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 an endpoint defines many potential errors under the same response code, then we name the $ref id after the route itself, with the status code. This makes the ref unique and ensures it won't accidentally be re-used by other endpoints when the client generator runs.
if @definition.type.polymorph? | ||
if @definition.try(:type)&.polymorph? |
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 needed to add try(:type)
in a few places because this schema class can now be called with a Apia::Definitions::Error
and that doesn't respond to type
.
72c7d4d
to
dab40b7
Compare
dab40b7
to
498d221
Compare
498d221
to
e54a8ca
Compare
Apia defines errors responses like this:
So now we declare these in the responses for each endpoint.
https://swagger.io/docs/specification/describing-responses/
closes: #2
In swagger: