From dadb4722bc12f89fe3b7733c0f94f0d2eac414d7 Mon Sep 17 00:00:00 2001 From: Ingars Ribners Date: Tue, 19 Nov 2024 17:30:36 +0200 Subject: [PATCH 1/7] Updated README.mustache file for the Erlang server generator. Fixed one error and updated the usage instructions Changes made to the Erlang server generator's user instructions ("README.mustache" file): 1. Corrected the argument in section 4.1 of the user instructions. In openapi_server:start/2, the second argument for the generated Erlang code must now be in a different format than proposed in the instructions (see lines 13-16 of the "server.mustache" file). Initially, the server failed to start, and after some debugging, I discovered that the argument format did not match the server's expectations, causing the port number not to be passed to cowboy:start_clear/3. This has now been fixed. 2. Reviewed and updated the text of the user instructions to remove any ambiguities. 3. Tested the user instructions for accuracy and completeness. --- .../resources/erlang-server/README.mustache | 100 ++++++++++++++---- 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache index 887f730062fe..139dc78eaab1 100644 --- a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache @@ -4,33 +4,95 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator.tech) given an OpenAPI spec. -Dependencies: Erlang OTP/27 and rebar3. Also: -- [Cowboy](https://hex.pm/packages/cowboy) -- [Ranch](https://hex.pm/packages/ranch) -- [Jesse](https://hex.pm/packages/jesse) - ## Prerequisites +1. [Erlang/OTP (v27)](https://www.erlang.org/) + +2. [rebar3](https://rebar3.org/) + +3. Erlang libraries: + - [Cowboy](https://hex.pm/packages/cowboy) + - [Ranch](https://hex.pm/packages/ranch) + - [Jesse](https://hex.pm/packages/jesse) + +4. OpenAPI generator script "openapi-generator-cli" +(for more information see [OpenAPI Generator - Getting Started](https://github.com/OpenAPITools/openapi-generator#2---getting-started) ) + +5. OpenAPI specification file in the current folder (for example [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml)) + + ## Getting started Use erlang-server with rebar3 - 1, Create an application by using rebar3 - $ rebar3 new app http_server + 1. Create a folder with an Erlang application by using rebar3 + + $ rebar3 new app http_server + + 2. Generate OpenAPI erlang-server project using openapi-generator + + $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi + + 3. Go into the http_server project folder + + $ cd http_server + + _NOTE: The following generated files are now in the folder "http_server":_ + - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 + - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli + - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli + - rebar.config - Erlang project configuration file generated by openapi-generator-cli + + 4. Add the following line to the start/2 function in the src/http_server_app.erl: + ```erlang + openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) + ``` + + The updated start/2 in src/http_server_app.erl should look like this: + ```erlang + start(_StartType, _StartArgs) -> + openapi_server:start(http_server, + #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), + http_server_sup:start_link(). + ``` + + 5. Update application configuration file http_server.app.src (in the src subfolder): + 1. Copy application name from http_server.app.src to openapi.app.src + 2. Copy "mod" rule from the http_server.app.src to openapi.app.src + 3. Copy openapi.app.src over http_server.app.src + $ cp src/openapi.app.src src/http_server.app.src + 4. Remove openapi.app.src + $ rm src/openapi.app.src + + The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: + ``` + {application, http_server, + [ {description, "This is a sample petstore server"}, + {vsn, "1.0.0"}, + {registered, []}, + {mod, {http_server_app, []}}, + {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, + {env, []}, + {modules, []}, + {licenses, ["Apache-2.0"]}, + {links, []} + ]}. + ``` + + 6. Compile your http_server project + $ rebar3 compile - 2, Generate erlang-server project using openapi-generator - https://github.com/OpenAPITools/openapi-generator#2---getting-started + 7. Start Erlang virtual machine + $ rebar3 shell - 3, Copy erlang-server file to http_server project, and don't forget the 'priv' folder. + 8. Start the application by running a following command in the rebar3 shell + 1> application:ensure_all_started(http_server). - 4, Start in the http_server project: - 1, Introduce the following line in the http_server_app:start(_Type, _Args) function - openapi_server:start(http_server, #{ip => {127,0,0,1}, port => 8080}) - 2, Compile your http_server project - $ rebar3 compile - 3, Start erlang virtual machine - $ rebar3 shell - 4, Start project - application:ensure_all_started(http_server). + Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: + ``` + {shell, [ + {apps, [http_server]} + ]}. + ``` To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. From 31d4ac2b4392a945bbc53457d2172eabcbcd2f64 Mon Sep 17 00:00:00 2001 From: Ingars Ribners Date: Tue, 19 Nov 2024 21:40:44 +0200 Subject: [PATCH 2/7] erlang-server sample recompiled --- .../server/petstore/erlang-server/README.md | 100 ++++++++++++++---- 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/samples/server/petstore/erlang-server/README.md b/samples/server/petstore/erlang-server/README.md index 887f730062fe..139dc78eaab1 100644 --- a/samples/server/petstore/erlang-server/README.md +++ b/samples/server/petstore/erlang-server/README.md @@ -4,33 +4,95 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator.tech) given an OpenAPI spec. -Dependencies: Erlang OTP/27 and rebar3. Also: -- [Cowboy](https://hex.pm/packages/cowboy) -- [Ranch](https://hex.pm/packages/ranch) -- [Jesse](https://hex.pm/packages/jesse) - ## Prerequisites +1. [Erlang/OTP (v27)](https://www.erlang.org/) + +2. [rebar3](https://rebar3.org/) + +3. Erlang libraries: + - [Cowboy](https://hex.pm/packages/cowboy) + - [Ranch](https://hex.pm/packages/ranch) + - [Jesse](https://hex.pm/packages/jesse) + +4. OpenAPI generator script "openapi-generator-cli" +(for more information see [OpenAPI Generator - Getting Started](https://github.com/OpenAPITools/openapi-generator#2---getting-started) ) + +5. OpenAPI specification file in the current folder (for example [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml)) + + ## Getting started Use erlang-server with rebar3 - 1, Create an application by using rebar3 - $ rebar3 new app http_server + 1. Create a folder with an Erlang application by using rebar3 + + $ rebar3 new app http_server + + 2. Generate OpenAPI erlang-server project using openapi-generator + + $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi + + 3. Go into the http_server project folder + + $ cd http_server + + _NOTE: The following generated files are now in the folder "http_server":_ + - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 + - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli + - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli + - rebar.config - Erlang project configuration file generated by openapi-generator-cli + + 4. Add the following line to the start/2 function in the src/http_server_app.erl: + ```erlang + openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) + ``` + + The updated start/2 in src/http_server_app.erl should look like this: + ```erlang + start(_StartType, _StartArgs) -> + openapi_server:start(http_server, + #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), + http_server_sup:start_link(). + ``` + + 5. Update application configuration file http_server.app.src (in the src subfolder): + 1. Copy application name from http_server.app.src to openapi.app.src + 2. Copy "mod" rule from the http_server.app.src to openapi.app.src + 3. Copy openapi.app.src over http_server.app.src + $ cp src/openapi.app.src src/http_server.app.src + 4. Remove openapi.app.src + $ rm src/openapi.app.src + + The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: + ``` + {application, http_server, + [ {description, "This is a sample petstore server"}, + {vsn, "1.0.0"}, + {registered, []}, + {mod, {http_server_app, []}}, + {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, + {env, []}, + {modules, []}, + {licenses, ["Apache-2.0"]}, + {links, []} + ]}. + ``` + + 6. Compile your http_server project + $ rebar3 compile - 2, Generate erlang-server project using openapi-generator - https://github.com/OpenAPITools/openapi-generator#2---getting-started + 7. Start Erlang virtual machine + $ rebar3 shell - 3, Copy erlang-server file to http_server project, and don't forget the 'priv' folder. + 8. Start the application by running a following command in the rebar3 shell + 1> application:ensure_all_started(http_server). - 4, Start in the http_server project: - 1, Introduce the following line in the http_server_app:start(_Type, _Args) function - openapi_server:start(http_server, #{ip => {127,0,0,1}, port => 8080}) - 2, Compile your http_server project - $ rebar3 compile - 3, Start erlang virtual machine - $ rebar3 shell - 4, Start project - application:ensure_all_started(http_server). + Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: + ``` + {shell, [ + {apps, [http_server]} + ]}. + ``` To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. From 70369de0fe67f99864548f78c19130d8b1de9858 Mon Sep 17 00:00:00 2001 From: Ingars Ribners Date: Tue, 19 Nov 2024 21:49:51 +0200 Subject: [PATCH 3/7] README fix --- .../resources/erlang-server/README.mustache | 134 +++++++++--------- .../server/petstore/erlang-server/README.md | 134 +++++++++--------- 2 files changed, 134 insertions(+), 134 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache index 139dc78eaab1..ce9a34fa0bf8 100644 --- a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache @@ -24,75 +24,75 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator ## Getting started Use erlang-server with rebar3 - 1. Create a folder with an Erlang application by using rebar3 - - $ rebar3 new app http_server - - 2. Generate OpenAPI erlang-server project using openapi-generator - - $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi - - 3. Go into the http_server project folder - - $ cd http_server - - _NOTE: The following generated files are now in the folder "http_server":_ - - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 - - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli - - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli - - rebar.config - Erlang project configuration file generated by openapi-generator-cli - - 4. Add the following line to the start/2 function in the src/http_server_app.erl: - ```erlang - openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) - ``` - - The updated start/2 in src/http_server_app.erl should look like this: - ```erlang - start(_StartType, _StartArgs) -> - openapi_server:start(http_server, - #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), - http_server_sup:start_link(). - ``` - - 5. Update application configuration file http_server.app.src (in the src subfolder): - 1. Copy application name from http_server.app.src to openapi.app.src - 2. Copy "mod" rule from the http_server.app.src to openapi.app.src - 3. Copy openapi.app.src over http_server.app.src - $ cp src/openapi.app.src src/http_server.app.src - 4. Remove openapi.app.src - $ rm src/openapi.app.src - - The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: - ``` - {application, http_server, - [ {description, "This is a sample petstore server"}, - {vsn, "1.0.0"}, - {registered, []}, - {mod, {http_server_app, []}}, - {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, - {env, []}, - {modules, []}, - {licenses, ["Apache-2.0"]}, - {links, []} - ]}. - ``` +1. Create a folder with an Erlang application by using rebar3 - 6. Compile your http_server project - $ rebar3 compile + $ rebar3 new app http_server - 7. Start Erlang virtual machine - $ rebar3 shell - - 8. Start the application by running a following command in the rebar3 shell - 1> application:ensure_all_started(http_server). - - Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: - ``` - {shell, [ - {apps, [http_server]} - ]}. - ``` +2. Generate OpenAPI erlang-server project using openapi-generator + + $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi + +3. Go into the http_server project folder + + $ cd http_server + + _NOTE: The following generated files are now in the folder "http_server":_ + - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 + - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli + - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli + - rebar.config - Erlang project configuration file generated by openapi-generator-cli + +4. Add the following line to the start/2 function in the src/http_server_app.erl: +```erlang +openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) +``` + + The updated start/2 in src/http_server_app.erl should look like this: +```erlang +start(_StartType, _StartArgs) -> + openapi_server:start(http_server, + #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), + http_server_sup:start_link(). +``` + +5. Update application configuration file http_server.app.src (in the src subfolder): + 1. Copy application name from http_server.app.src to openapi.app.src + 2. Copy "mod" rule from the http_server.app.src to openapi.app.src + 3. Copy openapi.app.src over http_server.app.src + $ cp src/openapi.app.src src/http_server.app.src + 4. Remove openapi.app.src + $ rm src/openapi.app.src + + The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: +``` +{application, http_server, + [ {description, "This is a sample petstore server"}, + {vsn, "1.0.0"}, + {registered, []}, + {mod, {http_server_app, []}}, + {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, + {env, []}, + {modules, []}, + {licenses, ["Apache-2.0"]}, + {links, []} + ]}. +``` + +6. Compile your http_server project + $ rebar3 compile + +7. Start Erlang virtual machine + $ rebar3 shell + +8. Start the application by running a following command in the rebar3 shell + 1> application:ensure_all_started(http_server). + + Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: +``` +{shell, [ + {apps, [http_server]} +]}. +``` To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. diff --git a/samples/server/petstore/erlang-server/README.md b/samples/server/petstore/erlang-server/README.md index 139dc78eaab1..ce9a34fa0bf8 100644 --- a/samples/server/petstore/erlang-server/README.md +++ b/samples/server/petstore/erlang-server/README.md @@ -24,75 +24,75 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator ## Getting started Use erlang-server with rebar3 - 1. Create a folder with an Erlang application by using rebar3 - - $ rebar3 new app http_server - - 2. Generate OpenAPI erlang-server project using openapi-generator - - $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi - - 3. Go into the http_server project folder - - $ cd http_server - - _NOTE: The following generated files are now in the folder "http_server":_ - - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 - - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli - - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli - - rebar.config - Erlang project configuration file generated by openapi-generator-cli - - 4. Add the following line to the start/2 function in the src/http_server_app.erl: - ```erlang - openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) - ``` - - The updated start/2 in src/http_server_app.erl should look like this: - ```erlang - start(_StartType, _StartArgs) -> - openapi_server:start(http_server, - #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), - http_server_sup:start_link(). - ``` - - 5. Update application configuration file http_server.app.src (in the src subfolder): - 1. Copy application name from http_server.app.src to openapi.app.src - 2. Copy "mod" rule from the http_server.app.src to openapi.app.src - 3. Copy openapi.app.src over http_server.app.src - $ cp src/openapi.app.src src/http_server.app.src - 4. Remove openapi.app.src - $ rm src/openapi.app.src - - The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: - ``` - {application, http_server, - [ {description, "This is a sample petstore server"}, - {vsn, "1.0.0"}, - {registered, []}, - {mod, {http_server_app, []}}, - {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, - {env, []}, - {modules, []}, - {licenses, ["Apache-2.0"]}, - {links, []} - ]}. - ``` +1. Create a folder with an Erlang application by using rebar3 - 6. Compile your http_server project - $ rebar3 compile + $ rebar3 new app http_server - 7. Start Erlang virtual machine - $ rebar3 shell - - 8. Start the application by running a following command in the rebar3 shell - 1> application:ensure_all_started(http_server). - - Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: - ``` - {shell, [ - {apps, [http_server]} - ]}. - ``` +2. Generate OpenAPI erlang-server project using openapi-generator + + $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi + +3. Go into the http_server project folder + + $ cd http_server + + _NOTE: The following generated files are now in the folder "http_server":_ + - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 + - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli + - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli + - rebar.config - Erlang project configuration file generated by openapi-generator-cli + +4. Add the following line to the start/2 function in the src/http_server_app.erl: +```erlang +openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) +``` + + The updated start/2 in src/http_server_app.erl should look like this: +```erlang +start(_StartType, _StartArgs) -> + openapi_server:start(http_server, + #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), + http_server_sup:start_link(). +``` + +5. Update application configuration file http_server.app.src (in the src subfolder): + 1. Copy application name from http_server.app.src to openapi.app.src + 2. Copy "mod" rule from the http_server.app.src to openapi.app.src + 3. Copy openapi.app.src over http_server.app.src + $ cp src/openapi.app.src src/http_server.app.src + 4. Remove openapi.app.src + $ rm src/openapi.app.src + + The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: +``` +{application, http_server, + [ {description, "This is a sample petstore server"}, + {vsn, "1.0.0"}, + {registered, []}, + {mod, {http_server_app, []}}, + {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, + {env, []}, + {modules, []}, + {licenses, ["Apache-2.0"]}, + {links, []} + ]}. +``` + +6. Compile your http_server project + $ rebar3 compile + +7. Start Erlang virtual machine + $ rebar3 shell + +8. Start the application by running a following command in the rebar3 shell + 1> application:ensure_all_started(http_server). + + Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: +``` +{shell, [ + {apps, [http_server]} +]}. +``` To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. From 3daae2b8e577a619b2934aa4c27c96dd5c28e70b Mon Sep 17 00:00:00 2001 From: Ingars Ribners Date: Wed, 20 Nov 2024 19:58:04 +0200 Subject: [PATCH 4/7] Fixed README.mustache template markdown for erlang-server. Re-generated erlang-server sample. --- .../resources/erlang-server/README.mustache | 94 +++++++++++------- .../server/petstore/erlang-server/README.md | 96 ++++++++++++------- 2 files changed, 122 insertions(+), 68 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache index ce9a34fa0bf8..8bab5c4e90e5 100644 --- a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache @@ -15,55 +15,71 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator - [Ranch](https://hex.pm/packages/ranch) - [Jesse](https://hex.pm/packages/jesse) -4. OpenAPI generator script "openapi-generator-cli" +4. OpenAPI generator script `openapi-generator-cli` (for more information see [OpenAPI Generator - Getting Started](https://github.com/OpenAPITools/openapi-generator#2---getting-started) ) 5. OpenAPI specification file in the current folder (for example [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml)) ## Getting started -Use erlang-server with rebar3 +Use `erlang-server` with `rebar3` -1. Create a folder with an Erlang application by using rebar3 +1. Create a folder with an Erlang application by using `rebar3` - $ rebar3 new app http_server + `$ rebar3 new app http_server` -2. Generate OpenAPI erlang-server project using openapi-generator +2. Generate OpenAPI `erlang-server` project using `openapi-generator` - $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi + `$ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi` -3. Go into the http_server project folder +3. Go into the `http_server` project folder - $ cd http_server + `$ cd http_server` - _NOTE: The following generated files are now in the folder "http_server":_ - - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 - - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli - - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli - - rebar.config - Erlang project configuration file generated by openapi-generator-cli + NOTE: The following generated files are now in the folder "http_server": + + - `src/http_server*.erl`, `http_server.app.src` -- Erlang application modules generated by `rebar3` + + - `src/openapi*.erl`, `openapi.app.src` -- REST API request handling modules generated by `openapi-generator-cli` + + - `priv/openapi.json` -- OpenAPI data in JSON format created by `openapi-generator-cli` + + - `rebar.config` -- Erlang project configuration file generated by `openapi-generator-cli` + +4. Add the following line to the `start/2` function in the `src/http_server_app.erl`: -4. Add the following line to the start/2 function in the src/http_server_app.erl: ```erlang -openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) + openapi_server:start(http_server, + #{transport_opts => {ip,{127,0,0,1}}, + {port,8080} ]}) ``` - The updated start/2 in src/http_server_app.erl should look like this: +The updated `start/2` in `src/http_server_app.erl` should look like this: + ```erlang start(_StartType, _StartArgs) -> - openapi_server:start(http_server, - #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), + openapi_server:start(http_server, + #{transport_opts => {ip,{127,0,0,1}}, + {port,8080} ]}), http_server_sup:start_link(). ``` -5. Update application configuration file http_server.app.src (in the src subfolder): - 1. Copy application name from http_server.app.src to openapi.app.src - 2. Copy "mod" rule from the http_server.app.src to openapi.app.src - 3. Copy openapi.app.src over http_server.app.src - $ cp src/openapi.app.src src/http_server.app.src - 4. Remove openapi.app.src - $ rm src/openapi.app.src +5. Update application configuration file `http_server.app.src` (in the `src` subfolder): + + 1. Copy application name from `http_server.app.src` to `openapi.app.src` + + 2. Copy `{mod,...}` rule from the `http_server.app.src` to `openapi.app.src` + + 3. Copy `openapi.app.src` over `http_server.app.src` + + `$ cp src/openapi.app.src src/http_server.app.src` + + 4. Remove `openapi.app.src` + + `$ rm src/openapi.app.src` + +The updated `src/http_server.app.src` must be the only configuration file in the project and it should look like this: - The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: ``` {application, http_server, [ {description, "This is a sample petstore server"}, @@ -78,21 +94,31 @@ start(_StartType, _StartArgs) -> ]}. ``` -6. Compile your http_server project - $ rebar3 compile +6. Compile your `http_server` project + + `$ rebar3 compile` 7. Start Erlang virtual machine - $ rebar3 shell + `$ rebar3 shell` + +8. Start the application by running a following command in the `rebar3` shell -8. Start the application by running a following command in the rebar3 shell - 1> application:ensure_all_started(http_server). + `1> application:ensure_all_started(http_server).` Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: + ``` + {shell, [ + {apps, [http_server]} + ]}. + ``` + +Note: If you need to repeat code generation using `openapi-generator-cli`, but don't want to rewrite changes in files made manually, you could use file `.openapi-generator-ignore` in the project root folder. For example, such `.openapi-generator-ignore` will preserve manual changes done in the file `rebar.conf` (Point 8) + ``` -{shell, [ - {apps, [http_server]} -]}. +# OpenAPI Generator Ignore +rebar.config ``` To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. + diff --git a/samples/server/petstore/erlang-server/README.md b/samples/server/petstore/erlang-server/README.md index ce9a34fa0bf8..321db5c968e5 100644 --- a/samples/server/petstore/erlang-server/README.md +++ b/samples/server/petstore/erlang-server/README.md @@ -15,55 +15,71 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator - [Ranch](https://hex.pm/packages/ranch) - [Jesse](https://hex.pm/packages/jesse) -4. OpenAPI generator script "openapi-generator-cli" +4. OpenAPI generator script `openapi-generator-cli` (for more information see [OpenAPI Generator - Getting Started](https://github.com/OpenAPITools/openapi-generator#2---getting-started) ) 5. OpenAPI specification file in the current folder (for example [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml)) ## Getting started -Use erlang-server with rebar3 +Use `erlang-server` with `rebar3` -1. Create a folder with an Erlang application by using rebar3 +1. Create a folder with an Erlang application by using `rebar3` - $ rebar3 new app http_server + `$ rebar3 new app http_server` -2. Generate OpenAPI erlang-server project using openapi-generator +2. Generate OpenAPI `erlang-server` project using `openapi-generator` - $ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi + `$ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi` -3. Go into the http_server project folder +3. Go into the `http_server` project folder - $ cd http_server + `$ cd http_server` - _NOTE: The following generated files are now in the folder "http_server":_ - - src/http_server*.erl, http_server.app.src - Erlang application modules generated by rebar3 - - src/openapi*.erl, openapi.app.src - REST API request handling modules generated by openapi-generator-cli - - priv/openapi.json - OpenAPI data in JSON format created by openapi-generator-cli - - rebar.config - Erlang project configuration file generated by openapi-generator-cli + NOTE: The following generated files are now in the folder "http_server": + + - `src/http_server*.erl`, `http_server.app.src` -- Erlang application modules generated by `rebar3` + + - `src/openapi*.erl`, `openapi.app.src` -- REST API request handling modules generated by `openapi-generator-cli` + + - `priv/openapi.json` -- OpenAPI data in JSON format created by `openapi-generator-cli` + + - `rebar.config` -- Erlang project configuration file generated by `openapi-generator-cli` + +4. Add the following line to the `start/2` function in the `src/http_server_app.erl`: -4. Add the following line to the start/2 function in the src/http_server_app.erl: ```erlang -openapi_server:start(http_server, #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}) + openapi_server:start(http_server, + #{transport_opts => {ip,{127,0,0,1}}, + {port,8080} ]}) ``` - The updated start/2 in src/http_server_app.erl should look like this: +The updated `start/2` in `src/http_server_app.erl` should look like this: + ```erlang start(_StartType, _StartArgs) -> - openapi_server:start(http_server, - #{transport_opts=>[{ip,{127,0,0,1}},{port,8080}]}), + openapi_server:start(http_server, + #{transport_opts => {ip,{127,0,0,1}}, + {port,8080} ]}), http_server_sup:start_link(). ``` -5. Update application configuration file http_server.app.src (in the src subfolder): - 1. Copy application name from http_server.app.src to openapi.app.src - 2. Copy "mod" rule from the http_server.app.src to openapi.app.src - 3. Copy openapi.app.src over http_server.app.src - $ cp src/openapi.app.src src/http_server.app.src - 4. Remove openapi.app.src - $ rm src/openapi.app.src +5. Update application configuration file `http_server.app.src` (in the `src` subfolder): + + 1. Copy application name from `http_server.app.src` to `openapi.app.src` + + 2. Copy `{mod,...}` rule from the `http_server.app.src` to `openapi.app.src` + + 3. Copy `openapi.app.src` over `http_server.app.src` + + `$ cp src/openapi.app.src src/http_server.app.src` + + 4. Remove `openapi.app.src` + + `$ rm src/openapi.app.src` + +The updated `src/http_server.app.src` must be the only configuration file in the project and it should look like this: - The updated src/http_server.app.src must be the only configuration file in the project and it should look like this: ``` {application, http_server, [ {description, "This is a sample petstore server"}, @@ -78,21 +94,33 @@ start(_StartType, _StartArgs) -> ]}. ``` -6. Compile your http_server project - $ rebar3 compile +6. Compile your `http_server` project + + `$ rebar3 compile` 7. Start Erlang virtual machine - $ rebar3 shell -8. Start the application by running a following command in the rebar3 shell - 1> application:ensure_all_started(http_server). + `$ rebar3 shell` + +8. Start the application by running a following command in the `rebar3` shell + + `1> application:ensure_all_started(http_server).` Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: + ``` + {shell, [ + {apps, [http_server]} + ]}. + ``` + +Note: If you need to repeat code generation using `openapi-generator-cli`, but don't want to rewrite changes in files made manually, you could use file `.openapi-generator-ignore` in the project root folder. For example, such `.openapi-generator-ignore` will preserve manual changes done in the file `rebar.config` (Point 8): + ``` -{shell, [ - {apps, [http_server]} -]}. +# OpenAPI Generator Ignore +rebar.config ``` + To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. + From c675922b2bdfd3b4eeea19e6bf07adc083ffd181 Mon Sep 17 00:00:00 2001 From: Ingars Ribners Date: Thu, 28 Nov 2024 13:53:28 +0300 Subject: [PATCH 5/7] Update README.mustache --- .../src/main/resources/erlang-server/README.mustache | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache index 8bab5c4e90e5..51773e39f10e 100644 --- a/modules/openapi-generator/src/main/resources/erlang-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/erlang-server/README.mustache @@ -50,8 +50,9 @@ Use `erlang-server` with `rebar3` ```erlang openapi_server:start(http_server, - #{transport_opts => {ip,{127,0,0,1}}, - {port,8080} ]}) + #{transport_opts => [{ip,{127,0,0,1}}, + {port,8080} + ]}) ``` The updated `start/2` in `src/http_server_app.erl` should look like this: @@ -59,8 +60,9 @@ The updated `start/2` in `src/http_server_app.erl` should look like this: ```erlang start(_StartType, _StartArgs) -> openapi_server:start(http_server, - #{transport_opts => {ip,{127,0,0,1}}, - {port,8080} ]}), + #{transport_opts => [{ip,{127,0,0,1}}, + {port,8080} + ]}), http_server_sup:start_link(). ``` @@ -105,7 +107,7 @@ The updated `src/http_server.app.src` must be the only configuration file in the `1> application:ensure_all_started(http_server).` - Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: + Alternatively, you could start your application with the `rebar3` shell by adding the following lines to the `rebar.config`: ``` {shell, [ {apps, [http_server]} From c522179dd5506ba1aa61237ff47d22132efa0d8f Mon Sep 17 00:00:00 2001 From: Ingars Ribners Date: Thu, 28 Nov 2024 14:08:39 +0300 Subject: [PATCH 6/7] Sample 'erlang-server' re-generated --- samples/server/petstore/erlang-server/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/server/petstore/erlang-server/README.md b/samples/server/petstore/erlang-server/README.md index 321db5c968e5..51773e39f10e 100644 --- a/samples/server/petstore/erlang-server/README.md +++ b/samples/server/petstore/erlang-server/README.md @@ -50,8 +50,9 @@ Use `erlang-server` with `rebar3` ```erlang openapi_server:start(http_server, - #{transport_opts => {ip,{127,0,0,1}}, - {port,8080} ]}) + #{transport_opts => [{ip,{127,0,0,1}}, + {port,8080} + ]}) ``` The updated `start/2` in `src/http_server_app.erl` should look like this: @@ -59,8 +60,9 @@ The updated `start/2` in `src/http_server_app.erl` should look like this: ```erlang start(_StartType, _StartArgs) -> openapi_server:start(http_server, - #{transport_opts => {ip,{127,0,0,1}}, - {port,8080} ]}), + #{transport_opts => [{ip,{127,0,0,1}}, + {port,8080} + ]}), http_server_sup:start_link(). ``` @@ -99,28 +101,26 @@ The updated `src/http_server.app.src` must be the only configuration file in the `$ rebar3 compile` 7. Start Erlang virtual machine - `$ rebar3 shell` 8. Start the application by running a following command in the `rebar3` shell `1> application:ensure_all_started(http_server).` - Alternatively, you could start your application with the rebar3 shell by adding the following lines to the rebar.config: + Alternatively, you could start your application with the `rebar3` shell by adding the following lines to the `rebar.config`: ``` {shell, [ {apps, [http_server]} ]}. ``` -Note: If you need to repeat code generation using `openapi-generator-cli`, but don't want to rewrite changes in files made manually, you could use file `.openapi-generator-ignore` in the project root folder. For example, such `.openapi-generator-ignore` will preserve manual changes done in the file `rebar.config` (Point 8): +Note: If you need to repeat code generation using `openapi-generator-cli`, but don't want to rewrite changes in files made manually, you could use file `.openapi-generator-ignore` in the project root folder. For example, such `.openapi-generator-ignore` will preserve manual changes done in the file `rebar.conf` (Point 8) ``` # OpenAPI Generator Ignore rebar.config ``` - To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. From 38bb4bc643ca0405b049bae2df349343d00acdf2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 30 Nov 2024 16:33:16 +0800 Subject: [PATCH 7/7] update samples --- .../server/echo_api/erlang-server/README.md | 130 +++++++++++++++--- 1 file changed, 110 insertions(+), 20 deletions(-) diff --git a/samples/server/echo_api/erlang-server/README.md b/samples/server/echo_api/erlang-server/README.md index 887f730062fe..51773e39f10e 100644 --- a/samples/server/echo_api/erlang-server/README.md +++ b/samples/server/echo_api/erlang-server/README.md @@ -4,33 +4,123 @@ An Erlang server stub generated by [OpenAPI Generator](https://openapi-generator.tech) given an OpenAPI spec. -Dependencies: Erlang OTP/27 and rebar3. Also: -- [Cowboy](https://hex.pm/packages/cowboy) -- [Ranch](https://hex.pm/packages/ranch) -- [Jesse](https://hex.pm/packages/jesse) - ## Prerequisites +1. [Erlang/OTP (v27)](https://www.erlang.org/) + +2. [rebar3](https://rebar3.org/) + +3. Erlang libraries: + - [Cowboy](https://hex.pm/packages/cowboy) + - [Ranch](https://hex.pm/packages/ranch) + - [Jesse](https://hex.pm/packages/jesse) + +4. OpenAPI generator script `openapi-generator-cli` +(for more information see [OpenAPI Generator - Getting Started](https://github.com/OpenAPITools/openapi-generator#2---getting-started) ) + +5. OpenAPI specification file in the current folder (for example [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml)) + + ## Getting started -Use erlang-server with rebar3 +Use `erlang-server` with `rebar3` + +1. Create a folder with an Erlang application by using `rebar3` + + `$ rebar3 new app http_server` + +2. Generate OpenAPI `erlang-server` project using `openapi-generator` + + `$ openapi-generator-cli generate -g erlang-server -i petstore.yaml -o ./http_server --additional-properties packageName=openapi` + +3. Go into the `http_server` project folder + + `$ cd http_server` + + NOTE: The following generated files are now in the folder "http_server": + + - `src/http_server*.erl`, `http_server.app.src` -- Erlang application modules generated by `rebar3` + + - `src/openapi*.erl`, `openapi.app.src` -- REST API request handling modules generated by `openapi-generator-cli` + + - `priv/openapi.json` -- OpenAPI data in JSON format created by `openapi-generator-cli` - 1, Create an application by using rebar3 - $ rebar3 new app http_server + - `rebar.config` -- Erlang project configuration file generated by `openapi-generator-cli` - 2, Generate erlang-server project using openapi-generator - https://github.com/OpenAPITools/openapi-generator#2---getting-started +4. Add the following line to the `start/2` function in the `src/http_server_app.erl`: - 3, Copy erlang-server file to http_server project, and don't forget the 'priv' folder. +```erlang + openapi_server:start(http_server, + #{transport_opts => [{ip,{127,0,0,1}}, + {port,8080} + ]}) +``` - 4, Start in the http_server project: - 1, Introduce the following line in the http_server_app:start(_Type, _Args) function - openapi_server:start(http_server, #{ip => {127,0,0,1}, port => 8080}) - 2, Compile your http_server project - $ rebar3 compile - 3, Start erlang virtual machine - $ rebar3 shell - 4, Start project - application:ensure_all_started(http_server). +The updated `start/2` in `src/http_server_app.erl` should look like this: + +```erlang +start(_StartType, _StartArgs) -> + openapi_server:start(http_server, + #{transport_opts => [{ip,{127,0,0,1}}, + {port,8080} + ]}), + http_server_sup:start_link(). +``` + +5. Update application configuration file `http_server.app.src` (in the `src` subfolder): + + 1. Copy application name from `http_server.app.src` to `openapi.app.src` + + 2. Copy `{mod,...}` rule from the `http_server.app.src` to `openapi.app.src` + + 3. Copy `openapi.app.src` over `http_server.app.src` + + `$ cp src/openapi.app.src src/http_server.app.src` + + 4. Remove `openapi.app.src` + + `$ rm src/openapi.app.src` + +The updated `src/http_server.app.src` must be the only configuration file in the project and it should look like this: + +``` +{application, http_server, + [ {description, "This is a sample petstore server"}, + {vsn, "1.0.0"}, + {registered, []}, + {mod, {http_server_app, []}}, + {applications, [kernel, stdlib, public_key, ssl, inets, ranch, cowboy]}, + {env, []}, + {modules, []}, + {licenses, ["Apache-2.0"]}, + {links, []} + ]}. +``` + +6. Compile your `http_server` project + + `$ rebar3 compile` + +7. Start Erlang virtual machine + `$ rebar3 shell` + +8. Start the application by running a following command in the `rebar3` shell + + `1> application:ensure_all_started(http_server).` + + Alternatively, you could start your application with the `rebar3` shell by adding the following lines to the `rebar.config`: + ``` + {shell, [ + {apps, [http_server]} + ]}. + ``` + +Note: If you need to repeat code generation using `openapi-generator-cli`, but don't want to rewrite changes in files made manually, you could use file `.openapi-generator-ignore` in the project root folder. For example, such `.openapi-generator-ignore` will preserve manual changes done in the file `rebar.conf` (Point 8) + +``` +# OpenAPI Generator Ignore +rebar.config +``` To implement your own business logic, create a module called `http_server_logic` that implements the behaviour `openapi_logic_handler`. Refer to `openapi_logic_handler` documentation for details. +