[cpp][tiny] rename generator, update samples (#9560)

* rename generator, update samples

* add doc

* update readme
This commit is contained in:
William Cheng 2021-05-25 23:55:16 +08:00 committed by GitHub
parent 6c40192706
commit ae430a8c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 5070 additions and 38 deletions

View File

@ -67,7 +67,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
| | Languages/Frameworks |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.0, .NET Core 2.0, .NET 5.0. Libraries: RestSharp, HttpClient), **C++** (cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client), **k6**, **Kotlin**, **Lua**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (2.x - 11.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs) |
| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.0, .NET Core 2.0, .NET 5.0. Libraries: RestSharp, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client), **k6**, **Kotlin**, **Lua**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (2.x - 11.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs) |
| **Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/)), **Kotlin** (Spring Boot, Ktor, Vertx), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), Scalatra) |
| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** |
| **Configuration files** | [**Apache2**](https://httpd.apache.org/) |
@ -843,6 +843,7 @@ Here is a list of template creators:
* Bash: @bkryza
* C: @PowerOfCreation @zhemant [:heart:](https://www.patreon.com/zhemant)
* C++ REST: @Danielku15
* C++ Tiny: @AndersSpringborg
* C++ UE4: @Kahncode
* C# (.NET 2.0): @who
* C# (.NET Standard 1.3 ): @Gronsak

View File

@ -1,7 +1,7 @@
generatorName: tiny-cpp
outputDir: samples/client/petstore/tiny/cpp
generatorName: cpp-tiny
outputDir: samples/client/petstore/cpp-tiny
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/tiny-cpp-client
templateDir: modules/openapi-generator/src/main/resources/cpp-tiny
additionalProperties:
hideGenerationTimestamp: "true"
controller: "esp32"

View File

@ -14,6 +14,7 @@ The following generators are available:
* [clojure](generators/clojure.md)
* [cpp-qt-client](generators/cpp-qt-client.md)
* [cpp-restsdk](generators/cpp-restsdk.md)
* [cpp-tiny (beta)](generators/cpp-tiny.md)
* [cpp-tizen](generators/cpp-tizen.md)
* [cpp-ue4 (beta)](generators/cpp-ue4.md)
* [crystal (beta)](generators/crystal.md)

243
docs/generators/cpp-tiny.md Normal file
View File

@ -0,0 +1,243 @@
---
title: Config Options for cpp-tiny
sidebar_label: cpp-tiny
---
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|controller|name of microcontroller (e.g esp32 or esp8266)| |esp32|
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|variableNameFirstCharacterUppercase|Make first character of variable name uppercase (eg. value -&gt; Value)| |true|
## IMPORT MAPPING
| Type/Alias | Imports |
| ---------- | ------- |
## INSTANTIATION TYPES
| Type/Alias | Instantiated By |
| ---------- | --------------- |
## LANGUAGE PRIMITIVES
<ul class="column-ul">
<li>bool</li>
<li>double</li>
<li>float</li>
<li>int</li>
<li>long</li>
<li>std::string</li>
</ul>
## RESERVED WORDS
<ul class="column-ul">
<li>alignas</li>
<li>alignof</li>
<li>and</li>
<li>and_eq</li>
<li>asm</li>
<li>auto</li>
<li>bitand</li>
<li>bitor</li>
<li>bool</li>
<li>break</li>
<li>case</li>
<li>catch</li>
<li>char</li>
<li>char16_t</li>
<li>char32_t</li>
<li>class</li>
<li>compl</li>
<li>concept</li>
<li>const</li>
<li>const_cast</li>
<li>constexpr</li>
<li>continue</li>
<li>decltype</li>
<li>default</li>
<li>delete</li>
<li>do</li>
<li>double</li>
<li>dynamic_cast</li>
<li>else</li>
<li>enum</li>
<li>explicit</li>
<li>export</li>
<li>extern</li>
<li>false</li>
<li>float</li>
<li>for</li>
<li>friend</li>
<li>goto</li>
<li>if</li>
<li>inline</li>
<li>int</li>
<li>linux</li>
<li>long</li>
<li>mutable</li>
<li>namespace</li>
<li>new</li>
<li>noexcept</li>
<li>not</li>
<li>not_eq</li>
<li>nullptr</li>
<li>operator</li>
<li>or</li>
<li>or_eq</li>
<li>private</li>
<li>protected</li>
<li>public</li>
<li>register</li>
<li>reinterpret_cast</li>
<li>requires</li>
<li>return</li>
<li>short</li>
<li>signed</li>
<li>sizeof</li>
<li>static</li>
<li>static_assert</li>
<li>static_cast</li>
<li>struct</li>
<li>switch</li>
<li>template</li>
<li>this</li>
<li>thread_local</li>
<li>throw</li>
<li>true</li>
<li>try</li>
<li>typedef</li>
<li>typeid</li>
<li>typename</li>
<li>union</li>
<li>unsigned</li>
<li>using</li>
<li>virtual</li>
<li>void</li>
<li>volatile</li>
<li>wchar_t</li>
<li>while</li>
<li>xor</li>
<li>xor_eq</li>
</ul>
## FEATURE SET
### Client Modification Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasePath|✗|ToolingExtension
|Authorizations|✗|ToolingExtension
|UserAgent|✗|ToolingExtension
|MockServer|✗|ToolingExtension
### Data Type Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Custom|✗|OAS2,OAS3
|Int32|✓|OAS2,OAS3
|Int64|✓|OAS2,OAS3
|Float|✓|OAS2,OAS3
|Double|✓|OAS2,OAS3
|Decimal|✓|ToolingExtension
|String|✓|OAS2,OAS3
|Byte|✓|OAS2,OAS3
|Binary|✓|OAS2,OAS3
|Boolean|✓|OAS2,OAS3
|Date|✓|OAS2,OAS3
|DateTime|✓|OAS2,OAS3
|Password|✓|OAS2,OAS3
|File|✓|OAS2
|Array|✓|OAS2,OAS3
|Maps|✗|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✗|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|ArrayOfCollectionOfModel|✓|ToolingExtension
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|MapOfEnum|✗|ToolingExtension
|MapOfModel|✗|ToolingExtension
|MapOfCollectionOfPrimitives|✗|ToolingExtension
|MapOfCollectionOfModel|✗|ToolingExtension
|MapOfCollectionOfEnum|✗|ToolingExtension
### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme|✓|ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension
### Global Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Host|✓|OAS2,OAS3
|BasePath|✓|OAS2,OAS3
|Info|✓|OAS2,OAS3
|Schemes|✗|OAS2,OAS3
|PartialSchemes|✓|OAS2,OAS3
|Consumes|✓|OAS2
|Produces|✓|OAS2
|ExternalDocumentation|✓|OAS2,OAS3
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✗|OAS3
|LinkObjects|✗|OAS3
### Parameter Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Path|✓|OAS2,OAS3
|Query|✗|OAS2,OAS3
|Header|✗|OAS2,OAS3
|Body|✓|OAS2
|FormUnencoded|✗|OAS2
|FormMultipart|✗|OAS2
|Cookie|✗|OAS3
### Schema Support Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism|✗|OAS2,OAS3
|Union|✗|OAS3
### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✓|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken|✓|OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✓|OAS2,OAS3
|OAuth2_ClientCredentials|✓|OAS2,OAS3
|OAuth2_AuthorizationCode|✓|OAS2,OAS3
### Wire Format Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML|✗|OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✗|OAS2,OAS3

View File

@ -1,9 +1,28 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.languages;
import org.openapitools.codegen.*;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.utils.ModelUtils;
import java.io.File;
@ -14,10 +33,10 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenConfig {
public class CppTinyClientCodegen extends AbstractCppCodegen implements CodegenConfig {
public static final String PROJECT_NAME = "TinyClient";
static final Logger LOGGER = LoggerFactory.getLogger(TinyCppClientCodegen.class);
static final Logger LOGGER = LoggerFactory.getLogger(CppTinyClientCodegen.class);
public static final String MICROCONTROLLER = "controller";
public static final String rootFolder = "";
@ -35,7 +54,7 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
* @return the friendly name for the generator
*/
public String getName() {
return "tiny-cpp";
return "cpp-tiny";
}
/**
@ -45,7 +64,7 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
* @return A string value for the help message
*/
public String getHelp() {
return "Generates a Arduino rest client.";
return "Generates a C++ Arduino REST API client.";
}
public void addControllerToAdditionalProperties() {
@ -55,8 +74,7 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
}};
if (supportedControllers.containsKey(controller)) {
additionalProperties.put(supportedControllers.get(controller), true);
}
else {
} else {
//String msg = String.format("The specified controller: %s is not supported.\nSupported controllers are: %s",
// controller,
// supportedControllers.keySet());
@ -64,7 +82,7 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
}
}
public TinyCppClientCodegen() {
public CppTinyClientCodegen() {
super();
modifyFeatureSet(feature -> feature
@ -103,8 +121,12 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
DocumentationFeature.Readme
));
outputFolder = "generated-code" + File.separator + "tiny-cpp";
embeddedTemplateDir = templateDir = "tiny-cpp-client";
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
.stability(Stability.BETA)
.build();
outputFolder = "generated-code" + File.separator + "cpp-tiny";
embeddedTemplateDir = templateDir = "cpp-tiny";
String libFolder = "lib";
// MODELS
@ -122,7 +144,7 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
supportingFiles.add(new SupportingFile("run-tests.mustache", "test", "RunTests.cpp"));
// SERVICES
apiPackage = TinyCppClientCodegen.libFolder + File.separator + "service";
apiPackage = CppTinyClientCodegen.libFolder + File.separator + "service";
apiTemplateFiles.put("service/api-header.mustache".replace('/', File.separatorChar), ".h");
apiTemplateFiles.put("service/api-body.mustache".replace('/', File.separatorChar), ".cpp");
@ -131,9 +153,8 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
supportingFiles.add(new SupportingFile("service/AbstractService.h.mustache", serviceFolder, "AbstractService.h"));
supportingFiles.add(new SupportingFile("service/AbstractService.cpp.mustache", serviceFolder, "AbstractService.cpp"));
// Main
supportingFiles.add(new SupportingFile("main.mustache", TinyCppClientCodegen.sourceFolder, "main.cpp"));
supportingFiles.add(new SupportingFile("main.mustache", CppTinyClientCodegen.sourceFolder, "main.cpp"));
// Config files
supportingFiles.add(new SupportingFile("README.mustache", rootFolder, "README.md"));
@ -142,8 +163,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
supportingFiles.add(new SupportingFile("README.mustache", rootFolder, "README.md"));
supportingFiles.add(new SupportingFile("pre_compiling_bourne.py.mustache", rootFolder, "pre_compiling_bourne.py"));
defaultIncludes = new HashSet<String>(
Arrays.asList(
"bool",
@ -162,10 +181,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
"std::string")
);
super.typeMapping = new HashMap<String, String>();
typeMapping.put("string", "std::string");
typeMapping.put("integer", "int");
@ -180,7 +195,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
}
// FilePaths
private static final String sourceFolder = "src";
private static final String libFolder = "lib";
@ -213,8 +227,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
typeMapping.put("URI", "std::string");
}
@Override
public void processOpts() {
super.processOpts();
@ -230,7 +242,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
LOGGER.info("Generator targeting the following microcontroller: {}", controller);
}
@Override
public String toInstantiationType(Schema p) {
if (ModelUtils.isArraySchema(p)) {
@ -240,7 +251,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
}
}
@Override
public String getTypeDeclaration(Schema p) {
String openAPIType = getSchemaType(p);
@ -251,7 +261,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
}
}
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
@ -291,8 +300,6 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
return "#include \"" + name + ".h\"";
}
@Override
public String toApiImport(String name) {
return super.toApiImport(name);
@ -333,6 +340,4 @@ public class TinyCppClientCodegen extends AbstractCppCodegen implements CodegenC
}
}

View File

@ -16,6 +16,7 @@ org.openapitools.codegen.languages.CppQtQHttpEngineServerCodegen
org.openapitools.codegen.languages.CppPistacheServerCodegen
org.openapitools.codegen.languages.CppRestbedServerCodegen
org.openapitools.codegen.languages.CppRestSdkClientCodegen
org.openapitools.codegen.languages.CppTinyClientCodegen
org.openapitools.codegen.languages.CppTizenClientCodegen
org.openapitools.codegen.languages.CppUE4ClientCodegen
org.openapitools.codegen.languages.CSharpClientCodegen
@ -132,5 +133,4 @@ org.openapitools.codegen.languages.TypeScriptNestjsClientCodegen
org.openapitools.codegen.languages.TypeScriptNodeClientCodegen
org.openapitools.codegen.languages.TypeScriptReduxQueryClientCodegen
org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen
org.openapitools.codegen.languages.TinyCppClientCodegen
org.openapitools.codegen.languages.GoEchoServerCodegen

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1,30 @@
README.md
README.md
lib/Models/ApiResponse.cpp
lib/Models/ApiResponse.h
lib/Models/Category.cpp
lib/Models/Category.h
lib/Models/Helpers.cpp
lib/Models/Helpers.h
lib/Models/Order.cpp
lib/Models/Order.h
lib/Models/Pet.cpp
lib/Models/Pet.h
lib/Models/Tag.cpp
lib/Models/Tag.h
lib/Models/User.cpp
lib/Models/User.h
lib/service/AbstractService.cpp
lib/service/AbstractService.h
lib/service/PetApi.cpp
lib/service/PetApi.h
lib/service/Response.h
lib/service/StoreApi.cpp
lib/service/StoreApi.h
lib/service/UserApi.cpp
lib/service/UserApi.h
platformio.ini
pre_compiling_bourne.py
root.cert
src/main.cpp
test/RunTests.cpp

View File

@ -0,0 +1 @@
5.2.0-SNAPSHOT

View File

@ -0,0 +1,73 @@
# Documentation for OpenAPI Petstore
This is a client generator for microcontrollers on the Espressif32 platform and the Arduino framework
After the client have been generated, you have to change these following variablies:
- root.cert | Provide your service root certificate.
- src/main.cpp | Change wifi name
- src/main.cpp | Change wifi password
- lib/service/AbstractService.h | Change to your url
# Documentation for OpenAPI Petstore 1.0.0 Tiny client cpp (Arduino)
The project is structured like this:
```
samples/client/petstore/tiny/cpp/
├── lib
│ ├── Models
│ ├── service
│ └── TestFiles
├── platformio.ini
├── pre_compiling_bourne.py
├── README.md
├── root.cert
├── src
│ └── main.cpp
└── test
└── RunTests.cpp
```
All URIs are relative to http://petstore.swagger.iohttp://petstore.swagger.io/v2
### PetApi
|Method | HTTP request | Description|
|------------- | ------------- | -------------|
|*addPet* | *POST* /pet | Add a new pet to the store.|
|*deletePet* | *DELETE* /pet/{petId} | Deletes a pet.|
|*findPetsByStatus* | *GET* /pet/findByStatus | Finds Pets by status.|
|*findPetsByTags* | *GET* /pet/findByTags | Finds Pets by tags.|
|*getPetById* | *GET* /pet/{petId} | Find pet by ID.|
|*updatePet* | *PUT* /pet | Update an existing pet.|
|*updatePetWithForm* | *POST* /pet/{petId} | Updates a pet in the store with form data.|
|*uploadFile* | *POST* /pet/{petId}/uploadImage | uploads an image.|
### StoreApi
|Method | HTTP request | Description|
|------------- | ------------- | -------------|
|*deleteOrder* | *DELETE* /store/order/{orderId} | Delete purchase order by ID.|
|*getInventory* | *GET* /store/inventory | Returns pet inventories by status.|
|*getOrderById* | *GET* /store/order/{orderId} | Find purchase order by ID.|
|*placeOrder* | *POST* /store/order | Place an order for a pet.|
### UserApi
|Method | HTTP request | Description|
|------------- | ------------- | -------------|
|*createUser* | *POST* /user | Create user.|
|*createUsersWithArrayInput* | *POST* /user/createWithArray | Creates list of users with given input array.|
|*createUsersWithListInput* | *POST* /user/createWithList | Creates list of users with given input array.|
|*deleteUser* | *DELETE* /user/{username} | Delete user.|
|*getUserByName* | *GET* /user/{username} | Get user by user name.|
|*loginUser* | *GET* /user/login | Logs user into the system.|
|*logoutUser* | *GET* /user/logout | Logs out current logged in user session.|
|*updateUser* | *PUT* /user/{username} | Updated user.|
## What are the Model files for the data structures/objects?
|Class | Description|
|------------- | -------------|
|*ApiResponse* | Describes the result of uploading an image resource|
|*Category* | A category for a pet|
|*Order* | An order for a pets from the pet store|
|*Pet* | A pet for sale in the pet store|
|*Tag* | A tag for a pet|
|*User* | A User who is purchasing from the pet store|

View File

@ -0,0 +1,139 @@
#include "ApiResponse.h"
using namespace Tiny;
ApiResponse::ApiResponse()
{
code = int(0);
type = std::string();
message = std::string();
}
ApiResponse::ApiResponse(std::string jsonString)
{
this->fromJson(jsonString);
}
ApiResponse::~ApiResponse()
{
}
void
ApiResponse::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *codeKey = "code";
if(object.has_key(codeKey))
{
bourne::json value = object[codeKey];
jsonToValue(&code, value, "int");
}
const char *typeKey = "type";
if(object.has_key(typeKey))
{
bourne::json value = object[typeKey];
jsonToValue(&type, value, "std::string");
}
const char *messageKey = "message";
if(object.has_key(messageKey))
{
bourne::json value = object[messageKey];
jsonToValue(&message, value, "std::string");
}
}
bourne::json
ApiResponse::toJson()
{
bourne::json object = bourne::json::object();
object["code"] = getCode();
object["type"] = getType();
object["message"] = getMessage();
return object;
}
int
ApiResponse::getCode()
{
return code;
}
void
ApiResponse::setCode(int code)
{
this->code = code;
}
std::string
ApiResponse::getType()
{
return type;
}
void
ApiResponse::setType(std::string type)
{
this->type = type;
}
std::string
ApiResponse::getMessage()
{
return message;
}
void
ApiResponse::setMessage(std::string message)
{
this->message = message;
}

View File

@ -0,0 +1,78 @@
/*
* ApiResponse.h
*
* Describes the result of uploading an image resource
*/
#ifndef TINY_CPP_CLIENT_ApiResponse_H_
#define TINY_CPP_CLIENT_ApiResponse_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief Describes the result of uploading an image resource
*
* \ingroup Models
*
*/
class ApiResponse{
public:
/*! \brief Constructor.
*/
ApiResponse();
ApiResponse(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~ApiResponse();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
int getCode();
/*! \brief Set
*/
void setCode(int code);
/*! \brief Get
*/
std::string getType();
/*! \brief Set
*/
void setType(std::string type);
/*! \brief Get
*/
std::string getMessage();
/*! \brief Set
*/
void setMessage(std::string message);
private:
int code{};
std::string type{};
std::string message{};
};
}
#endif /* TINY_CPP_CLIENT_ApiResponse_H_ */

View File

@ -0,0 +1,106 @@
#include "Category.h"
using namespace Tiny;
Category::Category()
{
id = long(0);
name = std::string();
}
Category::Category(std::string jsonString)
{
this->fromJson(jsonString);
}
Category::~Category()
{
}
void
Category::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *idKey = "id";
if(object.has_key(idKey))
{
bourne::json value = object[idKey];
jsonToValue(&id, value, "long");
}
const char *nameKey = "name";
if(object.has_key(nameKey))
{
bourne::json value = object[nameKey];
jsonToValue(&name, value, "std::string");
}
}
bourne::json
Category::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["name"] = getName();
return object;
}
long
Category::getId()
{
return id;
}
void
Category::setId(long id)
{
this->id = id;
}
std::string
Category::getName()
{
return name;
}
void
Category::setName(std::string name)
{
this->name = name;
}

View File

@ -0,0 +1,70 @@
/*
* Category.h
*
* A category for a pet
*/
#ifndef TINY_CPP_CLIENT_Category_H_
#define TINY_CPP_CLIENT_Category_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief A category for a pet
*
* \ingroup Models
*
*/
class Category{
public:
/*! \brief Constructor.
*/
Category();
Category(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Category();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
std::string getName();
/*! \brief Set
*/
void setName(std::string name);
private:
long id{};
std::string name{};
};
}
#endif /* TINY_CPP_CLIENT_Category_H_ */

View File

@ -0,0 +1,102 @@
#include "Helpers.h"
#include <string>
#include <sstream>
bool isprimitive(std::string type){
if(type == "std::string" ||
type == "int" ||
type == "float" ||
type == "long" ||
type == "double" ||
type == "bool" ||
type == "std::map" ||
type == "std::list")
{
return true;
}
return false;
}
void
jsonToValue(void* target, bourne::json value, std::string type)
{
if (target == NULL || value.is_null()) {
return;
}
else if (type.compare("bool") == 0)
{
bool* val = static_cast<bool*> (target);
*val = value.to_bool();
}
else if (type.compare("int") == 0)
{
int* val = static_cast<int*> (target);
*val = value.to_int();
}
else if (type.compare("float") == 0)
{
float* val = static_cast<float*> (target);
*val = (float)(value.to_float());
}
else if (type.compare("long") == 0)
{
long* val = static_cast<long*> (target);
*val = (long)(value.to_int());
}
else if (type.compare("double") == 0)
{
double* val = static_cast<double*> (target);
*val = value.to_float();
}
else if (type.compare("std::string") == 0)
{
std::string* val = static_cast<std::string*> (target);
*val = value.to_string();
}
else {
return;
}
}
std::string
stringify(long input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(int input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(double input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(float input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(std::string input){
std::stringstream stream;
stream << input;
return stream.str();
};

View File

@ -0,0 +1,22 @@
#ifndef TINY_CPP_CLIENT_HELPERS_H_
#define TINY_CPP_CLIENT_HELPERS_H_
#include <string>
#include "bourne/json.hpp"
bool isprimitive(std::string type);
void jsonToValue(void* target, bourne::json value, std::string type);
std::string stringify(long input);
std::string stringify(int input);
std::string stringify(double input);
std::string stringify(float input);
std::string stringify(std::string input);
#endif /* TINY_CPP_CLIENT_HELPERS_H_ */

View File

@ -0,0 +1,238 @@
#include "Order.h"
using namespace Tiny;
Order::Order()
{
id = long(0);
petId = long(0);
quantity = int(0);
shipDate = std::string();
status = std::string();
complete = bool(false);
}
Order::Order(std::string jsonString)
{
this->fromJson(jsonString);
}
Order::~Order()
{
}
void
Order::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *idKey = "id";
if(object.has_key(idKey))
{
bourne::json value = object[idKey];
jsonToValue(&id, value, "long");
}
const char *petIdKey = "petId";
if(object.has_key(petIdKey))
{
bourne::json value = object[petIdKey];
jsonToValue(&petId, value, "long");
}
const char *quantityKey = "quantity";
if(object.has_key(quantityKey))
{
bourne::json value = object[quantityKey];
jsonToValue(&quantity, value, "int");
}
const char *shipDateKey = "shipDate";
if(object.has_key(shipDateKey))
{
bourne::json value = object[shipDateKey];
jsonToValue(&shipDate, value, "std::string");
}
const char *statusKey = "status";
if(object.has_key(statusKey))
{
bourne::json value = object[statusKey];
jsonToValue(&status, value, "std::string");
}
const char *completeKey = "complete";
if(object.has_key(completeKey))
{
bourne::json value = object[completeKey];
jsonToValue(&complete, value, "bool");
}
}
bourne::json
Order::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["petId"] = getPetId();
object["quantity"] = getQuantity();
object["shipDate"] = getShipDate();
object["status"] = getStatus();
object["complete"] = isComplete();
return object;
}
long
Order::getId()
{
return id;
}
void
Order::setId(long id)
{
this->id = id;
}
long
Order::getPetId()
{
return petId;
}
void
Order::setPetId(long petId)
{
this->petId = petId;
}
int
Order::getQuantity()
{
return quantity;
}
void
Order::setQuantity(int quantity)
{
this->quantity = quantity;
}
std::string
Order::getShipDate()
{
return shipDate;
}
void
Order::setShipDate(std::string shipDate)
{
this->shipDate = shipDate;
}
std::string
Order::getStatus()
{
return status;
}
void
Order::setStatus(std::string status)
{
this->status = status;
}
bool
Order::isComplete()
{
return complete;
}
void
Order::setComplete(bool complete)
{
this->complete = complete;
}

View File

@ -0,0 +1,102 @@
/*
* Order.h
*
* An order for a pets from the pet store
*/
#ifndef TINY_CPP_CLIENT_Order_H_
#define TINY_CPP_CLIENT_Order_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief An order for a pets from the pet store
*
* \ingroup Models
*
*/
class Order{
public:
/*! \brief Constructor.
*/
Order();
Order(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Order();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
long getPetId();
/*! \brief Set
*/
void setPetId(long petId);
/*! \brief Get
*/
int getQuantity();
/*! \brief Set
*/
void setQuantity(int quantity);
/*! \brief Get
*/
std::string getShipDate();
/*! \brief Set
*/
void setShipDate(std::string shipDate);
/*! \brief Get Order Status
*/
std::string getStatus();
/*! \brief Set Order Status
*/
void setStatus(std::string status);
/*! \brief Get
*/
bool isComplete();
/*! \brief Set
*/
void setComplete(bool complete);
private:
long id{};
long petId{};
int quantity{};
std::string shipDate{};
std::string status{};
bool complete{};
};
}
#endif /* TINY_CPP_CLIENT_Order_H_ */

View File

@ -0,0 +1,274 @@
#include "Pet.h"
using namespace Tiny;
Pet::Pet()
{
id = long(0);
category = Category();
name = std::string();
photoUrls = std::list<std::string>();
tags = std::list<Tag>();
status = std::string();
}
Pet::Pet(std::string jsonString)
{
this->fromJson(jsonString);
}
Pet::~Pet()
{
}
void
Pet::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *idKey = "id";
if(object.has_key(idKey))
{
bourne::json value = object[idKey];
jsonToValue(&id, value, "long");
}
const char *categoryKey = "category";
if(object.has_key(categoryKey))
{
bourne::json value = object[categoryKey];
Category* obj = &category;
obj->fromJson(value.dump());
}
const char *nameKey = "name";
if(object.has_key(nameKey))
{
bourne::json value = object[nameKey];
jsonToValue(&name, value, "std::string");
}
const char *photoUrlsKey = "photoUrls";
if(object.has_key(photoUrlsKey))
{
bourne::json value = object[photoUrlsKey];
std::list<std::string> photoUrls_list;
std::string element;
for(auto& var : value.array_range())
{
jsonToValue(&element, var, "std::string");
photoUrls_list.push_back(element);
}
photoUrls = photoUrls_list;
}
const char *tagsKey = "tags";
if(object.has_key(tagsKey))
{
bourne::json value = object[tagsKey];
std::list<Tag> tags_list;
Tag element;
for(auto& var : value.array_range())
{
element.fromJson(var.dump());
tags_list.push_back(element);
}
tags = tags_list;
}
const char *statusKey = "status";
if(object.has_key(statusKey))
{
bourne::json value = object[statusKey];
jsonToValue(&status, value, "std::string");
}
}
bourne::json
Pet::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["category"] = getCategory().toJson();
object["name"] = getName();
std::list<std::string> photoUrls_list = getPhotoUrls();
bourne::json photoUrls_arr = bourne::json::array();
for(auto& var : photoUrls_list)
{
photoUrls_arr.append(var);
}
object["photoUrls"] = photoUrls_arr;
std::list<Tag> tags_list = getTags();
bourne::json tags_arr = bourne::json::array();
for(auto& var : tags_list)
{
Tag obj = var;
tags_arr.append(obj.toJson());
}
object["tags"] = tags_arr;
object["status"] = getStatus();
return object;
}
long
Pet::getId()
{
return id;
}
void
Pet::setId(long id)
{
this->id = id;
}
Category
Pet::getCategory()
{
return category;
}
void
Pet::setCategory(Category category)
{
this->category = category;
}
std::string
Pet::getName()
{
return name;
}
void
Pet::setName(std::string name)
{
this->name = name;
}
std::list<std::string>
Pet::getPhotoUrls()
{
return photoUrls;
}
void
Pet::setPhotoUrls(std::list <std::string> photoUrls)
{
this->photoUrls = photoUrls;
}
std::list<Tag>
Pet::getTags()
{
return tags;
}
void
Pet::setTags(std::list <Tag> tags)
{
this->tags = tags;
}
std::string
Pet::getStatus()
{
return status;
}
void
Pet::setStatus(std::string status)
{
this->status = status;
}

View File

@ -0,0 +1,105 @@
/*
* Pet.h
*
* A pet for sale in the pet store
*/
#ifndef TINY_CPP_CLIENT_Pet_H_
#define TINY_CPP_CLIENT_Pet_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
#include "Category.h"
#include "Tag.h"
#include <list>
namespace Tiny {
/*! \brief A pet for sale in the pet store
*
* \ingroup Models
*
*/
class Pet{
public:
/*! \brief Constructor.
*/
Pet();
Pet(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Pet();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
Category getCategory();
/*! \brief Set
*/
void setCategory(Category category);
/*! \brief Get
*/
std::string getName();
/*! \brief Set
*/
void setName(std::string name);
/*! \brief Get
*/
std::list<std::string> getPhotoUrls();
/*! \brief Set
*/
void setPhotoUrls(std::list <std::string> photoUrls);
/*! \brief Get
*/
std::list<Tag> getTags();
/*! \brief Set
*/
void setTags(std::list <Tag> tags);
/*! \brief Get pet status in the store
*/
std::string getStatus();
/*! \brief Set pet status in the store
*/
void setStatus(std::string status);
private:
long id{};
Category category;
std::string name{};
std::list<std::string> photoUrls;
std::list<Tag> tags;
std::string status{};
};
}
#endif /* TINY_CPP_CLIENT_Pet_H_ */

View File

@ -0,0 +1,106 @@
#include "Tag.h"
using namespace Tiny;
Tag::Tag()
{
id = long(0);
name = std::string();
}
Tag::Tag(std::string jsonString)
{
this->fromJson(jsonString);
}
Tag::~Tag()
{
}
void
Tag::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *idKey = "id";
if(object.has_key(idKey))
{
bourne::json value = object[idKey];
jsonToValue(&id, value, "long");
}
const char *nameKey = "name";
if(object.has_key(nameKey))
{
bourne::json value = object[nameKey];
jsonToValue(&name, value, "std::string");
}
}
bourne::json
Tag::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["name"] = getName();
return object;
}
long
Tag::getId()
{
return id;
}
void
Tag::setId(long id)
{
this->id = id;
}
std::string
Tag::getName()
{
return name;
}
void
Tag::setName(std::string name)
{
this->name = name;
}

View File

@ -0,0 +1,70 @@
/*
* Tag.h
*
* A tag for a pet
*/
#ifndef TINY_CPP_CLIENT_Tag_H_
#define TINY_CPP_CLIENT_Tag_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief A tag for a pet
*
* \ingroup Models
*
*/
class Tag{
public:
/*! \brief Constructor.
*/
Tag();
Tag(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Tag();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
std::string getName();
/*! \brief Set
*/
void setName(std::string name);
private:
long id{};
std::string name{};
};
}
#endif /* TINY_CPP_CLIENT_Tag_H_ */

View File

@ -0,0 +1,304 @@
#include "User.h"
using namespace Tiny;
User::User()
{
id = long(0);
username = std::string();
firstName = std::string();
lastName = std::string();
email = std::string();
password = std::string();
phone = std::string();
userStatus = int(0);
}
User::User(std::string jsonString)
{
this->fromJson(jsonString);
}
User::~User()
{
}
void
User::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *idKey = "id";
if(object.has_key(idKey))
{
bourne::json value = object[idKey];
jsonToValue(&id, value, "long");
}
const char *usernameKey = "username";
if(object.has_key(usernameKey))
{
bourne::json value = object[usernameKey];
jsonToValue(&username, value, "std::string");
}
const char *firstNameKey = "firstName";
if(object.has_key(firstNameKey))
{
bourne::json value = object[firstNameKey];
jsonToValue(&firstName, value, "std::string");
}
const char *lastNameKey = "lastName";
if(object.has_key(lastNameKey))
{
bourne::json value = object[lastNameKey];
jsonToValue(&lastName, value, "std::string");
}
const char *emailKey = "email";
if(object.has_key(emailKey))
{
bourne::json value = object[emailKey];
jsonToValue(&email, value, "std::string");
}
const char *passwordKey = "password";
if(object.has_key(passwordKey))
{
bourne::json value = object[passwordKey];
jsonToValue(&password, value, "std::string");
}
const char *phoneKey = "phone";
if(object.has_key(phoneKey))
{
bourne::json value = object[phoneKey];
jsonToValue(&phone, value, "std::string");
}
const char *userStatusKey = "userStatus";
if(object.has_key(userStatusKey))
{
bourne::json value = object[userStatusKey];
jsonToValue(&userStatus, value, "int");
}
}
bourne::json
User::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["username"] = getUsername();
object["firstName"] = getFirstName();
object["lastName"] = getLastName();
object["email"] = getEmail();
object["password"] = getPassword();
object["phone"] = getPhone();
object["userStatus"] = getUserStatus();
return object;
}
long
User::getId()
{
return id;
}
void
User::setId(long id)
{
this->id = id;
}
std::string
User::getUsername()
{
return username;
}
void
User::setUsername(std::string username)
{
this->username = username;
}
std::string
User::getFirstName()
{
return firstName;
}
void
User::setFirstName(std::string firstName)
{
this->firstName = firstName;
}
std::string
User::getLastName()
{
return lastName;
}
void
User::setLastName(std::string lastName)
{
this->lastName = lastName;
}
std::string
User::getEmail()
{
return email;
}
void
User::setEmail(std::string email)
{
this->email = email;
}
std::string
User::getPassword()
{
return password;
}
void
User::setPassword(std::string password)
{
this->password = password;
}
std::string
User::getPhone()
{
return phone;
}
void
User::setPhone(std::string phone)
{
this->phone = phone;
}
int
User::getUserStatus()
{
return userStatus;
}
void
User::setUserStatus(int userStatus)
{
this->userStatus = userStatus;
}

View File

@ -0,0 +1,118 @@
/*
* User.h
*
* A User who is purchasing from the pet store
*/
#ifndef TINY_CPP_CLIENT_User_H_
#define TINY_CPP_CLIENT_User_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief A User who is purchasing from the pet store
*
* \ingroup Models
*
*/
class User{
public:
/*! \brief Constructor.
*/
User();
User(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~User();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
std::string getUsername();
/*! \brief Set
*/
void setUsername(std::string username);
/*! \brief Get
*/
std::string getFirstName();
/*! \brief Set
*/
void setFirstName(std::string firstName);
/*! \brief Get
*/
std::string getLastName();
/*! \brief Set
*/
void setLastName(std::string lastName);
/*! \brief Get
*/
std::string getEmail();
/*! \brief Set
*/
void setEmail(std::string email);
/*! \brief Get
*/
std::string getPassword();
/*! \brief Set
*/
void setPassword(std::string password);
/*! \brief Get
*/
std::string getPhone();
/*! \brief Set
*/
void setPhone(std::string phone);
/*! \brief Get User Status
*/
int getUserStatus();
/*! \brief Set User Status
*/
void setUserStatus(int userStatus);
private:
long id{};
std::string username{};
std::string firstName{};
std::string lastName{};
std::string email{};
std::string password{};
std::string phone{};
int userStatus{};
};
}
#endif /* TINY_CPP_CLIENT_User_H_ */

View File

@ -0,0 +1,139 @@
#include "ApiResponse.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_ApiResponse_code_is_assigned_from_json()
{
bourne::json input =
{
"code", 1
};
ApiResponse obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getCode());
}
void test_ApiResponse_type_is_assigned_from_json()
{
bourne::json input =
{
"type", "hello"
};
ApiResponse obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getType().c_str());
}
void test_ApiResponse_message_is_assigned_from_json()
{
bourne::json input =
{
"message", "hello"
};
ApiResponse obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getMessage().c_str());
}
void test_ApiResponse_code_is_converted_to_json()
{
bourne::json input =
{
"code", 1
};
ApiResponse obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["code"] == output["code"]);
}
void test_ApiResponse_type_is_converted_to_json()
{
bourne::json input =
{
"type", "hello"
};
ApiResponse obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["type"] == output["type"]);
}
void test_ApiResponse_message_is_converted_to_json()
{
bourne::json input =
{
"message", "hello"
};
ApiResponse obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["message"] == output["message"]);
}

View File

@ -0,0 +1,97 @@
#include "Category.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Category_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Category obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Category_name_is_assigned_from_json()
{
bourne::json input =
{
"name", "hello"
};
Category obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getName().c_str());
}
void test_Category_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Category obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Category_name_is_converted_to_json()
{
bourne::json input =
{
"name", "hello"
};
Category obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["name"] == output["name"]);
}

View File

@ -0,0 +1,245 @@
#include "Order.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Order_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Order_petId_is_assigned_from_json()
{
bourne::json input =
{
"petId", 1
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getPetId());
}
void test_Order_quantity_is_assigned_from_json()
{
bourne::json input =
{
"quantity", 1
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getQuantity());
}
void test_Order_shipDate_is_assigned_from_json()
{
}
void test_Order_status_is_assigned_from_json()
{
bourne::json input =
{
"status", "hello"
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getStatus().c_str());
}
void test_Order_complete_is_assigned_from_json()
{
bourne::json input =
{
"complete", true
};
Order obj(input.dump());
TEST_ASSERT(true == obj.isComplete());
}
void test_Order_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Order_petId_is_converted_to_json()
{
bourne::json input =
{
"petId", 1
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["petId"] == output["petId"]);
}
void test_Order_quantity_is_converted_to_json()
{
bourne::json input =
{
"quantity", 1
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["quantity"] == output["quantity"]);
}
void test_Order_shipDate_is_converted_to_json()
{
}
void test_Order_status_is_converted_to_json()
{
bourne::json input =
{
"status", "hello"
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["status"] == output["status"]);
}
void test_Order_complete_is_converted_to_json()
{
bourne::json input =
{
"complete", true
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["complete"] == output["complete"]);
}

View File

@ -0,0 +1,145 @@
#include "Pet.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Pet_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Pet obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Pet_name_is_assigned_from_json()
{
bourne::json input =
{
"name", "hello"
};
Pet obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getName().c_str());
}
void test_Pet_status_is_assigned_from_json()
{
bourne::json input =
{
"status", "hello"
};
Pet obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getStatus().c_str());
}
void test_Pet_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Pet obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Pet_name_is_converted_to_json()
{
bourne::json input =
{
"name", "hello"
};
Pet obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["name"] == output["name"]);
}
void test_Pet_status_is_converted_to_json()
{
bourne::json input =
{
"status", "hello"
};
Pet obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["status"] == output["status"]);
}

View File

@ -0,0 +1,97 @@
#include "Tag.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Tag_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Tag obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Tag_name_is_assigned_from_json()
{
bourne::json input =
{
"name", "hello"
};
Tag obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getName().c_str());
}
void test_Tag_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Tag obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Tag_name_is_converted_to_json()
{
bourne::json input =
{
"name", "hello"
};
Tag obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["name"] == output["name"]);
}

View File

@ -0,0 +1,349 @@
#include "User.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_User_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
User obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_User_username_is_assigned_from_json()
{
bourne::json input =
{
"username", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getUsername().c_str());
}
void test_User_firstName_is_assigned_from_json()
{
bourne::json input =
{
"firstName", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getFirstName().c_str());
}
void test_User_lastName_is_assigned_from_json()
{
bourne::json input =
{
"lastName", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getLastName().c_str());
}
void test_User_email_is_assigned_from_json()
{
bourne::json input =
{
"email", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getEmail().c_str());
}
void test_User_password_is_assigned_from_json()
{
bourne::json input =
{
"password", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getPassword().c_str());
}
void test_User_phone_is_assigned_from_json()
{
bourne::json input =
{
"phone", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getPhone().c_str());
}
void test_User_userStatus_is_assigned_from_json()
{
bourne::json input =
{
"userStatus", 1
};
User obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getUserStatus());
}
void test_User_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_User_username_is_converted_to_json()
{
bourne::json input =
{
"username", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["username"] == output["username"]);
}
void test_User_firstName_is_converted_to_json()
{
bourne::json input =
{
"firstName", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["firstName"] == output["firstName"]);
}
void test_User_lastName_is_converted_to_json()
{
bourne::json input =
{
"lastName", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["lastName"] == output["lastName"]);
}
void test_User_email_is_converted_to_json()
{
bourne::json input =
{
"email", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["email"] == output["email"]);
}
void test_User_password_is_converted_to_json()
{
bourne::json input =
{
"password", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["password"] == output["password"]);
}
void test_User_phone_is_converted_to_json()
{
bourne::json input =
{
"phone", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["phone"] == output["phone"]);
}
void test_User_userStatus_is_converted_to_json()
{
bourne::json input =
{
"userStatus", 1
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["userStatus"] == output["userStatus"]);
}

View File

@ -0,0 +1,8 @@
#include "AbstractService.h"
#include "Arduino.h"
void Tiny::AbstractService::begin(std::string url){
http.begin(String(url.c_str()), test_root_ca); //HTTPS connection
}

View File

@ -0,0 +1,28 @@
#ifndef TINY_CPP_CLIENT_ABSTRACTSERVICE_H_
#define TINY_CPP_CLIENT_ABSTRACTSERVICE_H_
#include "HTTPClient.h"
#include "Response.h"
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class AbstractService {
public:
HTTPClient http;
std::string basepath = "https://petstore3.swagger.io/api/v3"; // TODO: change to your url
void begin(std::string url);
// Go and comment out a certificate in root.cert, if you get an error here
// Certificate from file
const char* test_root_ca =
#include "../../root.cert"
;
}; // end class
}// namespace Tinyclient
#endif /* TINY_CPP_CLIENT_ABSTRACTSERVICE_H_ */

View File

@ -0,0 +1,418 @@
#include "PetApi.h"
using namespace Tiny;
Response<
Pet
>
PetApi::
addPet(
Pet pet
)
{
std::string url = basepath + "/pet"; //
// Query |
// Headers |
// Form |
// Body | pet
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
payload = pet.toJson().dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Pet obj(output_string);
Response<Pet> response(obj, httpCode);
return response;
}
Response<
String
>
PetApi::
deletePet(
long petId
,
std::string apiKey
)
{
std::string url = basepath + "/pet/{petId}"; //petId
// Query |
// Headers | apiKey
// Form |
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | DELETE
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
std::list<Pet>
>
PetApi::
findPetsByStatus(
std::list<std::string> status
)
{
std::string url = basepath + "/pet/findByStatus"; //
// Query | status
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
std::list<Pet> obj = std::list<Pet>();
bourne::json jsonPayload(output_string);
for(auto& var : jsonPayload.array_range())
{
Pet tmp(var.dump());
obj.push_back(tmp);
}
Response<std::list<Pet>> response(obj, httpCode);
return response;
}
Response<
std::list<Pet>
>
PetApi::
findPetsByTags(
std::list<std::string> tags
)
{
std::string url = basepath + "/pet/findByTags"; //
// Query | tags
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
std::list<Pet> obj = std::list<Pet>();
bourne::json jsonPayload(output_string);
for(auto& var : jsonPayload.array_range())
{
Pet tmp(var.dump());
obj.push_back(tmp);
}
Response<std::list<Pet>> response(obj, httpCode);
return response;
}
Response<
Pet
>
PetApi::
getPetById(
long petId
)
{
std::string url = basepath + "/pet/{petId}"; //petId
// Query |
// Headers |
// Form |
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Pet obj(output_string);
Response<Pet> response(obj, httpCode);
return response;
}
Response<
Pet
>
PetApi::
updatePet(
Pet pet
)
{
std::string url = basepath + "/pet"; //
// Query |
// Headers |
// Form |
// Body | pet
begin(url);
std::string payload = "";
// Send Request
// METHOD | PUT
http.addHeader("Content-Type", "application/json");
payload = pet.toJson().dump();
int httpCode = http.sendRequest("PUT", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Pet obj(output_string);
Response<Pet> response(obj, httpCode);
return response;
}
Response<
String
>
PetApi::
updatePetWithForm(
long petId
,
std::string name
,
std::string status
)
{
std::string url = basepath + "/pet/{petId}"; //petId
// Query |
// Headers |
// Form | name status
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
ApiResponse
>
PetApi::
uploadFile(
long petId
,
std::string additionalMetadata
,
std::string file
)
{
std::string url = basepath + "/pet/{petId}/uploadImage"; //petId
// Query |
// Headers |
// Form | additionalMetadata file
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
ApiResponse obj(output_string);
Response<ApiResponse> response(obj, httpCode);
return response;
}

View File

@ -0,0 +1,163 @@
#ifndef TINY_CPP_CLIENT_PetApi_H_
#define TINY_CPP_CLIENT_PetApi_H_
#include "Response.h"
#include "Arduino.h"
#include "AbstractService.h"
#include "Helpers.h"
#include <list>
#include "ApiResponse.h"
#include "Pet.h"
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class PetApi : public AbstractService {
public:
PetApi() = default;
virtual ~PetApi() = default;
/**
* Add a new pet to the store.
*
*
* \param pet Pet object that needs to be added to the store *Required*
*/
Response<
Pet
>
addPet(
Pet pet
);
/**
* Deletes a pet.
*
*
* \param petId Pet id to delete *Required*
* \param apiKey
*/
Response<
String
>
deletePet(
long petId
,
std::string apiKey
);
/**
* Finds Pets by status.
*
* Multiple status values can be provided with comma separated strings
* \param status Status values that need to be considered for filter *Required*
*/
Response<
std::list<Pet>
>
findPetsByStatus(
std::list<std::string> status
);
/**
* Finds Pets by tags.
*
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* \param tags Tags to filter by *Required*
*/
Response<
std::list<Pet>
>
findPetsByTags(
std::list<std::string> tags
);
/**
* Find pet by ID.
*
* Returns a single pet
* \param petId ID of pet to return *Required*
*/
Response<
Pet
>
getPetById(
long petId
);
/**
* Update an existing pet.
*
*
* \param pet Pet object that needs to be added to the store *Required*
*/
Response<
Pet
>
updatePet(
Pet pet
);
/**
* Updates a pet in the store with form data.
*
*
* \param petId ID of pet that needs to be updated *Required*
* \param name Updated name of the pet
* \param status Updated status of the pet
*/
Response<
String
>
updatePetWithForm(
long petId
,
std::string name
,
std::string status
);
/**
* uploads an image.
*
*
* \param petId ID of pet to update *Required*
* \param additionalMetadata Additional data to pass to server
* \param file file to upload
*/
Response<
ApiResponse
>
uploadFile(
long petId
,
std::string additionalMetadata
,
std::string file
);
};
}
#endif /* TINY_CPP_CLIENT_PetApi_H_ */

View File

@ -0,0 +1,25 @@
#ifndef TINY_CPP_CLIENT_RESPONSE_H_
#define TINY_CPP_CLIENT_RESPONSE_H_
#include <string>
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
template <typename T = std::string>
class Response {
public:
Response(T _obj, int _code){
obj = _obj;
code = _code;
}
int code;
T obj;
};
} // namespace Tinyclient
#endif /* TINY_CPP_CLIENT_RESPONSE_H_ */

View File

@ -0,0 +1,185 @@
#include "StoreApi.h"
using namespace Tiny;
Response<
String
>
StoreApi::
deleteOrder(
std::string orderId
)
{
std::string url = basepath + "/store/order/{orderId}"; //orderId
// Query |
// Headers |
// Form |
// Body |
std::string s_orderId("{");
s_orderId.append("orderId");
s_orderId.append("}");
int pos = url.find(s_orderId);
url.erase(pos, s_orderId.length());
url.insert(pos, stringify(orderId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | DELETE
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
StoreApi::
getInventory(
)
{
std::string url = basepath + "/store/inventory"; //
// Query |
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
//TODO: Implement map logic here
//TODO: No support for maps.
Response<String> response(output, httpCode);
return response;
}
Response<
Order
>
StoreApi::
getOrderById(
long orderId
)
{
std::string url = basepath + "/store/order/{orderId}"; //orderId
// Query |
// Headers |
// Form |
// Body |
std::string s_orderId("{");
s_orderId.append("orderId");
s_orderId.append("}");
int pos = url.find(s_orderId);
url.erase(pos, s_orderId.length());
url.insert(pos, stringify(orderId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Order obj(output_string);
Response<Order> response(obj, httpCode);
return response;
}
Response<
Order
>
StoreApi::
placeOrder(
Order order
)
{
std::string url = basepath + "/store/order"; //
// Query |
// Headers |
// Form |
// Body | order
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
payload = order.toJson().dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Order obj(output_string);
Response<Order> response(obj, httpCode);
return response;
}

View File

@ -0,0 +1,83 @@
#ifndef TINY_CPP_CLIENT_StoreApi_H_
#define TINY_CPP_CLIENT_StoreApi_H_
#include "Response.h"
#include "Arduino.h"
#include "AbstractService.h"
#include "Helpers.h"
#include <list>
#include <map>
#include "Order.h"
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class StoreApi : public AbstractService {
public:
StoreApi() = default;
virtual ~StoreApi() = default;
/**
* Delete purchase order by ID.
*
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
* \param orderId ID of the order that needs to be deleted *Required*
*/
Response<
String
>
deleteOrder(
std::string orderId
);
/**
* Returns pet inventories by status.
*
* Returns a map of status codes to quantities
*/
Response<
String
>
getInventory(
);
/**
* Find purchase order by ID.
*
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
* \param orderId ID of pet that needs to be fetched *Required*
*/
Response<
Order
>
getOrderById(
long orderId
);
/**
* Place an order for a pet.
*
*
* \param order order placed for purchasing the pet *Required*
*/
Response<
Order
>
placeOrder(
Order order
);
};
}
#endif /* TINY_CPP_CLIENT_StoreApi_H_ */

View File

@ -0,0 +1,366 @@
#include "UserApi.h"
using namespace Tiny;
Response<
String
>
UserApi::
createUser(
User user
)
{
std::string url = basepath + "/user"; //
// Query |
// Headers |
// Form |
// Body | user
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
payload = user.toJson().dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
createUsersWithArrayInput(
std::list<User> user
)
{
std::string url = basepath + "/user/createWithArray"; //
// Query |
// Headers |
// Form |
// Body | user
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
bourne::json tmp_arr = bourne::json::array();
for(auto& var : user)
{
auto tmp = var.toJson();
tmp_arr.append(tmp);
}
payload = tmp_arr.dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
createUsersWithListInput(
std::list<User> user
)
{
std::string url = basepath + "/user/createWithList"; //
// Query |
// Headers |
// Form |
// Body | user
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
bourne::json tmp_arr = bourne::json::array();
for(auto& var : user)
{
auto tmp = var.toJson();
tmp_arr.append(tmp);
}
payload = tmp_arr.dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
deleteUser(
std::string username
)
{
std::string url = basepath + "/user/{username}"; //username
// Query |
// Headers |
// Form |
// Body |
std::string s_username("{");
s_username.append("username");
s_username.append("}");
int pos = url.find(s_username);
url.erase(pos, s_username.length());
url.insert(pos, stringify(username));
begin(url);
std::string payload = "";
// Send Request
// METHOD | DELETE
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
User
>
UserApi::
getUserByName(
std::string username
)
{
std::string url = basepath + "/user/{username}"; //username
// Query |
// Headers |
// Form |
// Body |
std::string s_username("{");
s_username.append("username");
s_username.append("}");
int pos = url.find(s_username);
url.erase(pos, s_username.length());
url.insert(pos, stringify(username));
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
User obj(output_string);
Response<User> response(obj, httpCode);
return response;
}
Response<
std::string
>
UserApi::
loginUser(
std::string username
,
std::string password
)
{
std::string url = basepath + "/user/login"; //
// Query | username password
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
bourne::json jsonPayload(output_string);
std::string obj;
jsonToValue(&obj, jsonPayload, "std::string");
Response<std::string> response(obj, httpCode);
return response;
}
Response<
String
>
UserApi::
logoutUser(
)
{
std::string url = basepath + "/user/logout"; //
// Query |
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
updateUser(
std::string username
,
User user
)
{
std::string url = basepath + "/user/{username}"; //username
// Query |
// Headers |
// Form |
// Body | user
std::string s_username("{");
s_username.append("username");
s_username.append("}");
int pos = url.find(s_username);
url.erase(pos, s_username.length());
url.insert(pos, stringify(username));
begin(url);
std::string payload = "";
// Send Request
// METHOD | PUT
http.addHeader("Content-Type", "application/json");
payload = user.toJson().dump();
int httpCode = http.sendRequest("PUT", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}

View File

@ -0,0 +1,147 @@
#ifndef TINY_CPP_CLIENT_UserApi_H_
#define TINY_CPP_CLIENT_UserApi_H_
#include "Response.h"
#include "Arduino.h"
#include "AbstractService.h"
#include "Helpers.h"
#include <list>
#include "User.h"
#include <list>
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class UserApi : public AbstractService {
public:
UserApi() = default;
virtual ~UserApi() = default;
/**
* Create user.
*
* This can only be done by the logged in user.
* \param user Created user object *Required*
*/
Response<
String
>
createUser(
User user
);
/**
* Creates list of users with given input array.
*
*
* \param user List of user object *Required*
*/
Response<
String
>
createUsersWithArrayInput(
std::list<User> user
);
/**
* Creates list of users with given input array.
*
*
* \param user List of user object *Required*
*/
Response<
String
>
createUsersWithListInput(
std::list<User> user
);
/**
* Delete user.
*
* This can only be done by the logged in user.
* \param username The name that needs to be deleted *Required*
*/
Response<
String
>
deleteUser(
std::string username
);
/**
* Get user by user name.
*
*
* \param username The name that needs to be fetched. Use user1 for testing. *Required*
*/
Response<
User
>
getUserByName(
std::string username
);
/**
* Logs user into the system.
*
*
* \param username The user name for login *Required*
* \param password The password for login in clear text *Required*
*/
Response<
std::string
>
loginUser(
std::string username
,
std::string password
);
/**
* Logs out current logged in user session.
*
*
*/
Response<
String
>
logoutUser(
);
/**
* Updated user.
*
* This can only be done by the logged in user.
* \param username name that need to be deleted *Required*
* \param user Updated user object *Required*
*/
Response<
String
>
updateUser(
std::string username
,
User user
);
};
}
#endif /* TINY_CPP_CLIENT_UserApi_H_ */

View File

@ -0,0 +1,7 @@
[env:esp32]
platform = espressif32
board = nodemcu-32s
framework = arduino
lib_deps = https://github.com/steinwurf/bourne.git
extra_scripts = pre_compiling_bourne.py

View File

@ -0,0 +1,25 @@
Import("env")
## Compatibility for bourne to work on microcontrollers
# We insert '#define _GLIBCXX_USE_C99' in files that use std::stoll or std::to_string
def insert_c99_into(file):
import fileinput
path = env['PROJECT_LIBDEPS_DIR'] + "/" + env['PIOENV'] + "/bourne/src/bourne/" + file
value = '#define _GLIBCXX_USE_C99 1\n'
for line in fileinput.FileInput(path,inplace=1):
if line.startswith('#define _GLIBCXX_USE_C99'):
continue
elif line.startswith('// D'):
line=line.replace(line,line+value)
print(line, end='')
def fix_parser():
insert_c99_into('detail/parser.cpp')
def fix_json():
insert_c99_into('json.cpp')
fix_parser()
fix_json()

View File

@ -0,0 +1,53 @@
// TODO: Provide your service root certificate.
// Below is two examples of root certificates.
// Let's encrypt root certificate
/**
"-----BEGIN CERTIFICATE-----\n" \
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" \
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \
"QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" \
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \
"b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" \
"9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n" \
"CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" \
"nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" \
"43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" \
"T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" \
"gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" \
"BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" \
"TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" \
"DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" \
"hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" \
"06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" \
"PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" \
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" \
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" \
"-----END CERTIFICATE-----\n"
*/
// Amazon_Root_CA_1.pem
/**
"-----BEGIN CERTIFICATE-----\n" \
"MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n" \
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n" \
"b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n" \
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n" \
"b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n" \
"ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n" \
"9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n" \
"IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n" \
"VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n" \
"93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n" \
"jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n" \
"AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n" \
"A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\n" \
"U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n" \
"N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\n" \
"o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n" \
"5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n" \
"rqXRfboQnoZsG4q5WTP468SQvvG5\n" \
"-----END CERTIFICATE-----\n" \
*/

View File

@ -0,0 +1,37 @@
#include "PetApi.h"
const char* ssid = "your wifi name"; // TODO Change wifi name
const char* password = "Your wifi password"; //TODO Change wifi password
void setup(){
//Initialize serial and wait for port to open:
Serial.begin(9600);
delay(100);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
// wait 1 second for re-trying
delay(1000);
}
Serial.print("Connected to ");
Serial.println(ssid);
//Print LAN IP.
Serial.print("IP address set: ");
Serial.println(WiFi.localIP());
Tiny::PetApi petapi;
auto resp = petapi.getPetById(10);
Serial.println(resp.code);
Tiny::Pet pet = resp.obj;
Serial.println(pet.toJson().dump().c_str());
}
void loop(){}

View File

@ -0,0 +1,204 @@
#include "ApiResponseTest.cpp"
#include "CategoryTest.cpp"
#include "OrderTest.cpp"
#include "PetTest.cpp"
#include "TagTest.cpp"
#include "UserTest.cpp"
void setUp(){}
void tearDown(){}
void runTests(){
RUN_TEST(test_ApiResponse_code_is_assigned_from_json);
RUN_TEST(test_ApiResponse_type_is_assigned_from_json);
RUN_TEST(test_ApiResponse_message_is_assigned_from_json);
RUN_TEST(test_Category_id_is_assigned_from_json);
RUN_TEST(test_Category_name_is_assigned_from_json);
RUN_TEST(test_Order_id_is_assigned_from_json);
RUN_TEST(test_Order_petId_is_assigned_from_json);
RUN_TEST(test_Order_quantity_is_assigned_from_json);
RUN_TEST(test_Order_shipDate_is_assigned_from_json);
RUN_TEST(test_Order_status_is_assigned_from_json);
RUN_TEST(test_Order_complete_is_assigned_from_json);
RUN_TEST(test_Pet_id_is_assigned_from_json);
RUN_TEST(test_Pet_name_is_assigned_from_json);
RUN_TEST(test_Pet_status_is_assigned_from_json);
RUN_TEST(test_Tag_id_is_assigned_from_json);
RUN_TEST(test_Tag_name_is_assigned_from_json);
RUN_TEST(test_User_id_is_assigned_from_json);
RUN_TEST(test_User_username_is_assigned_from_json);
RUN_TEST(test_User_firstName_is_assigned_from_json);
RUN_TEST(test_User_lastName_is_assigned_from_json);
RUN_TEST(test_User_email_is_assigned_from_json);
RUN_TEST(test_User_password_is_assigned_from_json);
RUN_TEST(test_User_phone_is_assigned_from_json);
RUN_TEST(test_User_userStatus_is_assigned_from_json);
RUN_TEST(test_ApiResponse_code_is_converted_to_json);
RUN_TEST(test_ApiResponse_type_is_converted_to_json);
RUN_TEST(test_ApiResponse_message_is_converted_to_json);
RUN_TEST(test_Category_id_is_converted_to_json);
RUN_TEST(test_Category_name_is_converted_to_json);
RUN_TEST(test_Order_id_is_converted_to_json);
RUN_TEST(test_Order_petId_is_converted_to_json);
RUN_TEST(test_Order_quantity_is_converted_to_json);
RUN_TEST(test_Order_shipDate_is_converted_to_json);
RUN_TEST(test_Order_status_is_converted_to_json);
RUN_TEST(test_Order_complete_is_converted_to_json);
RUN_TEST(test_Pet_id_is_converted_to_json);
RUN_TEST(test_Pet_name_is_converted_to_json);
RUN_TEST(test_Pet_status_is_converted_to_json);
RUN_TEST(test_Tag_id_is_converted_to_json);
RUN_TEST(test_Tag_name_is_converted_to_json);
RUN_TEST(test_User_id_is_converted_to_json);
RUN_TEST(test_User_username_is_converted_to_json);
RUN_TEST(test_User_firstName_is_converted_to_json);
RUN_TEST(test_User_lastName_is_converted_to_json);
RUN_TEST(test_User_email_is_converted_to_json);
RUN_TEST(test_User_password_is_converted_to_json);
RUN_TEST(test_User_phone_is_converted_to_json);
RUN_TEST(test_User_userStatus_is_converted_to_json);
}
int main(void) {
UNITY_BEGIN();
runTests();
return UNITY_END();
}
void setup() {
UNITY_BEGIN();
runTests();
UNITY_END();
}
void loop() {
}