### Getting Started example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore-security-test/javascript/README.md Example usage of the API client. ```javascript var SwaggerPetstoreEndRnNR = require('swagger_petstore____end____rn_n_r'); var api = new SwaggerPetstoreEndRnNR.FakeApi() var opts = { 'testCodeInjectEndRnNR': "testCodeInjectEndRnNR_example" // {String} To test code injection *_/ ' \" =end -- \\r\\n \\n \\r }; var callback = function(error, data, response) { if (error) { console.error(error); } else { console.log('API called successfully.'); } }; api.testCodeInjectEndRnNR(opts, callback); ``` -------------------------------- ### Run PHP Server Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/slim/vendor/slim/slim/example/README.md Start the PHP built-in server on localhost:8888, serving the example directory. ```text $ cd Slim $ php -S localhost:8888 -t example example/index.php ``` -------------------------------- ### Install Composer Dependencies Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/slim/vendor/slim/slim/example/README.md Run these commands in the Slim directory to install dependencies using Composer. ```text $ cd Slim $ composer install ``` -------------------------------- ### Run the server example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/rust-server/README.md Starts the server example. ```bash cargo run --example server ``` -------------------------------- ### Run the application with stack Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/haskell-http-client/example-app/README.md Use this command to run the example application after installing the Haskell stack tool and starting the petstore server. On the first run, stack installs GHC; after that, the --install-ghc flag can be omitted. ```bash stack --install-ghc exec swagger-petstore-app ``` -------------------------------- ### Clone the repository from GitHub Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Clone the repository using the provided Git URL. This is the first step in the installation process. ```bash $ git clone git@github.com:GIT_USER_ID/GIT_REPO_ID.git ``` -------------------------------- ### Install dependencies and run server Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/flaskConnexion-python2/README.md Execute from the root directory to install required packages and start the server. Then open the browser to the UI and Swagger definition URLs. ```bash pip install -r requirements.txt python -m swagger_server ``` ```text http://localhost:8080/v2/ui/ ``` ```text http://localhost:8080/v2/swagger.json ``` -------------------------------- ### Successful deployment output Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Example output of a successful deployment, showing the deployment status and build success. ```bash [sf:deploy] Request Status: Succeeded [sf:deploy] *********** DEPLOYMENT SUCCEEDED *********** [sf:deploy] Finished request 0Af7A00000Ebd5oSAB successfully. BUILD SUCCESSFUL Total time: 34 seconds ``` -------------------------------- ### Verify Ant installation with ant -version Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Run this command to confirm Apache Ant 1.6 or later is installed. Expected output shows version 1.10.1. ```bash Apache Ant(TM) version 1.10.1 compiled on February 2 2017 ``` -------------------------------- ### Run examples with cargo run Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/rust-server/README.md Use `cargo run --example ` to run any example. Pass arguments after `--`. ```bash cargo run --example ``` ```bash cargo run --example client -- --help ``` -------------------------------- ### Verify Java installation with java -version Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Run this command to confirm Java 8 JDK is installed and accessible. Expected output shows version 1.8.0_121. ```bash java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode) ``` -------------------------------- ### Run client examples Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/rust-server/README.md Runs various client examples for different endpoints. ```bash cargo run --example client TestSpecialTags ``` ```bash cargo run --example client FakeOuterBooleanSerialize ``` ```bash cargo run --example client FakeOuterCompositeSerialize ``` ```bash cargo run --example client FakeOuterNumberSerialize ``` ```bash cargo run --example client FakeOuterStringSerialize ``` ```bash cargo run --example client TestBodyWithQueryParams ``` ```bash cargo run --example client TestClientModel ``` ```bash cargo run --example client TestEndpointParameters ``` ```bash cargo run --example client TestEnumParameters ``` ```bash cargo run --example client TestInlineAdditionalProperties ``` ```bash cargo run --example client TestJsonFormData ``` ```bash cargo run --example client TestClassname ``` ```bash cargo run --example client AddPet ``` ```bash cargo run --example client DeletePet ``` ```bash cargo run --example client FindPetsByStatus ``` ```bash cargo run --example client FindPetsByTags ``` ```bash cargo run --example client GetPetById ``` ```bash cargo run --example client UpdatePet ``` ```bash cargo run --example client UpdatePetWithForm ``` ```bash cargo run --example client UploadFile ``` ```bash cargo run --example client DeleteOrder ``` ```bash cargo run --example client GetInventory ``` ```bash cargo run --example client GetOrderById ``` ```bash cargo run --example client PlaceOrder ``` ```bash cargo run --example client CreateUser ``` ```bash cargo run --example client CreateUsersWithArrayInput ``` ```bash cargo run --example client CreateUsersWithListInput ``` ```bash cargo run --example client DeleteUser ``` ```bash cargo run --example client GetUserByName ``` ```bash cargo run --example client LoginUser ``` ```bash cargo run --example client LogoutUser ``` ```bash cargo run --example client UpdateUser ``` -------------------------------- ### Install via setuptools Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/python/README.md Install the package using setuptools with the --user flag. Use sudo to install for all users. ```sh python setup.py install --user ``` -------------------------------- ### Getting started with PetApi.AddPet Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/csharp-dotnet2/SwaggerClientTest/Lib/SwaggerClient/README.md Example of adding a new pet to the store using the PetApi. Configure the OAuth2 access token for petstore_auth, create a Pet object, and call AddPet. The catch block prints any exception message. ```csharp using System; using System.Diagnostics; using IO.Swagger.Api; using IO.Swagger.Client; using IO.Swagger.Model; namespace Example { public class Example { public void main() { // Configure OAuth2 access token for authorization: petstore_auth Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; var apiInstance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store try { // Add a new pet to the store apiInstance.AddPet(body); } catch (Exception e) { Debug.Print("Exception when calling PetApi.AddPet: " + e.Message ); } } } } ``` -------------------------------- ### Run server example with HTTPS Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/rust-server/README.md Runs the server example in HTTPS mode using the `--https` flag. Uses keys/certificates from the examples directory; the server chain is signed with `CN=localhost`. ```bash cargo run --example server -- --https ``` -------------------------------- ### Run pod install Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/swift/promisekit/SwaggerClientTests/Pods/Alamofire/README.md Command to install the dependencies specified in the Podfile. ```bash $ pod install ``` -------------------------------- ### Create database and start Rails server Source: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/rails5/README.md Run these commands to set up the database and start the Rails server. The first command creates and migrates the database, the second starts the server. ```bash bin/rake db:create db:migrate ``` ```bash bin/rails s ``` -------------------------------- ### Install Carthage with Homebrew Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/swift/promisekit/SwaggerClientTests/Pods/Alamofire/README.md Commands to install Carthage, a decentralized dependency manager, using Homebrew. ```bash $ brew update $ brew install carthage ``` -------------------------------- ### GET /store/inventory Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/bash/docs/StoreApi.md Returns pet inventories by status. Returns a map of status codes to quantities. ```APIDOC ## GET /store/inventory ### Description Returns pet inventories by status. Returns a map of status codes to quantities. ### Method GET ### Endpoint /store/inventory ### Parameters This endpoint does not need any parameter. ### Request Example ```bash petstore-cli getInventory ``` ### Response #### Success Response - **map[String, integer]** - A map of status codes to quantities ### Authorization [api_key](../README.md#api_key) ### HTTP request headers - **Content-Type**: Not Applicable - **Accept**: application/json ``` -------------------------------- ### Build and install with Maven Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/java/okhttp4-gson/README.md Use `mvn clean install` to install the client library to your local Maven repository, or `mvn clean deploy` to deploy to a remote repository. `mvn clean package` generates the JAR for manual installation. ```shell mvn clean install ``` ```shell mvn clean deploy ``` ```shell mvn clean package ``` -------------------------------- ### Configure OAuth2 and add a pet with SWGPetApi Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Sets up the shared SWGDefaultConfiguration with an OAuth2 access token for the petstore_auth scheme, then calls addPetWithBody on SWGPetApi. The completion handler logs any error. Use this as a starting point after installation. ```objc SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig]; // Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth) [apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"]; SWGPet* *body = [[SWGPet alloc] init]; // Pet object that needs to be added to the store (optional) SWGPetApi *apiInstance = [[SWGPetApi alloc] init]; // Add a new pet to the store [apiInstance addPetWithBody:body completionHandler: ^(NSError* error) { if (error) { NSLog(@"Error: %@", error); } }]; ``` -------------------------------- ### Create user example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/python/docs/UserApi.md Example for creating a user. This can only be done by the logged in user. The example creates an instance of UserApi and calls create_user with a User object. ```python from __future__ import print_function import time import petstore_api from petstore_api.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() body = petstore_api.User() # User | Created user object try: # Create user api_instance.create_user(body) except ApiException as e: print("Exception when calling UserApi->create_user: %s\n" % e) ``` -------------------------------- ### Getting started example for FakeApi Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore-security-test/php/SwaggerClient-php/README.md Example usage of the FakeApi testCodeInjectEndRnNR method. Requires autoload.php and optionally a custom HTTP client implementing GuzzleHttp\ClientInterface; defaults to GuzzleHttp\Client. ```php testCodeInjectEndRnNR($test_code_inject____end____rn_n_r); } catch (Exception $e) { echo 'Exception when calling FakeApi->testCodeInjectEndRnNR: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Set JAVA_HOME on Windows Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Required environment variable for the Force.com Migration Tool. Set JAVA_HOME to the JDK installation path, e.g., C:\Program Files\Java\jdk1.8.0_121. ```plaintext JAVA_HOME = C:\Program Files\Java\jdk1.8.0_121 ``` -------------------------------- ### Generate dynamic HTML API documentation Source: https://github.com/swagger-api/swagger-codegen/blob/master/README.md Builds and serves dynamic HTML documentation generated with the -l dynamic-html flag. Requires npm install and then starts a Node.js server for AJAX calls. ```sh cd samples/dynamic-html/ npm install node . ``` -------------------------------- ### Implement the PetApiInterface Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md Shows how to implement the autogenerated PetApiInterface. Includes an example for setting the OAuth2 token and implementing the addPet operation. ```php new( ); my $test_code_inject_*/_'_"_=end____\r\n_\n_\r = 'test_code_inject_*/_'_"_=end____\r\n_\n_\r_example'; # string | To test code injection */ ' " =_end -- \r\n \n \r eval { $api_instance->test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r); }; if ($@) { warn "Exception when calling FakeApi->test_code_inject____end__rn_n_r: $@\n"; } ``` -------------------------------- ### Getting started with the Perl SDK Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore-security-test/perl/deep_module_test/README.md Place the SDK under the 'lib' folder and run this script to call the FakeApi test method. The example includes loading the API and model packages, setting up the API instance, and handling exceptions. ```perl #!/usr/bin/perl use lib 'lib'; use strict; use warnings; # load the API package use Something::Deep::FakeApi; # load the models use Something::Deep::Object::ModelReturn; # for displaying the API response data use Data::Dumper; use Something::Deep::; my $api_instance = Something::Deep::->new( ); my $test_code_inject_*/_'_"_=end____\r\n_\n_\r = 'test_code_inject_*/_'_"_=end____\r\n_\n_\r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r eval { $api_instance->test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r); }; if ($@) { warn "Exception when calling FakeApi->test_code_inject____end__rn_n_r: $@\n"; } ``` -------------------------------- ### Use Swagger Generator Docker image to generate a client Source: https://github.com/swagger-api/swagger-codegen/blob/master/docs/docker.md Starts the `swaggerapi/swagger-generator` container, waits for startup, gets its IP, posts a swaggerUrl to the API, downloads the generated zip, and stops the container. Assumes `jq` is installed. The result is saved as `result.zip`. ```sh # Start container and save the container id CID=$(docker run -d swaggerapi/swagger-generator) # allow for startup sleep 5 # Get the IP of the running container GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $CID) # Execute an HTTP request and store the download link RESULT=$(curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "swaggerUrl": "https://petstore.swagger.io/v2/swagger.json" }' 'http://localhost:8188/api/gen/clients/javascript' | jq '.link' | tr -d '"') # Download the generated zip and redirect to a file curl $RESULT > result.zip # Shutdown the swagger generator image docker stop $CID && docker rm $CID ``` -------------------------------- ### Generate Node.js server stub with Google Cloud Function support Source: https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO Generate a Node.js server stub with the additional property googleCloudFunctions=true to enable Google Cloud Function support. The linked quickstart guide is a good starting point for deploying the generated code. ```bash git clone https://github.com/swagger-api/swagger-codegen cd swagger-codegen mvn clean package java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i https://petstore.swagger.io/v2/swagger.json \ -l nodejs-server --additional-properties=googleCloudFunctions=true \ -o samples/server/petstore/nodejs-google-cloud-function ``` -------------------------------- ### Copy server example files into project Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/rust-server/README.md Copy the autogenerated server example files into your project's src directory. Run these commands from the project root after setting up the Rust project and configuring Cargo.toml. ```bash cp petstore_api/examples/server.rs src/main.rs cp petstore_api/examples/server_lib/mod.rs src/lib.rs cp petstore_api/examples/server_lib/server.rs src/server.rs ``` -------------------------------- ### CreateUser Example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/csharp/SwaggerClient/docs/UserApi.md Example of calling the CreateUser endpoint. This can only be done by the logged in user. The example creates a User object and passes it to the API method, catching any exceptions. ```csharp using System; using System.Diagnostics; using IO.Swagger.Api; using IO.Swagger.Client; using IO.Swagger.Model; namespace Example { public class CreateUserExample { public void main() { var apiInstance = new UserApi(); var body = new User(); // User | Created user object try { // Create user apiInstance.CreateUser(body); } catch (Exception e) { Debug.Print("Exception when calling UserApi.CreateUser: " + e.Message ); } } } } ``` -------------------------------- ### Install via Homebrew: brew install swagger-codegen Source: https://github.com/swagger-api/swagger-codegen/blob/master/docs/building.md Installs Swagger Codegen using Homebrew. Example usage generates a Ruby client from the Petstore API. ```sh brew install swagger-codegen ``` ```sh swagger-codegen generate -i https://petstore.swagger.io/v2/swagger.json -l ruby -o /tmp/test/ ``` -------------------------------- ### Install published package with npm install @swagger/typescript-fetch-petstore@1.0.0 --save Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/typescript-fetch/builds/es6-target/README.md Run this in your consuming project to install the published package. ```bash npm install @swagger/typescript-fetch-petstore@1.0.0 --save ``` -------------------------------- ### Install from git repository Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/javascript/README.md Install the library from a git repository. ```shell npm install GIT_USER_ID/GIT_REPO_ID --save ``` -------------------------------- ### GET /user/{username} Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Get user by user name. This endpoint retrieves a user by their username. ```APIDOC ## GET /user/{username} ### Description Get user by user name. ### Method GET ### Endpoint /user/{username} ### Parameters #### Path Parameters - **username** (string) - Required - The name that needs to be fetched ### Response #### Success Response Returns a User object. ``` -------------------------------- ### TestEnumParameters C# Example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md Example of calling the TestEnumParameters API method with all optional parameters. The method returns void and requires no authorization. The example includes parameter setup and exception handling. ```csharp using System; using System.Diagnostics; using IO.Swagger.Api; using IO.Swagger.Client; using IO.Swagger.Model; namespace Example { public class TestEnumParametersExample { public void main() { var apiInstance = new FakeApi(); var enumFormStringArray = enumFormStringArray_example; // List | Form parameter enum test (string array) (optional) var enumFormString = enumFormString_example; // string | Form parameter enum test (string) (optional) (default to -efg) var enumHeaderStringArray = enumHeaderStringArray_example; // List | Header parameter enum test (string array) (optional) var enumHeaderString = enumHeaderString_example; // string | Header parameter enum test (string) (optional) (default to -efg) var enumQueryStringArray = enumQueryStringArray_example; // List | Query parameter enum test (string array) (optional) var enumQueryString = enumQueryString_example; // string | Query parameter enum test (string) (optional) (default to -efg) var enumQueryInteger = 56; // int? | Query parameter enum test (double) (optional) var enumQueryDouble = 1.2; // double? | Query parameter enum test (double) (optional) try { // To test enum parameters apiInstance.TestEnumParameters(enumFormStringArray, enumFormString, enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble); } catch (Exception e) { Debug.Print("Exception when calling FakeApi.TestEnumParameters: " + e.Message ); } } } } ``` -------------------------------- ### Start the server with npm start Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/nodejs/README.md Run this command in the project root to start the generated Node.js server. The server listens on port 8080 by default. ```bash npm start ``` -------------------------------- ### GET /user/{username} Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Get user by user name. This endpoint is part of the SwagUserApi class. ```APIDOC ## [GET] /user/{username} ### Description Get user by user name. ### Method GET ### Endpoint /user/{username} ### Parameters #### Path Parameters - **username** (String) - Required - The name that needs to be fetched. Use user1 for testing. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **body** (SwagUser) - Successful operation #### Response Example ```json { "id": 0, "username": "string", "firstName": "string", "lastName": "string", "email": "string", "password": "string", "phone": "string", "userStatus": 0 } ``` ``` -------------------------------- ### Run the server Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/pistache-server/README.md Starts the compiled server from the build directory. ```bash cd build ./server ``` -------------------------------- ### Java example using PetApi Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/android/volley/README.md Example Java code that calls the PetApi addPet method. Requires the library to be installed. The Pet object is passed as the body parameter. ```java import io.swagger.client.api.PetApi; public class PetApiExample { public static void main(String[] args) { PetApi apiInstance = new PetApi(); Pet body = new Pet(); // Pet | Pet object that needs to be added to the store try { apiInstance.addPet(body); } catch (ApiException e) { System.err.println("Exception when calling PetApi#addPet"); e.printStackTrace(); } } } ``` -------------------------------- ### Run the Go API server Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/go-api-server/go/README.md Starts the generated Go server stub. Run this command from the project root after generating the server. ```bash go run main.go ``` -------------------------------- ### Java example for PetApi addPet Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/java/resteasy/README.md Example Java code that configures OAuth2 access token and calls PetApi.addPet. Requires the client library installed. ```java import io.swagger.client.*; import io.swagger.client.auth.*; import io.swagger.client.model.*; import io.swagger.client.api.PetApi; import java.io.File; import java.util.*; public class PetApiExample { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); // Configure OAuth2 access token for authorization: petstore_auth OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); PetApi apiInstance = new PetApi(); Pet body = new Pet(); // Pet | Pet object that needs to be added to the store try { apiInstance.addPet(body); } catch (ApiException e) { System.err.println("Exception when calling PetApi#addPet"); e.printStackTrace(); } } } ``` -------------------------------- ### Install dependencies and run the server Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/flaskConnexion/README.md Execute these commands from the root directory to install required packages and start the Flask server. Requires Python 3.5.2+. ```bash pip3 install -r requirements.txt python3 -m swagger_server ``` -------------------------------- ### Generate Java petstore sample client with bin script Source: https://github.com/swagger-api/swagger-codegen/blob/master/README.md Runs the bundled shell script to generate a Java client from the Swagger petstore sample. On Windows, use the .bat equivalent instead. ```sh ./bin/java-petstore.sh ``` -------------------------------- ### Generate PHP client from petstore (Windows) Source: https://github.com/swagger-api/swagger-codegen/blob/master/README.md Windows alternative to the Unix command, using backslashes in the JAR path and a Windows output directory. ```sh java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i https://petstore.swagger.io/v2/swagger.json -l php -o c:\temp\php_api_client ``` -------------------------------- ### Start the server with rackup Source: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/sinatra/README.md Command to start the Sinatra server on port 4567 using the config.ru file. ```bash rackup -p 4567 config.ru ``` -------------------------------- ### Build and test the library Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/kotlin/README.md Runs all tests and packages the library. Execute after creating the Gradle wrapper. ```bash ./gradlew check assemble ``` -------------------------------- ### placeOrder example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/kotlin/docs/StoreApi.md Places an order for a pet. No authorization required. ```kotlin // Import classes: //import io.swagger.client.infrastructure.* //import io.swagger.client.models.* val apiInstance = StoreApi() val body : Order = // Order | order placed for purchasing the pet try { val result : Order = apiInstance.placeOrder(body) println(result) } catch (e: ClientException) { println("4xx response calling StoreApi#placeOrder") e.printStackTrace() } catch (e: ServerException) { println("5xx response calling StoreApi#placeOrder") e.printStackTrace() } ``` -------------------------------- ### getPetById Usage Example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/default/docs/SWGPetApi.md Example of calling getPetById with API key and OAuth2 authentication setup. Configures the shared configuration, sets the pet ID, and invokes the API with a completion handler that logs the output or error. ```objc SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig]; // Configure API key authorization: (authentication scheme: api_key) [apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api_key"]; // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed //[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api_key"]; // Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth) [apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"]; NSNumber* petId = @789; // ID of pet that needs to be fetched SWGPetApi*apiInstance = [[SWGPetApi alloc] init]; // Find pet by ID [apiInstance getPetByIdWithPetId:petId completionHandler: ^(SWGPet* output, NSError* error) { if (output) { NSLog(@"%@", output); } if (error) { NSLog(@"Error calling SWGPetApi->getPetById: %@", error); } }]; ``` -------------------------------- ### deletePet usage example with OAuth2 setup Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/default/docs/SWGPetApi.md Example call to deletePet. Configures OAuth2 access token for petstore_auth authorization, sets petId and optional apiKey, then invokes the API with a completion handler that logs errors. ```objc SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig]; // Configure OAuth2 access token for authorization: (authentication scheme: petstore_auth) [apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"]; NSNumber* petId = @789; // Pet id to delete NSString* apiKey = @"apiKey_example"; // (optional) SWGPetApi*apiInstance = [[SWGPetApi alloc] init]; // Deletes a pet [apiInstance deletePetWithPetId:petId apiKey:apiKey completionHandler: ^(NSError* error) { if (error) { NSLog(@"Error calling SWGPetApi->deletePet: %@", error); } }]; ``` -------------------------------- ### API key authentication example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/rust/README.md Shows how to set an API key with optional prefix for the api_key authorization. ```go auth := context.WithValue(context.TODO(), sw.ContextAPIKey, sw.APIKey{ Key: "APIKEY", Prefix: "Bearer", // Omit if not necessary. }) r, err := client.Service.Operation(auth, args) ``` -------------------------------- ### Install with Maven Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/android/volley/README.md Run this command to install the API client library to your local Maven repository. ```shell mvn install ``` -------------------------------- ### Dispatch method return example for FOUND Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/slim/vendor/nikic/fast-route/README.md Shows the array returned by dispatch() when a route is found. The second element is the handler, the third is a dictionary of placeholder values. Example for GET /user/nikic/42. ```php /* Routing against GET /user/nikic/42 */ [FastRoute\Dispatcher::FOUND, 'handler0', ['name' => 'nikic', 'id' => '42']] ``` -------------------------------- ### Start Undertow server with Maven Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/undertow/README.md Run this command from the project root to start the Undertow server. It packages the application and executes the exec plugin. ```bash mvn package exec:exec ``` -------------------------------- ### placeOrder CLI example Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/bash/docs/StoreApi.md Places an order for a pet. The body parameter is an Order object. No authorization is required. ```bash petstore-cli placeOrder ``` -------------------------------- ### findPetsByStatus - Android Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/html2/index.html Android example for finding pets by status. This version does not include authentication setup. ```java import io.swagger.client.api.PetApi; public class PetApiExample { public static void main(String[] args) { PetApi apiInstance = new PetApi(); array[String] status = ; // array[String] | Status values that need to be considered for filter try { array[Pet] result = apiInstance.findPetsByStatus(status); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling PetApi#findPetsByStatus"); e.printStackTrace(); } } } ``` -------------------------------- ### GET /user/login Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Logs user into the system. This endpoint is part of the SwagUserApi class. ```APIDOC ## [GET] /user/login ### Description Logs user into the system. ### Method GET ### Endpoint /user/login ### Parameters #### Query Parameters - **username** (String) - Required - The user name for login - **password** (String) - Required - The password for login in clear text ### Request Example ```json {} ``` ### Response #### Success Response (200) - **body** (String) - Successful operation #### Response Example ```json "string" ``` ``` -------------------------------- ### Deploy to Salesforce org with ant deploy Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Deploys all classes, creates an unmanaged package, runs unit tests, and sets up a remote site. Requires SF_USERNAME and SF_PASSWORD environment variables or build.properties settings. Rolls back changes on error. ```bash $ ant deploy ``` -------------------------------- ### GET /pet/findByTags Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Finds Pets by tags. This endpoint is part of the SwagPetApi class. ```APIDOC ## [GET] /pet/findByTags ### Description Finds Pets by tags. ### Method GET ### Endpoint /pet/findByTags ### Parameters #### Query Parameters - **tags** (List) - Required - Tags to filter by ### Request Example ```json {} ``` ### Response #### Success Response (200) - **body** (List) - Successful operation #### Response Example ```json [ { "id": 0, "category": { "id": 0, "name": "string" }, "name": "doggie", "photoUrls": [ "string" ], "tags": [ { "id": 0, "name": "string" } ], "status": "available" } ] ``` ``` -------------------------------- ### Create index.php with Slim App Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/slim/vendor/slim/slim/README.md Create an index.php file with this content to set up a basic Slim application with a GET route. ```php get('/hello/{name}', function ($request, $response, $args) { $response->write("Hello, " . $args['name']); return $response; }); $app->run(); ``` -------------------------------- ### Start PHP development server Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/ze-ph/README.md Starts the PHP built-in development server with the public directory as webroot. Ensure rewrites are configured to ./public/index.php. ```bash php -S 0.0.0.0:8080 -t ./public ``` -------------------------------- ### GET /pet/findByStatus Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Finds Pets by status. This endpoint is part of the SwagPetApi class. ```APIDOC ## [GET] /pet/findByStatus ### Description Finds Pets by status. ### Method GET ### Endpoint /pet/findByStatus ### Parameters #### Query Parameters - **status** (List) - Required - Status values that need to be considered for filter ### Request Example ```json {} ``` ### Response #### Success Response (200) - **body** (List) - Successful operation #### Response Example ```json [ { "id": 0, "category": { "id": 0, "name": "string" }, "name": "doggie", "photoUrls": [ "string" ], "tags": [ { "id": 0, "name": "string" } ], "status": "available" } ] ``` ``` -------------------------------- ### Curl: loginUser Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/html2/index.html Calls the /user/login endpoint with GET. The username and password query parameters are empty in the example. ```bash curl -X GET "http://petstore.swagger.io/v2/user/login?username=&password=" ``` -------------------------------- ### Install dependencies locally Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/javascript/README.md Install dependencies for local development. ```shell npm install ``` -------------------------------- ### Install the API client library to local Maven repository Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/akka-scala/README.md Run this command to install the generated client library into your local Maven repository. Requires Java 1.7+ and Maven/Gradle/SBT. ```shell mvn clean install ``` -------------------------------- ### Debug print request with CustomDebugStringConvertible Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/swift3/default/SwaggerClientTests/Pods/Alamofire/README.md Use debugPrint to output a cURL command for the request. The example shows the output for a GET request with parameters. ```swift let request = Alamofire.request("https://httpbin.org/get", parameters: ["foo": "bar"]) debugPrint(request) ``` -------------------------------- ### GET /user/logout Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Logs out current logged in user session. This endpoint logs out the current user. ```APIDOC ## GET /user/logout ### Description Logs out current logged in user session. ### Method GET ### Endpoint /user/logout ### Response #### Success Response No response body is returned on success. ``` -------------------------------- ### Packaging with nuget pack Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/csharp/SwaggerClient/README.md Builds the .csproj directly to create a NuGet package, using placeholders from the .csproj. Output is placed in the 'out' directory. ```bash nuget pack -Build -OutputDirectory out IO.Swagger.csproj ``` -------------------------------- ### GET /user/login Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Logs user into the system. This endpoint authenticates a user and returns a session token. ```APIDOC ## GET /user/login ### Description Logs user into the system. ### Method GET ### Endpoint /user/login ### Parameters #### Query Parameters - **username** (string) - Required - The user name for login - **password** (string) - Required - The password for login in clear text ### Response #### Success Response Returns a string (session token). ``` -------------------------------- ### Install published package Source: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/README.md Navigate to your consuming project folder and run this command to install the published package. ```bash npm install additionalPropertiesTest@1.0.2 --save ``` -------------------------------- ### GET /store/inventory Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Returns pet inventories by status. This endpoint retrieves the inventory of pets by status. ```APIDOC ## GET /store/inventory ### Description Returns pet inventories by status. ### Method GET ### Endpoint /store/inventory ### Response #### Success Response Returns a map of status to quantity. ``` -------------------------------- ### GET /store/inventory Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Returns pet inventories by status. This endpoint is part of the SwagStoreApi class. ```APIDOC ## [GET] /store/inventory ### Description Returns pet inventories by status. ### Method GET ### Endpoint /store/inventory ### Parameters No parameters ### Request Example ```json {} ``` ### Response #### Success Response (200) - **body** (Map) - Successful operation #### Response Example ```json { "additionalProp1": 0, "additionalProp2": 0, "additionalProp3": 0 } ``` ``` -------------------------------- ### GET /pet/{petId} Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Find pet by ID. This endpoint is part of the SwagPetApi class. ```APIDOC ## [GET] /pet/{petId} ### Description Find pet by ID. ### Method GET ### Endpoint /pet/{petId} ### Parameters #### Path Parameters - **petId** (Long) - Required - ID of pet to return ### Request Example ```json {} ``` ### Response #### Success Response (200) - **body** (SwagPet) - Successful operation #### Response Example ```json { "id": 0, "category": { "id": 0, "name": "string" }, "name": "doggie", "photoUrls": [ "string" ], "tags": [ { "id": 0, "name": "string" } ], "status": "available" } ``` ``` -------------------------------- ### Generate PHP client from petstore (Unix) Source: https://github.com/swagger-api/swagger-codegen/blob/master/README.md Clones the repository, builds the project, and runs the CLI to generate a PHP client from the Petstore Swagger spec. Output is written to /var/tmp/php_api_client. ```sh git clone https://github.com/swagger-api/swagger-codegen cd swagger-codegen mvn clean package java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i https://petstore.swagger.io/v2/swagger.json \ -l php \ -o /var/tmp/php_api_client ``` -------------------------------- ### C# SDK example for UserApi.updateUser Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/html2/index.html C# client example that calls updateUser with a username and User body, printing exceptions. ```csharp using System; using System.Diagnostics; using IO.Swagger.Api; using IO.Swagger.Client; using IO.Swagger.Model; namespace Example { public class updateUserExample { public void main() { var apiInstance = new UserApi(); var username = username_example; // String | name that need to be deleted var body = new User(); // User | Updated user object try { // Updated user apiInstance.updateUser(username, body); } catch (Exception e) { Debug.Print("Exception when calling UserApi.updateUser: " + e.Message ); } } } } ``` -------------------------------- ### GET /store/order/{orderId} Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Find purchase order by ID. This endpoint retrieves an order based on its ID. ```APIDOC ## GET /store/order/{orderId} ### Description Find purchase order by ID. ### Method GET ### Endpoint /store/order/{orderId} ### Parameters #### Path Parameters - **orderId** (integer) - Required - ID of pet that needs to be fetched ### Response #### Success Response Returns an Order object. ``` -------------------------------- ### GET /pet/{petId} Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Find pet by ID. This endpoint retrieves a pet record based on its ID. ```APIDOC ## GET /pet/{petId} ### Description Find pet by ID. ### Method GET ### Endpoint /pet/{petId} ### Parameters #### Path Parameters - **petId** (integer) - Required - ID of pet to return ### Response #### Success Response Returns a Pet object. ``` -------------------------------- ### GET /pet/findByTags Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Finds Pets by tags. This endpoint returns a list of pets that match the given tags. ```APIDOC ## GET /pet/findByTags ### Description Finds Pets by tags. ### Method GET ### Endpoint /pet/findByTags ### Parameters #### Query Parameters - **tags** (array) - Required - Tags to filter by ### Response #### Success Response Returns an array of Pet objects. ``` -------------------------------- ### Run the server in Docker Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/kotlin-server/ktor/README.md Builds a Docker image and runs the server container, mapping port 8080. ```bash docker build -t kotlin-server . ``` ```bash docker run -p 8080:8080 kotlin-server ``` -------------------------------- ### GET /pet/findByStatus Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/objc/core-data/README.md Finds Pets by status. This endpoint returns a list of pets that match the given status. ```APIDOC ## GET /pet/findByStatus ### Description Finds Pets by status. ### Method GET ### Endpoint /pet/findByStatus ### Parameters #### Query Parameters - **status** (string) - Required - Status values that need to be considered for filter ### Response #### Success Response Returns an array of Pet objects. ``` -------------------------------- ### Typecheck, Build and run Unit tests Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/haskell-http-client/CONTRIBUTING.md Check that the following commands complete build without any errors. The commands clean stack work directories, run haddock and tests, then build example-app and tests-integration. ```bash (rm -Rf ./.stack-work ./example-app/.stack-work ./tests-integration/.stack-work); (stack haddock && stack test); (cd ./example-app; stack build); (cd ./tests-integration; stack build --no-run-tests); ``` -------------------------------- ### Run PHPUnit test suite Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/slim/vendor/slim/slim/README.md Execute the test suite using PHPUnit. ```bash $ phpunit ``` -------------------------------- ### GET /store/order/{orderId} Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md Find purchase order by ID. This endpoint retrieves an order based on its ID. ```APIDOC ## [GET] /store/order/{orderId} ### Description Find purchase order by ID. ### Method GET ### Endpoint /store/order/{orderId} ``` -------------------------------- ### GET /user/logout Source: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/apex/README.md Logs out current logged in user session. This endpoint is part of the SwagUserApi class. ```APIDOC ## [GET] /user/logout ### Description Logs out current logged in user session. ### Method GET ### Endpoint /user/logout ### Parameters No parameters ### Request Example ```json {} ``` ### Response #### Success Response (200) - No response body specified #### Response Example ```json {} ``` ```