From 4e1d9ea010c314babbf8bfe840dc060dbad13c4f Mon Sep 17 00:00:00 2001 From: niku Date: Thu, 30 Mar 2017 23:45:39 +0900 Subject: [PATCH] [Elixir] Add documentation for functions (#5260) --- .../src/main/resources/elixir/api.mustache | 7 +++++ .../elixir/lib/swagger_petstore/api/fake.ex | 15 ++++++++++ .../elixir/lib/swagger_petstore/api/pet.ex | 30 +++++++++++++++++++ .../elixir/lib/swagger_petstore/api/store.ex | 18 +++++++++++ .../elixir/lib/swagger_petstore/api/user.ex | 30 +++++++++++++++++++ 5 files changed, 100 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/elixir/api.mustache b/modules/swagger-codegen/src/main/resources/elixir/api.mustache index 7a10537b5fac..799a4c31c089 100644 --- a/modules/swagger-codegen/src/main/resources/elixir/api.mustache +++ b/modules/swagger-codegen/src/main/resources/elixir/api.mustache @@ -10,6 +10,13 @@ defmodule {{#modulized}}{{appName}}{{/modulized}}.Api.{{classname}} do {{#operations}} {{#operation}} + @doc """ + {{summary}} + {{^notes.isEmpty}} + + {{notes}} + {{/notes.isEmpty}} + """ def {{#underscored}}{{operationId}}{{/underscored}}({{#allParams}}{{^-first}}, {{/-first}}{{#underscored}}{{paramName}}{{/underscored}}{{/allParams}}) do method = [method: :{{#underscored}}{{httpMethod}}{{/underscored}}] url = [url: "{{replacedPathName}}"] diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex index ebf4327576f6..9698a6dd4162 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex @@ -8,6 +8,11 @@ defmodule SwaggerPetstore.Api.Fake do plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2" plug Tesla.Middleware.JSON + @doc """ + To test \"client\" model + + To test \"client\" model + """ def test_client_model(body) do method = [method: :patch] url = [url: "/fake"] @@ -22,6 +27,11 @@ defmodule SwaggerPetstore.Api.Fake do request(options) end + @doc """ + Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + + Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + """ def test_endpoint_parameters(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, date, date_time, password, callback) do method = [method: :post] url = [url: "/fake"] @@ -36,6 +46,11 @@ defmodule SwaggerPetstore.Api.Fake do request(options) end + @doc """ + To test enum parameters + + To test enum parameters + """ def test_enum_parameters(enum_form_string_array, enum_form_string, enum_header_string_array, enum_header_string, enum_query_string_array, enum_query_string, enum_query_integer, enum_query_double) do method = [method: :get] url = [url: "/fake"] diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex index b4a9e0faf0cd..e68fb0ceaed1 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex @@ -8,6 +8,9 @@ defmodule SwaggerPetstore.Api.Pet do plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2" plug Tesla.Middleware.JSON + @doc """ + Add a new pet to the store + """ def add_pet(body) do method = [method: :post] url = [url: "/pet"] @@ -22,6 +25,9 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + Deletes a pet + """ def delete_pet(pet_id, api_key) do method = [method: :delete] url = [url: "/pet/#{pet_id}"] @@ -36,6 +42,11 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + Finds Pets by status + + Multiple status values can be provided with comma separated strings + """ def find_pets_by_status(status) do method = [method: :get] url = [url: "/pet/findByStatus"] @@ -50,6 +61,11 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + Finds Pets by tags + + Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + """ def find_pets_by_tags(tags) do method = [method: :get] url = [url: "/pet/findByTags"] @@ -64,6 +80,11 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + Find pet by ID + + Returns a single pet + """ def get_pet_by_id(pet_id) do method = [method: :get] url = [url: "/pet/#{pet_id}"] @@ -78,6 +99,9 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + Update an existing pet + """ def update_pet(body) do method = [method: :put] url = [url: "/pet"] @@ -92,6 +116,9 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + Updates a pet in the store with form data + """ def update_pet_with_form(pet_id, name, status) do method = [method: :post] url = [url: "/pet/#{pet_id}"] @@ -106,6 +133,9 @@ defmodule SwaggerPetstore.Api.Pet do request(options) end + @doc """ + uploads an image + """ def upload_file(pet_id, additional_metadata, file) do method = [method: :post] url = [url: "/pet/#{pet_id}/uploadImage"] diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex index 0bb53ca1d576..a37ac36b2f70 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex @@ -8,6 +8,11 @@ defmodule SwaggerPetstore.Api.Store do plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2" plug Tesla.Middleware.JSON + @doc """ + Delete purchase order by ID + + For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + """ def delete_order(order_id) do method = [method: :delete] url = [url: "/store/order/#{order_id}"] @@ -22,6 +27,11 @@ defmodule SwaggerPetstore.Api.Store do request(options) end + @doc """ + Returns pet inventories by status + + Returns a map of status codes to quantities + """ def get_inventory() do method = [method: :get] url = [url: "/store/inventory"] @@ -36,6 +46,11 @@ defmodule SwaggerPetstore.Api.Store do request(options) end + @doc """ + Find purchase order by ID + + For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + """ def get_order_by_id(order_id) do method = [method: :get] url = [url: "/store/order/#{order_id}"] @@ -50,6 +65,9 @@ defmodule SwaggerPetstore.Api.Store do request(options) end + @doc """ + Place an order for a pet + """ def place_order(body) do method = [method: :post] url = [url: "/store/order"] diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex index 6bccbea13318..9ebb200f0f09 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex @@ -8,6 +8,11 @@ defmodule SwaggerPetstore.Api.User do plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2" plug Tesla.Middleware.JSON + @doc """ + Create user + + This can only be done by the logged in user. + """ def create_user(body) do method = [method: :post] url = [url: "/user"] @@ -22,6 +27,9 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Creates list of users with given input array + """ def create_users_with_array_input(body) do method = [method: :post] url = [url: "/user/createWithArray"] @@ -36,6 +44,9 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Creates list of users with given input array + """ def create_users_with_list_input(body) do method = [method: :post] url = [url: "/user/createWithList"] @@ -50,6 +61,11 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Delete user + + This can only be done by the logged in user. + """ def delete_user(username) do method = [method: :delete] url = [url: "/user/#{username}"] @@ -64,6 +80,9 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Get user by user name + """ def get_user_by_name(username) do method = [method: :get] url = [url: "/user/#{username}"] @@ -78,6 +97,9 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Logs user into the system + """ def login_user(username, password) do method = [method: :get] url = [url: "/user/login"] @@ -92,6 +114,9 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Logs out current logged in user session + """ def logout_user() do method = [method: :get] url = [url: "/user/logout"] @@ -106,6 +131,11 @@ defmodule SwaggerPetstore.Api.User do request(options) end + @doc """ + Updated user + + This can only be done by the logged in user. + """ def update_user(username, body) do method = [method: :put] url = [url: "/user/#{username}"]