618b4698c2
Conflicts: README.md bin/Version.scala build.sbt modules/swagger-codegen/src/main/resources/Java/api.mustache modules/swagger-codegen/src/main/resources/android-java/api.mustache modules/swagger-codegen/src/main/resources/nodejs/api.mustache modules/swagger-codegen/src/main/resources/objc/SWGApiClient.h modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m modules/swagger-codegen/src/main/resources/objc/SWGDate.h modules/swagger-codegen/src/main/resources/objc/SWGDate.m modules/swagger-codegen/src/main/resources/objc/SWGFile.m modules/swagger-codegen/src/main/resources/objc/SWGObject.h modules/swagger-codegen/src/main/resources/objc/SWGObject.m modules/swagger-codegen/src/main/resources/objc/api-header.mustache modules/swagger-codegen/src/main/resources/php/api.mustache modules/swagger-codegen/src/main/resources/python/api.mustache modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache modules/swagger-codegen/src/main/resources/scala/pom.mustache project/build.properties samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java samples/client/petstore/scala/pom.xml samples/client/petstore/scala/src/test/scala/PetApiTest.scala samples/client/petstore/scala/src/test/scala/StoreApiTest.scala samples/client/petstore/scala/src/test/scala/UserApiTest.scala samples/client/wordnik-apiobjc/client/SWGAccountApi.h samples/client/wordnik-apiobjc/client/SWGAccountApi.m samples/client/wordnik-apiobjc/client/SWGApiClient.h samples/client/wordnik-apiobjc/client/SWGApiClient.m samples/client/wordnik-apiobjc/client/SWGApiTokenStatus.h samples/client/wordnik-apiobjc/client/SWGAudioFile.h samples/client/wordnik-apiobjc/client/SWGAuthenticationToken.h samples/client/wordnik-apiobjc/client/SWGBigram.h samples/client/wordnik-apiobjc/client/SWGCitation.h samples/client/wordnik-apiobjc/client/SWGCitation.m samples/client/wordnik-apiobjc/client/SWGContentProvider.h samples/client/wordnik-apiobjc/client/SWGContentProvider.m samples/client/wordnik-apiobjc/client/SWGDate.h samples/client/wordnik-apiobjc/client/SWGDate.m samples/client/wordnik-apiobjc/client/SWGDefinition.h samples/client/wordnik-apiobjc/client/SWGDefinition.m samples/client/wordnik-apiobjc/client/SWGDefinitionSearchResults.h samples/client/wordnik-apiobjc/client/SWGDefinitionSearchResults.m samples/client/wordnik-apiobjc/client/SWGExample.h samples/client/wordnik-apiobjc/client/SWGExample.m samples/client/wordnik-apiobjc/client/SWGExampleSearchResults.h samples/client/wordnik-apiobjc/client/SWGExampleSearchResults.m samples/client/wordnik-apiobjc/client/SWGExampleUsage.h samples/client/wordnik-apiobjc/client/SWGExampleUsage.m samples/client/wordnik-apiobjc/client/SWGFacet.h samples/client/wordnik-apiobjc/client/SWGFacet.m samples/client/wordnik-apiobjc/client/SWGFacetValue.h samples/client/wordnik-apiobjc/client/SWGFacetValue.m samples/client/wordnik-apiobjc/client/SWGFile.h samples/client/wordnik-apiobjc/client/SWGFile.m samples/client/wordnik-apiobjc/client/SWGFrequency.h samples/client/wordnik-apiobjc/client/SWGFrequency.m samples/client/wordnik-apiobjc/client/SWGFrequencySummary.h samples/client/wordnik-apiobjc/client/SWGFrequencySummary.m samples/client/wordnik-apiobjc/client/SWGLabel.h samples/client/wordnik-apiobjc/client/SWGLabel.m samples/client/wordnik-apiobjc/client/SWGNote.h samples/client/wordnik-apiobjc/client/SWGObject.h samples/client/wordnik-apiobjc/client/SWGObject.m samples/client/wordnik-apiobjc/client/SWGRelated.h samples/client/wordnik-apiobjc/client/SWGScoredWord.h samples/client/wordnik-apiobjc/client/SWGSentence.h samples/client/wordnik-apiobjc/client/SWGSentence.m samples/client/wordnik-apiobjc/client/SWGSimpleDefinition.h samples/client/wordnik-apiobjc/client/SWGSimpleExample.h samples/client/wordnik-apiobjc/client/SWGStringValue.h samples/client/wordnik-apiobjc/client/SWGStringValue.m samples/client/wordnik-apiobjc/client/SWGSyllable.h samples/client/wordnik-apiobjc/client/SWGTextPron.h samples/client/wordnik-apiobjc/client/SWGUser.h samples/client/wordnik-apiobjc/client/SWGWordApi.h samples/client/wordnik-apiobjc/client/SWGWordList.h samples/client/wordnik-apiobjc/client/SWGWordList.m samples/client/wordnik-apiobjc/client/SWGWordListApi.h samples/client/wordnik-apiobjc/client/SWGWordListApi.m samples/client/wordnik-apiobjc/client/SWGWordListWord.h samples/client/wordnik-apiobjc/client/SWGWordListsApi.h samples/client/wordnik-apiobjc/client/SWGWordListsApi.m samples/client/wordnik-apiobjc/client/SWGWordObject.h samples/client/wordnik-apiobjc/client/SWGWordOfTheDay.h samples/client/wordnik-apiobjc/client/SWGWordOfTheDay.m samples/client/wordnik-apiobjc/client/SWGWordSearchResult.h samples/client/wordnik-apiobjc/client/SWGWordSearchResults.h samples/client/wordnik-apiobjc/client/SWGWordSearchResults.m samples/client/wordnik-apiobjc/client/SWGWordsApi.h samples/client/wordnik-apiobjc/client/SWGWordsApi.m samples/client/wordnik-api-objc/Podfile samples/client/wordnik-api-objc/client/SWGAccountApi.h samples/client/wordnik-api-objc/client/SWGAccountApi.m samples/client/wordnik-api-objc/client/SWGApiClient.h samples/client/wordnik-api-objc/client/SWGApiClient.m samples/client/wordnik-api-objc/client/SWGApiTokenStatus.h samples/client/wordnik-api-objc/client/SWGApiTokenStatus.m samples/client/wordnik-api-objc/client/SWGAudioFile.h samples/client/wordnik-api-objc/client/SWGAudioFile.m samples/client/wordnik-api-objc/client/SWGAuthenticationToken.h samples/client/wordnik-api-objc/client/SWGAuthenticationToken.m samples/client/wordnik-api-objc/client/SWGBigram.h samples/client/wordnik-api-objc/client/SWGBigram.m samples/client/wordnik-api-objc/client/SWGCitation.h samples/client/wordnik-api-objc/client/SWGCitation.m samples/client/wordnik-api-objc/client/SWGContentProvider.h samples/client/wordnik-api-objc/client/SWGContentProvider.m samples/client/wordnik-api-objc/client/SWGDate.h samples/client/wordnik-api-objc/client/SWGDate.m samples/client/wordnik-api-objc/client/SWGDefinition.h samples/client/wordnik-api-objc/client/SWGDefinition.m samples/client/wordnik-api-objc/client/SWGDefinitionSearchResults.h samples/client/wordnik-api-objc/client/SWGDefinitionSearchResults.m samples/client/wordnik-api-objc/client/SWGExample.h samples/client/wordnik-api-objc/client/SWGExample.m samples/client/wordnik-api-objc/client/SWGExampleSearchResults.h samples/client/wordnik-api-objc/client/SWGExampleSearchResults.m samples/client/wordnik-api-objc/client/SWGExampleUsage.h samples/client/wordnik-api-objc/client/SWGExampleUsage.m samples/client/wordnik-api-objc/client/SWGFacet.h samples/client/wordnik-api-objc/client/SWGFacet.m samples/client/wordnik-api-objc/client/SWGFacetValue.h samples/client/wordnik-api-objc/client/SWGFacetValue.m samples/client/wordnik-api-objc/client/SWGFile.h samples/client/wordnik-api-objc/client/SWGFile.m samples/client/wordnik-api-objc/client/SWGFrequency.h samples/client/wordnik-api-objc/client/SWGFrequency.m samples/client/wordnik-api-objc/client/SWGFrequencySummary.h samples/client/wordnik-api-objc/client/SWGFrequencySummary.m samples/client/wordnik-api-objc/client/SWGLabel.h samples/client/wordnik-api-objc/client/SWGLabel.m samples/client/wordnik-api-objc/client/SWGNote.h samples/client/wordnik-api-objc/client/SWGNote.m samples/client/wordnik-api-objc/client/SWGObject.h samples/client/wordnik-api-objc/client/SWGObject.m samples/client/wordnik-api-objc/client/SWGRelated.h samples/client/wordnik-api-objc/client/SWGRelated.m samples/client/wordnik-api-objc/client/SWGScoredWord.h samples/client/wordnik-api-objc/client/SWGScoredWord.m samples/client/wordnik-api-objc/client/SWGScrabbleScoreResult.h samples/client/wordnik-api-objc/client/SWGScrabbleScoreResult.m samples/client/wordnik-api-objc/client/SWGSentence.h samples/client/wordnik-api-objc/client/SWGSentence.m samples/client/wordnik-api-objc/client/SWGSimpleDefinition.h samples/client/wordnik-api-objc/client/SWGSimpleDefinition.m samples/client/wordnik-api-objc/client/SWGSimpleExample.h samples/client/wordnik-api-objc/client/SWGSimpleExample.m samples/client/wordnik-api-objc/client/SWGStringValue.h samples/client/wordnik-api-objc/client/SWGStringValue.m samples/client/wordnik-api-objc/client/SWGSyllable.h samples/client/wordnik-api-objc/client/SWGSyllable.m samples/client/wordnik-api-objc/client/SWGTextPron.h samples/client/wordnik-api-objc/client/SWGTextPron.m samples/client/wordnik-api-objc/client/SWGUser.h samples/client/wordnik-api-objc/client/SWGUser.m samples/client/wordnik-api-objc/client/SWGWordApi.h samples/client/wordnik-api-objc/client/SWGWordApi.m samples/client/wordnik-api-objc/client/SWGWordList.h samples/client/wordnik-api-objc/client/SWGWordList.m samples/client/wordnik-api-objc/client/SWGWordListApi.h samples/client/wordnik-api-objc/client/SWGWordListApi.m samples/client/wordnik-api-objc/client/SWGWordListWord.h samples/client/wordnik-api-objc/client/SWGWordListWord.m samples/client/wordnik-api-objc/client/SWGWordListsApi.h samples/client/wordnik-api-objc/client/SWGWordListsApi.m samples/client/wordnik-api-objc/client/SWGWordObject.h samples/client/wordnik-api-objc/client/SWGWordObject.m samples/client/wordnik-api-objc/client/SWGWordOfTheDay.h samples/client/wordnik-api-objc/client/SWGWordOfTheDay.m samples/client/wordnik-api-objc/client/SWGWordSearchResult.h samples/client/wordnik-api-objc/client/SWGWordSearchResult.m samples/client/wordnik-api-objc/client/SWGWordSearchResults.h samples/client/wordnik-api-objc/client/SWGWordSearchResults.m samples/client/wordnik-api-objc/client/SWGWordsApi.h samples/client/wordnik-api-objc/client/SWGWordsApi.m samples/client/wordnik-api-php/wordnik/AccountApi.php samples/client/wordnik-api/scala/src/test/scala/AccountApiTest.scala samples/client/wordnik-api/scala/src/test/scala/WordApiTest.scala samples/client/wordnik-api/scala/src/test/scala/WordListApiTest.scala samples/client/wordnik-api/scala/src/test/scala/WordsApiTest.scala samples/client/wordnik/objc/client/SWGAccountApi.h samples/client/wordnik/objc/client/SWGAccountApi.m samples/client/wordnik/objc/client/SWGApiTokenStatus.h samples/client/wordnik/objc/client/SWGAudioFile.h samples/client/wordnik/objc/client/SWGAuthenticationToken.h samples/client/wordnik/objc/client/SWGBigram.h samples/client/wordnik/objc/client/SWGCitation.h samples/client/wordnik/objc/client/SWGCitation.m samples/client/wordnik/objc/client/SWGContentProvider.h samples/client/wordnik/objc/client/SWGContentProvider.m samples/client/wordnik/objc/client/SWGDefinition.h samples/client/wordnik/objc/client/SWGDefinition.m samples/client/wordnik/objc/client/SWGDefinitionSearchResults.h samples/client/wordnik/objc/client/SWGDefinitionSearchResults.m samples/client/wordnik/objc/client/SWGExample.h samples/client/wordnik/objc/client/SWGExample.m samples/client/wordnik/objc/client/SWGExampleSearchResults.h samples/client/wordnik/objc/client/SWGExampleSearchResults.m samples/client/wordnik/objc/client/SWGExampleUsage.h samples/client/wordnik/objc/client/SWGExampleUsage.m samples/client/wordnik/objc/client/SWGFacet.h samples/client/wordnik/objc/client/SWGFacet.m samples/client/wordnik/objc/client/SWGFacetValue.h samples/client/wordnik/objc/client/SWGFacetValue.m samples/client/wordnik/objc/client/SWGFile.h samples/client/wordnik/objc/client/SWGFrequency.h samples/client/wordnik/objc/client/SWGFrequency.m samples/client/wordnik/objc/client/SWGFrequencySummary.h samples/client/wordnik/objc/client/SWGFrequencySummary.m samples/client/wordnik/objc/client/SWGLabel.h samples/client/wordnik/objc/client/SWGLabel.m samples/client/wordnik/objc/client/SWGNote.h samples/client/wordnik/objc/client/SWGRelated.h samples/client/wordnik/objc/client/SWGScoredWord.h samples/client/wordnik/objc/client/SWGSentence.h samples/client/wordnik/objc/client/SWGSentence.m samples/client/wordnik/objc/client/SWGSimpleDefinition.h samples/client/wordnik/objc/client/SWGSimpleExample.h samples/client/wordnik/objc/client/SWGStringValue.h samples/client/wordnik/objc/client/SWGStringValue.m samples/client/wordnik/objc/client/SWGSyllable.h samples/client/wordnik/objc/client/SWGTextPron.h samples/client/wordnik/objc/client/SWGUser.h samples/client/wordnik/objc/client/SWGWordApi.h samples/client/wordnik/objc/client/SWGWordList.h samples/client/wordnik/objc/client/SWGWordList.m samples/client/wordnik/objc/client/SWGWordListApi.h samples/client/wordnik/objc/client/SWGWordListApi.m samples/client/wordnik/objc/client/SWGWordListWord.h samples/client/wordnik/objc/client/SWGWordListsApi.h samples/client/wordnik/objc/client/SWGWordListsApi.m samples/client/wordnik/objc/client/SWGWordObject.h samples/client/wordnik/objc/client/SWGWordOfTheDay.h samples/client/wordnik/objc/client/SWGWordOfTheDay.m samples/client/wordnik/objc/client/SWGWordSearchResult.h samples/client/wordnik/objc/client/SWGWordSearchResults.h samples/client/wordnik/objc/client/SWGWordSearchResults.m samples/client/wordnik/objc/client/SWGWordsApi.h samples/client/wordnik/objc/client/SWGWordsApi.m samples/server-generator/node/README.md samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Pet.java samples/server/petstore/nodejs/app/apis/PetApi.js samples/server/petstore/nodejs/app/apis/StoreApi.js samples/server/petstore/nodejs/app/apis/UserApi.js sbt src/main/resources/objc/api-body.mustache src/main/resources/php/Swagger.mustache src/main/resources/python/swagger.mustache src/main/scala/com/wordnik/swagger/codegen/BasicAndroidJavaClient.scala src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala src/main/scala/com/wordnik/swagger/codegen/BasicPythonGenerator.scala src/main/scala/com/wordnik/swagger/codegen/BasicScalaGenerator.scala src/main/scala/com/wordnik/swagger/codegen/Codegen.scala src/main/scala/com/wordnik/swagger/codegen/ScalaAsyncClientGenerator.scala src/main/scala/com/wordnik/swagger/codegen/model/AuthorizationModels.scala src/main/scala/com/wordnik/swagger/codegen/spec/SwaggerSpecValidator.scala src/main/scala/com/wordnik/swagger/codegen/util/RemoteUrl.scala src/test/scala/CodegenTest.scala |
||
---|---|---|
.. | ||
README.md |
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:
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** swagger 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
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 templates and are easy to modify. Take a look at the sample templates here:
Sound easy? It is!