forked from loafle/openapi-generator-original
remove oudated php, node server samples
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
Using the swagger-codegen, you can not only generate clients but servers as well! The same spec can be used to drive your
|
||||
development both ways. This is an example of generating a server for `node.js`.
|
||||
|
||||
### Prerequisites
|
||||
You need the following installed and available in your $PATH:
|
||||
|
||||
<li>- node (http://nodejs.org)
|
||||
|
||||
<li>- Scala 2.9.1 [available here](http://www.scala-lang.org)
|
||||
|
||||
You also need to add the scala binary to your PATH.
|
||||
|
||||
### Generating a server
|
||||
You first need to build the `swagger-codegen` project--this is done by running this command at the root of the swagger-codegen project:
|
||||
|
||||
```
|
||||
mvn package
|
||||
```
|
||||
|
||||
You can now generate a server from any valid[**](https://github.com/wordnik/swagger-codegen/blob/master/README.md#validating-your-swagger-spec) OpenAPI Spec:
|
||||
|
||||
```
|
||||
./bin/runscala.sh samples/server-generator/node/NodeServerFromSpec.scala http://petstore.swagger.wordnik.com/api/api-docs special-key
|
||||
```
|
||||
|
||||
After executing this script, you will have an output directory with the server-generated files:
|
||||
|
||||
```
|
||||
$ find samples/server-generator/node/output
|
||||
samples/server-generator/node/output
|
||||
samples/server-generator/node/output/App
|
||||
samples/server-generator/node/output/App/apis
|
||||
samples/server-generator/node/output/App/apis/PetApi.js
|
||||
samples/server-generator/node/output/App/apis/StoreApi.js
|
||||
samples/server-generator/node/output/App/apis/UserApi.js
|
||||
samples/server-generator/node/output/App/Common
|
||||
samples/server-generator/node/output/App/Common/node
|
||||
samples/server-generator/node/output/App/Common/node/paramTypes.js
|
||||
samples/server-generator/node/output/App/Common/node/randomizer.js
|
||||
samples/server-generator/node/output/App/Common/node/swagger.js
|
||||
samples/server-generator/node/output/App/main.js
|
||||
samples/server-generator/node/output/App/models.js
|
||||
samples/server-generator/node/output/package.json
|
||||
```
|
||||
|
||||
To run the server, cd to the `samples/server-generator/node/output` folder and run:
|
||||
|
||||
```
|
||||
# install the dependencies
|
||||
npm install
|
||||
node App/main.js
|
||||
```
|
||||
|
||||
You can now load the swagger-ui against `http://localhost:8002/resources.json`. Of course this isn't a fully
|
||||
runnable server! You have to add the logic in the apis/*.js files. But that's the easy part.
|
||||
|
||||
|
||||
### Making it your own
|
||||
Running the sample is easy, but how about making your own server? Easy! Just modify the `samples/server-generator/node/NodeServerFromSpec.scala` file.
|
||||
See comments in below, in a copy of the script
|
||||
|
||||
```scala
|
||||
object NodeServerGenerator extends BasicScalaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
// if you want to point to a different template directory, change this
|
||||
override def templateDir = "samples/server-generator/node/templates"
|
||||
|
||||
// where the files are written
|
||||
val outputFolder = "samples/server-generator/node/output"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = outputFolder + "/App"
|
||||
|
||||
// template used for apis (writes one file per api)
|
||||
apiTemplateFiles ++= Map("api.mustache" -> ".js")
|
||||
|
||||
modelTemplateFiles.clear
|
||||
|
||||
// puts the api files in a folder called `apis`
|
||||
override def apiPackage = Some("apis")
|
||||
|
||||
// copies swagger files and processes any *.mustache files
|
||||
override def supportingFiles = List(
|
||||
("package.json", outputFolder, "package.json"),
|
||||
("README.json", outputFolder, "README.md"),
|
||||
("main.mustache", destinationDir, "main.js"),
|
||||
("models.mustache", destinationDir, "models.js"))
|
||||
}
|
||||
```
|
||||
|
||||
Don't like the templates? Don't worry, we're not offended! They're [mustache](http://mustache.github.com/) templates and are easy to modify.
|
||||
Take a look at the sample templates here:
|
||||
|
||||
<li> Generator for your api classes: [api.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/node/templates/api.mustache)
|
||||
|
||||
<li> Generator for your models: [models.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/node/templates/models.mustache)
|
||||
|
||||
<li> The main class to run your server: [main.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/node/templates/main.mustache)
|
||||
|
||||
|
||||
Sound easy? It is!
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
object PHPServerGenerator extends BasicPHPGenerator {
|
||||
val outputFolder = "samples/server-generator/php/output"
|
||||
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
override def templateDir = "samples/server-generator/php/templates"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = outputFolder + ""
|
||||
|
||||
apiTemplateFiles.clear
|
||||
|
||||
modelTemplateFiles.clear
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("README.mustache", outputFolder, "README.md"),
|
||||
("composer.json", outputFolder, "composer.json"),
|
||||
(".htaccess", outputFolder, ".htaccess"),
|
||||
("index.mustache", outputFolder, "index.php"))
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
Using the swagger-codegen, you can not only generate clients but servers as well! The same spec can be used to drive your
|
||||
development both ways. This is an example of generating a server for `PHP`.
|
||||
|
||||
### Prerequisites
|
||||
You need the following installed and available in your $PATH:
|
||||
|
||||
<li>- Scala 2.9.1 [available here](http://www.scala-lang.org)
|
||||
|
||||
You also need to add scala binary to your PATH.
|
||||
|
||||
You need an apache server running with mod_rewrite enabled
|
||||
|
||||
### Generating a server
|
||||
You first need to build the `swagger-codegen` project--this is done by running this command at the root of the swagger-codegen project:
|
||||
|
||||
```
|
||||
mvn package
|
||||
```
|
||||
|
||||
You can now generate a server from any valid[**](https://github.com/swagger-api/swagger-codegen/blob/master/README.md#validating-your-swagger-spec) OpenAPI Spec:
|
||||
|
||||
```
|
||||
./bin/runscala.sh samples/server-generator/php/PHPServerFromSpec.scala http://petstore.swagger.wordnik.com/api/api-docs special-key
|
||||
```
|
||||
|
||||
After executing this script, you will have an output directory with the server-generated files:
|
||||
|
||||
```
|
||||
$ cd samples/server-generator/php/output
|
||||
$ find . -type f
|
||||
./.htaccess
|
||||
./composer.json
|
||||
./index.php
|
||||
./README.md
|
||||
```
|
||||
|
||||
To install the dependencies, cd to the `samples/server-generator/php/output` folder and run:
|
||||
|
||||
```
|
||||
$ curl -s http://getcomposer.org/installer | php
|
||||
$ php composer.phar install
|
||||
```
|
||||
|
||||
You can now access the api by going to `http://localhost/path-to-output-dir/`. Of course this isn't a fully
|
||||
runnable server! You have to add the logic in the index.php file. But that's the easy part.
|
||||
|
||||
|
||||
### Making it your own
|
||||
Running the sample is easy, but how about making your own server? Easy! Just modify the `samples/server-generator/php/PHPServerGenerator.scala` file.
|
||||
|
||||
Don't like the templates? Don't worry, we're not offended! They're [mustache](http://mustache.github.com/) templates and are easy to modify.
|
||||
Take a look at the sample templates here:
|
||||
|
||||
<li> - Generator for the index.php file : [api.mustache](https://github.com/swagger-api/swagger-codegen/blob/master/samples/server-generator/php/templates/index.mustache)
|
||||
|
||||
Sound easy? It is!
|
||||
@@ -1,5 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
|
||||
</IfModule>
|
||||
@@ -1,10 +0,0 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
|
||||
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
|
||||
is an example of building a PHP server.
|
||||
|
||||
This example uses the [Silex](http://silex.sensiolabs.org/) micro-framework. To see how to make this your own, look here:
|
||||
|
||||
[README](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/php)
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"require": {
|
||||
"silex/silex": "~1.2"
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Silex\Application;
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
$app->POST('/user/createWithArray', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing createUsersWithArrayInput as a POST method ?');
|
||||
});
|
||||
|
||||
$app->POST('/user/createWithList', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing createUsersWithListInput as a POST method ?');
|
||||
});
|
||||
|
||||
$app->PUT('/user/{username}', function(Application $app, Request $request, $username) {
|
||||
return new Response('How about implementing updateUser as a PUT method ?');
|
||||
});
|
||||
|
||||
$app->DELETE('/user/{username}', function(Application $app, Request $request, $username) {
|
||||
return new Response('How about implementing deleteUser as a DELETE method ?');
|
||||
});
|
||||
|
||||
$app->GET('/user/{username}', function(Application $app, Request $request, $username) {
|
||||
return new Response('How about implementing getUserByName as a GET method ?');
|
||||
});
|
||||
|
||||
$app->GET('/user/login', function(Application $app, Request $request) {
|
||||
$username = $request->get('username');
|
||||
$password = $request->get('password');
|
||||
return new Response('How about implementing loginUser as a GET method ?');
|
||||
});
|
||||
|
||||
$app->GET('/user/logout', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing logoutUser as a GET method ?');
|
||||
});
|
||||
|
||||
$app->POST('/user', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing createUser as a POST method ?');
|
||||
});
|
||||
|
||||
$app->PUT('/pet', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing updatePet as a PUT method ?');
|
||||
});
|
||||
|
||||
$app->POST('/pet', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing addPet as a POST method ?');
|
||||
});
|
||||
|
||||
$app->GET('/pet/findByStatus', function(Application $app, Request $request) {
|
||||
$status = $request->get('status');
|
||||
return new Response('How about implementing findPetsByStatus as a GET method ?');
|
||||
});
|
||||
|
||||
$app->GET('/pet/findByTags', function(Application $app, Request $request) {
|
||||
$tags = $request->get('tags');
|
||||
return new Response('How about implementing findPetsByTags as a GET method ?');
|
||||
});
|
||||
|
||||
$app->POST('/pet/{petId}', function(Application $app, Request $request, $petId) {
|
||||
$name = $request->get('name');
|
||||
$status = $request->get('status');
|
||||
return new Response('How about implementing updatePetWithForm as a POST method ?');
|
||||
});
|
||||
|
||||
$app->GET('/pet/{petId}', function(Application $app, Request $request, $petId) {
|
||||
return new Response('How about implementing getPetById as a GET method ?');
|
||||
});
|
||||
|
||||
$app->DELETE('/pet/{petId}', function(Application $app, Request $request, $petId) {
|
||||
return new Response('How about implementing deletePet as a DELETE method ?');
|
||||
});
|
||||
|
||||
$app->PATCH('/pet/{petId}', function(Application $app, Request $request, $petId) {
|
||||
return new Response('How about implementing partialUpdate as a PATCH method ?');
|
||||
});
|
||||
|
||||
$app->POST('/pet/uploadImage', function(Application $app, Request $request) {
|
||||
$additionalMetadata = $request->get('additionalMetadata');
|
||||
$file = $request->get('file');
|
||||
return new Response('How about implementing uploadFile as a POST method ?');
|
||||
});
|
||||
|
||||
$app->POST('/store/order', function(Application $app, Request $request) {
|
||||
return new Response('How about implementing placeOrder as a POST method ?');
|
||||
});
|
||||
|
||||
$app->DELETE('/store/order/{orderId}', function(Application $app, Request $request, $orderId) {
|
||||
return new Response('How about implementing deleteOrder as a DELETE method ?');
|
||||
});
|
||||
|
||||
$app->GET('/store/order/{orderId}', function(Application $app, Request $request, $orderId) {
|
||||
return new Response('How about implementing getOrderById as a GET method ?');
|
||||
});
|
||||
|
||||
$app->run();
|
||||
@@ -1,5 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
|
||||
</IfModule>
|
||||
@@ -1,10 +0,0 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
|
||||
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
|
||||
is an example of building a PHP server.
|
||||
|
||||
This example uses the [Silex](http://silex.sensiolabs.org/) micro-framework. To see how to make this your own, look here:
|
||||
|
||||
[README](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/php)
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"require": {
|
||||
"silex/silex": "~1.2"
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Silex\Application;
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
$app->{{httpMethod}}('{{path}}', function(Application $app, Request $request{{#pathParams}}, ${{paramName}}{{/pathParams}}) {
|
||||
{{#queryParams}}${{paramName}} = $request->get('{{paramName}}');{{newline}} {{/queryParams}}
|
||||
{{#formParams}}${{paramName}} = $request->get('{{paramName}}');{{newline}} {{/formParams}}
|
||||
return new Response('How about implementing {{nickname}} as a {{httpMethod}} method ?');
|
||||
});
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
||||
$app->run();
|
||||
Reference in New Issue
Block a user