forked from loafle/openapi-generator-original
Merge pull request #1619 from EduGraph/issue-1075
[PHP] Slim Framework v3 - Server Generator #1075
This commit is contained in:
commit
2d34f567ff
@ -41,6 +41,7 @@ cd $APP_DIR
|
|||||||
./bin/scala-petstore.sh
|
./bin/scala-petstore.sh
|
||||||
./bin/scalatra-petstore-server.sh
|
./bin/scalatra-petstore-server.sh
|
||||||
./bin/silex-petstore-server.sh
|
./bin/silex-petstore-server.sh
|
||||||
|
./bin/slim-petstore-server.sh
|
||||||
./bin/spring-mvc-petstore-server.sh
|
./bin/spring-mvc-petstore-server.sh
|
||||||
./bin/swift-petstore.sh
|
./bin/swift-petstore.sh
|
||||||
./bin/tizen-petstore.sh
|
./bin/tizen-petstore.sh
|
||||||
|
31
bin/slim-petstore-server.sh
Normal file
31
bin/slim-petstore-server.sh
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT="$0"
|
||||||
|
|
||||||
|
while [ -h "$SCRIPT" ] ; do
|
||||||
|
ls=`ls -ld "$SCRIPT"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
SCRIPT="$link"
|
||||||
|
else
|
||||||
|
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "${APP_DIR}" ]; then
|
||||||
|
APP_DIR=`dirname "$SCRIPT"`/..
|
||||||
|
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||||
|
fi
|
||||||
|
|
||||||
|
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||||
|
|
||||||
|
if [ ! -f "$executable" ]
|
||||||
|
then
|
||||||
|
mvn clean package
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
|
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
|
ags="$@ generate -t modules/swagger-codegen/src/main/resources/slim -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l slim -o samples/server/petstore/slim"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
@ -0,0 +1,221 @@
|
|||||||
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import io.swagger.codegen.CodegenConfig;
|
||||||
|
import io.swagger.codegen.CodegenConstants;
|
||||||
|
import io.swagger.codegen.CodegenType;
|
||||||
|
import io.swagger.codegen.DefaultCodegen;
|
||||||
|
import io.swagger.codegen.SupportingFile;
|
||||||
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
|
import io.swagger.models.properties.MapProperty;
|
||||||
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.models.properties.RefProperty;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class SlimFrameworkServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
protected String invokerPackage;
|
||||||
|
protected String groupId = "io.swagger";
|
||||||
|
protected String artifactId = "swagger-server";
|
||||||
|
protected String artifactVersion = "1.0.0";
|
||||||
|
private String variableNamingConvention = "camelCase";
|
||||||
|
|
||||||
|
public SlimFrameworkServerCodegen() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
invokerPackage = camelize("SwaggerServer");
|
||||||
|
|
||||||
|
String packagePath = "SwaggerServer";
|
||||||
|
|
||||||
|
modelPackage = packagePath + "\\lib\\Models";
|
||||||
|
apiPackage = packagePath + "\\lib";
|
||||||
|
outputFolder = "generated-code" + File.separator + "slim";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".php");
|
||||||
|
|
||||||
|
// no api files
|
||||||
|
apiTemplateFiles.clear();
|
||||||
|
|
||||||
|
embeddedTemplateDir = templateDir = "slim";
|
||||||
|
|
||||||
|
reservedWords = new HashSet<String>(
|
||||||
|
Arrays.asList(
|
||||||
|
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||||
|
);
|
||||||
|
|
||||||
|
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||||
|
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||||
|
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||||
|
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||||
|
|
||||||
|
// ref: http://php.net/manual/en/language.types.intro.php
|
||||||
|
languageSpecificPrimitives = new HashSet<String>(
|
||||||
|
Arrays.asList(
|
||||||
|
"boolean",
|
||||||
|
"int",
|
||||||
|
"integer",
|
||||||
|
"double",
|
||||||
|
"float",
|
||||||
|
"string",
|
||||||
|
"object",
|
||||||
|
"DateTime",
|
||||||
|
"mixed",
|
||||||
|
"number")
|
||||||
|
);
|
||||||
|
|
||||||
|
instantiationTypes.put("array", "array");
|
||||||
|
instantiationTypes.put("map", "map");
|
||||||
|
|
||||||
|
// ref: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
|
||||||
|
typeMapping = new HashMap<String, String>();
|
||||||
|
typeMapping.put("integer", "int");
|
||||||
|
typeMapping.put("long", "int");
|
||||||
|
typeMapping.put("float", "float");
|
||||||
|
typeMapping.put("double", "double");
|
||||||
|
typeMapping.put("string", "string");
|
||||||
|
typeMapping.put("byte", "int");
|
||||||
|
typeMapping.put("boolean", "bool");
|
||||||
|
typeMapping.put("date", "\\DateTime");
|
||||||
|
typeMapping.put("datetime", "\\DateTime");
|
||||||
|
typeMapping.put("file", "\\SplFileObject");
|
||||||
|
typeMapping.put("map", "map");
|
||||||
|
typeMapping.put("array", "array");
|
||||||
|
typeMapping.put("list", "array");
|
||||||
|
typeMapping.put("object", "object");
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("README.mustache", packagePath.replace('/', File.separatorChar), "README.md"));
|
||||||
|
supportingFiles.add(new SupportingFile("composer.json", packagePath.replace('/', File.separatorChar), "composer.json"));
|
||||||
|
supportingFiles.add(new SupportingFile("index.mustache", packagePath.replace('/', File.separatorChar), "index.php"));
|
||||||
|
supportingFiles.add(new SupportingFile(".htaccess", packagePath.replace('/', File.separatorChar), ".htaccess"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.SERVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "slim";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates a Slim Framework server library.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
return "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return (outputFolder + "/" + apiPackage()).replace('/', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return (outputFolder + "/" + modelPackage()).replace('/', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(Property p) {
|
||||||
|
if (p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
Property inner = ap.getItems();
|
||||||
|
return getTypeDeclaration(inner) + "[]";
|
||||||
|
} else if (p instanceof MapProperty) {
|
||||||
|
MapProperty mp = (MapProperty) p;
|
||||||
|
Property inner = mp.getAdditionalProperties();
|
||||||
|
return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||||
|
} else if (p instanceof RefProperty) {
|
||||||
|
String type = super.getTypeDeclaration(p);
|
||||||
|
return (!languageSpecificPrimitives.contains(type))
|
||||||
|
? "\\" + modelPackage + "\\" + type : type;
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSwaggerType(Property p) {
|
||||||
|
String swaggerType = super.getSwaggerType(p);
|
||||||
|
String type = null;
|
||||||
|
if (typeMapping.containsKey(swaggerType)) {
|
||||||
|
type = typeMapping.get(swaggerType);
|
||||||
|
if (languageSpecificPrimitives.contains(type)) {
|
||||||
|
return type;
|
||||||
|
} else if (instantiationTypes.containsKey(type)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
type = swaggerType;
|
||||||
|
}
|
||||||
|
if (type == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return toModelName(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(String name) {
|
||||||
|
if (!languageSpecificPrimitives.contains(name)) {
|
||||||
|
return "\\" + modelPackage + "\\" + name;
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toDefaultValue(Property p) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParameterNamingConvention(String variableNamingConvention) {
|
||||||
|
this.variableNamingConvention = variableNamingConvention;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toVarName(String name) {
|
||||||
|
// sanitize name
|
||||||
|
name = sanitizeName(name);
|
||||||
|
|
||||||
|
if ("camelCase".equals(variableNamingConvention)) {
|
||||||
|
// return the name in camelCase style
|
||||||
|
// phone_number => phoneNumber
|
||||||
|
name = camelize(name, true);
|
||||||
|
} else { // default to snake case
|
||||||
|
// return the name in underscore style
|
||||||
|
// PhoneNumber => phone_number
|
||||||
|
name = underscore(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// parameter name starting with number won't compile
|
||||||
|
// need to escape it by appending _ at the beginning
|
||||||
|
if (name.matches("^\\d.*")) {
|
||||||
|
name = "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toParamName(String name) {
|
||||||
|
// should be the same as variable name
|
||||||
|
return toVarName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelName(String name) {
|
||||||
|
// model name cannot use reserved keyword
|
||||||
|
if (reservedWords.contains(name)) {
|
||||||
|
escapeReservedWord(name); // e.g. return => _return
|
||||||
|
}
|
||||||
|
|
||||||
|
// camelize the model name
|
||||||
|
// phone_number => PhoneNumber
|
||||||
|
return camelize(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelFilename(String name) {
|
||||||
|
// should be the same as the model name
|
||||||
|
return toModelName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,6 +18,7 @@ io.swagger.codegen.languages.ScalaClientCodegen
|
|||||||
io.swagger.codegen.languages.ScalatraServerCodegen
|
io.swagger.codegen.languages.ScalatraServerCodegen
|
||||||
io.swagger.codegen.languages.SilexServerCodegen
|
io.swagger.codegen.languages.SilexServerCodegen
|
||||||
io.swagger.codegen.languages.SinatraServerCodegen
|
io.swagger.codegen.languages.SinatraServerCodegen
|
||||||
|
io.swagger.codegen.languages.SlimFrameworkServerCodegen
|
||||||
io.swagger.codegen.languages.SpringMVCServerCodegen
|
io.swagger.codegen.languages.SpringMVCServerCodegen
|
||||||
io.swagger.codegen.languages.StaticDocCodegen
|
io.swagger.codegen.languages.StaticDocCodegen
|
||||||
io.swagger.codegen.languages.StaticHtmlGenerator
|
io.swagger.codegen.languages.StaticHtmlGenerator
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
RewriteEngine On
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
|
||||||
|
</IfModule>
|
@ -0,0 +1,10 @@
|
|||||||
|
# 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 [Slim Framework](http://www.slimframework.com/). To see how to make this your own, please take a look at the template here:
|
||||||
|
|
||||||
|
[TEMPLATES](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/slim/)
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"minimum-stability": "RC",
|
||||||
|
"require": {
|
||||||
|
"slim/slim": "3.*"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
{{#apiInfo}}/**
|
||||||
|
* {{appName}}
|
||||||
|
* @version {{appVersion}}
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
$app = new Slim\App();
|
||||||
|
|
||||||
|
{{#apis}}{{#operations}}{{#operation}}
|
||||||
|
/**
|
||||||
|
* {{httpMethod}} {{nickname}}
|
||||||
|
* Summary: {{summary}}
|
||||||
|
* Notes: {{notes}}
|
||||||
|
{{#hasProduces}} * Output-Formats: [{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}]{{/hasProduces}}
|
||||||
|
*/
|
||||||
|
$app->{{httpMethod}}('{{path}}', function($request, $response, $args) {
|
||||||
|
{{#hasHeaderParams}}$headers = $request->getHeaders();{{/hasHeaderParams}}
|
||||||
|
{{#hasQueryParams}}$queryParams = $request->getQueryParams();
|
||||||
|
{{#queryParams}}${{paramName}} = $queryParams['{{paramName}}'];{{newline}} {{/queryParams}}{{/hasQueryParams}}
|
||||||
|
{{#hasFormParams}}{{#formParams}}${{paramName}} = $args['{{paramName}}'];{{newline}} {{/formParams}}{{/hasFormParams}}
|
||||||
|
{{#hasBodyParam}}$body = $request->getParsedBody();{{/hasBodyParam}}
|
||||||
|
$response->write('How about implementing {{nickname}} as a {{httpMethod}} method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
||||||
|
|
||||||
|
$app->run();
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
{{#models}}{{#model}}/*
|
||||||
|
* {{classname}}
|
||||||
|
*/
|
||||||
|
namespace {{package}};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* {{classname}}
|
||||||
|
*/
|
||||||
|
class {{classname}} {
|
||||||
|
{{#vars}}/* @var {{datatype}} ${{name}} {{#description}}{{description}}{{/description}} */
|
||||||
|
private ${{name}};
|
||||||
|
{{/vars}}
|
||||||
|
}
|
||||||
|
{{/model}}{{/models}}
|
@ -0,0 +1,30 @@
|
|||||||
|
package io.swagger.codegen.options;
|
||||||
|
|
||||||
|
import io.swagger.codegen.CodegenConstants;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SlimFrameworkServerOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SORT_PARAMS_VALUE = "false";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "slim";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package io.swagger.codegen.slim;
|
||||||
|
|
||||||
|
import io.swagger.codegen.AbstractOptionsTest;
|
||||||
|
import io.swagger.codegen.CodegenConfig;
|
||||||
|
import io.swagger.codegen.languages.SlimFrameworkServerCodegen;
|
||||||
|
import io.swagger.codegen.options.SlimFrameworkServerOptionsProvider;
|
||||||
|
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class SlimFrameworkServerOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private SlimFrameworkServerCodegen clientCodegen;
|
||||||
|
|
||||||
|
public SlimFrameworkServerOptionsTest() {
|
||||||
|
super(new SlimFrameworkServerOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(SlimFrameworkServerOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,7 @@ import io.swagger.codegen.options.ScalaClientOptionsProvider;
|
|||||||
import io.swagger.codegen.options.ScalatraServerOptionsProvider;
|
import io.swagger.codegen.options.ScalatraServerOptionsProvider;
|
||||||
import io.swagger.codegen.options.SilexServerOptionsProvider;
|
import io.swagger.codegen.options.SilexServerOptionsProvider;
|
||||||
import io.swagger.codegen.options.SinatraServerOptionsProvider;
|
import io.swagger.codegen.options.SinatraServerOptionsProvider;
|
||||||
|
import io.swagger.codegen.options.SlimFrameworkServerOptionsProvider;
|
||||||
import io.swagger.codegen.options.SpringMVCServerOptionsProvider;
|
import io.swagger.codegen.options.SpringMVCServerOptionsProvider;
|
||||||
import io.swagger.codegen.options.StaticDocOptionsProvider;
|
import io.swagger.codegen.options.StaticDocOptionsProvider;
|
||||||
import io.swagger.codegen.options.StaticHtmlOptionsProvider;
|
import io.swagger.codegen.options.StaticHtmlOptionsProvider;
|
||||||
@ -77,11 +78,12 @@ public class OnlineGeneratorOptionsTest {
|
|||||||
{new PythonClientOptionsProvider()}, {new Qt5CPPOptionsProvider()},
|
{new PythonClientOptionsProvider()}, {new Qt5CPPOptionsProvider()},
|
||||||
{new RubyClientOptionsProvider()}, {new ScalaClientOptionsProvider()},
|
{new RubyClientOptionsProvider()}, {new ScalaClientOptionsProvider()},
|
||||||
{new ScalatraServerOptionsProvider()}, {new SilexServerOptionsProvider()},
|
{new ScalatraServerOptionsProvider()}, {new SilexServerOptionsProvider()},
|
||||||
{new SinatraServerOptionsProvider()}, {new SpringMVCServerOptionsProvider()},
|
{new SinatraServerOptionsProvider()}, {new SlimFrameworkServerOptionsProvider()},
|
||||||
{new StaticDocOptionsProvider()}, {new StaticHtmlOptionsProvider()},
|
{new SpringMVCServerOptionsProvider()}, {new StaticDocOptionsProvider()},
|
||||||
{new SwaggerOptionsProvider()}, {new SwaggerYamlOptionsProvider()},
|
{new StaticHtmlOptionsProvider()}, {new SwaggerOptionsProvider()},
|
||||||
{new SwiftOptionsProvider()}, {new TizenClientOptionsProvider()},
|
{new SwaggerYamlOptionsProvider()}, {new SwiftOptionsProvider()},
|
||||||
{new TypeScriptAngularClientOptionsProvider()}, {new TypeScriptNodeClientOptionsProvider()}
|
{new TizenClientOptionsProvider()}, {new TypeScriptAngularClientOptionsProvider()},
|
||||||
|
{new TypeScriptNodeClientOptionsProvider()}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
samples/server/petstore/slim/SwaggerServer/.htaccess
Normal file
5
samples/server/petstore/slim/SwaggerServer/.htaccess
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
RewriteEngine On
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
|
||||||
|
</IfModule>
|
10
samples/server/petstore/slim/SwaggerServer/README.md
Normal file
10
samples/server/petstore/slim/SwaggerServer/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# 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 [Slim Framework](http://www.slimframework.com/). To see how to make this your own, please take a look at the template here:
|
||||||
|
|
||||||
|
[TEMPLATES](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/slim/)
|
6
samples/server/petstore/slim/SwaggerServer/composer.json
Normal file
6
samples/server/petstore/slim/SwaggerServer/composer.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"minimum-stability": "RC",
|
||||||
|
"require": {
|
||||||
|
"slim/slim": "3.*"
|
||||||
|
}
|
||||||
|
}
|
336
samples/server/petstore/slim/SwaggerServer/index.php
Normal file
336
samples/server/petstore/slim/SwaggerServer/index.php
Normal file
@ -0,0 +1,336 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
$app = new Slim\App();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST createUser
|
||||||
|
* Summary: Create user
|
||||||
|
* Notes: This can only be done by the logged in user.
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/user', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing createUser as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST createUsersWithArrayInput
|
||||||
|
* Summary: Creates list of users with given input array
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/user/createWithArray', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing createUsersWithArrayInput as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST createUsersWithListInput
|
||||||
|
* Summary: Creates list of users with given input array
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/user/createWithList', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing createUsersWithListInput as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET loginUser
|
||||||
|
* Summary: Logs user into the system
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/user/login', function($request, $response, $args) {
|
||||||
|
|
||||||
|
$queryParams = $request->getQueryParams();
|
||||||
|
$username = $queryParams['username']; $password = $queryParams['password'];
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing loginUser as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET logoutUser
|
||||||
|
* Summary: Logs out current logged in user session
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/user/logout', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing logoutUser as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET getUserByName
|
||||||
|
* Summary: Get user by user name
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/user/{username}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing getUserByName as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT updateUser
|
||||||
|
* Summary: Updated user
|
||||||
|
* Notes: This can only be done by the logged in user.
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->PUT('/user/{username}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing updateUser as a PUT method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE deleteUser
|
||||||
|
* Summary: Delete user
|
||||||
|
* Notes: This can only be done by the logged in user.
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->DELETE('/user/{username}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing deleteUser as a DELETE method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET getInventory
|
||||||
|
* Summary: Returns pet inventories by status
|
||||||
|
* Notes: Returns a map of status codes to quantities
|
||||||
|
* Output-Formats: [application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/store/inventory', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing getInventory as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST placeOrder
|
||||||
|
* Summary: Place an order for a pet
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/store/order', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing placeOrder as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET getOrderById
|
||||||
|
* Summary: Find purchase order by ID
|
||||||
|
* Notes: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/store/order/{orderId}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing getOrderById as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE deleteOrder
|
||||||
|
* Summary: Delete purchase order by ID
|
||||||
|
* Notes: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->DELETE('/store/order/{orderId}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing deleteOrder as a DELETE method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT updatePet
|
||||||
|
* Summary: Update an existing pet
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->PUT('/pet', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing updatePet as a PUT method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST addPet
|
||||||
|
* Summary: Add a new pet to the store
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/pet', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$response->write('How about implementing addPet as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET findPetsByStatus
|
||||||
|
* Summary: Finds Pets by status
|
||||||
|
* Notes: Multiple status values can be provided with comma seperated strings
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/pet/findByStatus', function($request, $response, $args) {
|
||||||
|
|
||||||
|
$queryParams = $request->getQueryParams();
|
||||||
|
$status = $queryParams['status'];
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing findPetsByStatus as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET findPetsByTags
|
||||||
|
* Summary: Finds Pets by tags
|
||||||
|
* Notes: Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/pet/findByTags', function($request, $response, $args) {
|
||||||
|
|
||||||
|
$queryParams = $request->getQueryParams();
|
||||||
|
$tags = $queryParams['tags'];
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing findPetsByTags as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET getPetById
|
||||||
|
* Summary: Find pet by ID
|
||||||
|
* Notes: Returns a single pet
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->GET('/pet/{petId}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing getPetById as a GET method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST updatePetWithForm
|
||||||
|
* Summary: Updates a pet in the store with form data
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/pet/{petId}', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
$name = $args['name']; $status = $args['status'];
|
||||||
|
|
||||||
|
$response->write('How about implementing updatePetWithForm as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE deletePet
|
||||||
|
* Summary: Deletes a pet
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/xml, application/json]
|
||||||
|
*/
|
||||||
|
$app->DELETE('/pet/{petId}', function($request, $response, $args) {
|
||||||
|
$headers = $request->getHeaders();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response->write('How about implementing deletePet as a DELETE method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST uploadFile
|
||||||
|
* Summary: uploads an image
|
||||||
|
* Notes:
|
||||||
|
* Output-Formats: [application/json]
|
||||||
|
*/
|
||||||
|
$app->POST('/pet/{petId}/uploadImage', function($request, $response, $args) {
|
||||||
|
|
||||||
|
|
||||||
|
$additionalMetadata = $args['additionalMetadata']; $file = $args['file'];
|
||||||
|
|
||||||
|
$response->write('How about implementing uploadFile as a POST method ?');
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$app->run();
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* ApiResponse
|
||||||
|
*/
|
||||||
|
namespace SwaggerServer\lib\models;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ApiResponse
|
||||||
|
*/
|
||||||
|
class ApiResponse {
|
||||||
|
/* @var int $code */
|
||||||
|
private $code;
|
||||||
|
/* @var string $type */
|
||||||
|
private $type;
|
||||||
|
/* @var string $message */
|
||||||
|
private $message;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Category
|
||||||
|
*/
|
||||||
|
namespace SwaggerServer\lib\models;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Category
|
||||||
|
*/
|
||||||
|
class Category {
|
||||||
|
/* @var int $id */
|
||||||
|
private $id;
|
||||||
|
/* @var string $name */
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Order
|
||||||
|
*/
|
||||||
|
namespace SwaggerServer\lib\models;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Order
|
||||||
|
*/
|
||||||
|
class Order {
|
||||||
|
/* @var int $id */
|
||||||
|
private $id;
|
||||||
|
/* @var int $pet_id */
|
||||||
|
private $pet_id;
|
||||||
|
/* @var int $quantity */
|
||||||
|
private $quantity;
|
||||||
|
/* @var DateTime $ship_date */
|
||||||
|
private $ship_date;
|
||||||
|
/* @var string $status Order Status */
|
||||||
|
private $status;
|
||||||
|
/* @var boolean $complete */
|
||||||
|
private $complete;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Pet
|
||||||
|
*/
|
||||||
|
namespace SwaggerServer\lib\models;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pet
|
||||||
|
*/
|
||||||
|
class Pet {
|
||||||
|
/* @var int $id */
|
||||||
|
private $id;
|
||||||
|
/* @var Category $category */
|
||||||
|
private $category;
|
||||||
|
/* @var string $name */
|
||||||
|
private $name;
|
||||||
|
/* @var array[string] $photo_urls */
|
||||||
|
private $photo_urls;
|
||||||
|
/* @var array[Tag] $tags */
|
||||||
|
private $tags;
|
||||||
|
/* @var string $status pet status in the store */
|
||||||
|
private $status;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Tag
|
||||||
|
*/
|
||||||
|
namespace SwaggerServer\lib\models;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tag
|
||||||
|
*/
|
||||||
|
class Tag {
|
||||||
|
/* @var int $id */
|
||||||
|
private $id;
|
||||||
|
/* @var string $name */
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* User
|
||||||
|
*/
|
||||||
|
namespace SwaggerServer\lib\models;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* User
|
||||||
|
*/
|
||||||
|
class User {
|
||||||
|
/* @var int $id */
|
||||||
|
private $id;
|
||||||
|
/* @var string $username */
|
||||||
|
private $username;
|
||||||
|
/* @var string $first_name */
|
||||||
|
private $first_name;
|
||||||
|
/* @var string $last_name */
|
||||||
|
private $last_name;
|
||||||
|
/* @var string $email */
|
||||||
|
private $email;
|
||||||
|
/* @var string $password */
|
||||||
|
private $password;
|
||||||
|
/* @var string $phone */
|
||||||
|
private $phone;
|
||||||
|
/* @var int $user_status User Status */
|
||||||
|
private $user_status;
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user