Expose error responses in the spec output#25
Conversation
|
|
||
| module CoreAPI | ||
| module Authenticators | ||
| class MainAuthenticator < Apia::Authenticator |
There was a problem hiding this comment.
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.
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.
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.
| # frozen_string_literal: true | ||
|
|
||
| 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.
make rubocop happy
| ].flatten.join("_").camelize | ||
| end | ||
|
|
||
| def add_error_response_schemas |
There was a problem hiding this comment.
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.
| "in": "query", | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CoreAPI_Objects_TimeZone" | ||
| "$ref": "#/components/schemas/CoreAPIObjectsTimeZone" |
There was a problem hiding this comment.
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.
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.
|
|
||
| def add_to_spec | ||
| if @definition.type.polymorph? | ||
| if @definition.try(:type)&.polymorph? |
There was a problem hiding this comment.
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: