Conversation
|
OK hopefully got it right now. |
mbuhot
left a comment
There was a problem hiding this comment.
Thanks for writing this up! 🙏
| use PhoenixSwagger | ||
|
|
||
| @doc """ | ||
| Returns map of common swagger definitions merged with the map of provided schema definitions. |
There was a problem hiding this comment.
These very general schemas could be added to the MyAppWeb.Router.swagger_info callback.
There was a problem hiding this comment.
Can you pls elaborate more or provide a concrete code example ?
|
|
||
| @doc false | ||
| def swagger_definitions do | ||
| create_swagger_definitions(%{ |
There was a problem hiding this comment.
I think there is a simpler way to include specific schemas by putting each shared schema in its own module and including it in the map:
%{
ListOfProjects: ... schema definitions ...
Address: MyAppWeb.Schemas.Adress.schema()
}There was a problem hiding this comment.
Yes this is something that I did from be beginning. But the problem was that along with Address you have to include all other general common schemas, that Address schema is using. Otherwise they're not gonna appear in generate swagger.json.
| end | ||
| ``` | ||
|
|
||
| To avoid importing `create_swagger_definitions/1` in every controller, find a `HelloWeb` module and add an import |
There was a problem hiding this comment.
This advice feels a bit opinionated. Users are free to organise their projects and code as they like. My preference is to delete this file for API projects trading off some dry-ness for explicitness of imports.
There was a problem hiding this comment.
Yes I agree, this is my opinionated hint how to use something that pre-generated phoenix project already contains. Should we remove this section then ?
| parameters do | ||
| sort_by :query, :string, "The property to sort by" | ||
| sort_direction :query, :string, "The sort direction", enum: [:asc, :desc], default: :asc | ||
| company_id :string, :query, "The company id" |
There was a problem hiding this comment.
why does location and type differ between line 28 & 29?
There was a problem hiding this comment.
The example was directly copied from this location of the official documentation: https://hexdocs.pm/phoenix_swagger/reusing-swagger-parameters.html#content
Closes #243