klo

klo

OpenApiSpex schema - are there any naming conventions on handling show and index routes?

Hi all,

I was wondering if there is any naming convention on handling show and index routes. Would they just fall under Request and Response?

If i have a show route for getting a car by id

would it be something like

show naming:


defmodule CarRequest do
  require OpenApiSpex
  alias OpenApiSpex.Schema
  
  OpenApiSpex.schema(%{
    title: "CarRequest",
    description: "Gets a single car by id.",
    type: :object,
    required: [:id],
    properties: %{
      id: %Schema{type: :integer, example: 12}
    }
  })
end

index naming:

defmodule CarsRequest do
  require OpenApiSpex
  alias OpenApiSpex.Schema
  
  OpenApiSpex.schema(%{
    title: "CarsRequest",
    description: "Gets all cars.",
    type: :object
  })
end

then inside of the response would it be something like

defmodule CarResponse do
  require OpenApiSpex
  alias OpenApiSpex.Schema
  
  OpenApiSpex.schema(%{
    title: "CarResponse",
    description: "Gets a single car.",
    type: :object,
    required: [:data],
    properties: %{
      data: Car.schema()
    }
  })
end

index response

defmodule CarsResponse do
  require OpenApiSpex
  alias OpenApiSpex.Schema
  
  OpenApiSpex.schema(%{
    title: "CarsResponse",
    description: "Gets all cars.",
    type: :object,
    required: [:data],
    properties: %{
      data: %Schema{type: :array, data: Car.schema()}
    }
  })
end

shared Car response:

defmodule Car do
  require OpenApiSpex
  alias OpenApiSpex.Schema
  
  OpenApiSpex.schema(%{
    title: "Car",
    description: "A single car.",
    type: :object,
    required: [:id, :make, :model],
    properties: %{
      id: %Schema{type: :integer, example: 12},
      make: %Schema{type: :string, example: "toyota"},
      model: %Schema{type: :string, example: "corolla"}
    }
  })
end

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement