forked from loafle/openapi-generator-original
[BUG] [C++][Pistache] cpp-pistache-server generating API include unde… (#18553)
* [BUG] [C++][Pistache] cpp-pistache-server generating API include undefined "Object.h" (#2769) Should handle Object.h, AnyType.h correctly. Set.h also tested. - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues - object had an invalid syntax: ':' instead of '::' in types with namespace - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp> - nlohmann::json is excluded from model namespace Tested with custom petstore played, with suggested openapi specs coming from issues #2769, #10266, #14234 ```bash rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel ``` * - Adding to samples/server/petstore cpp-pistache-everything * - .md and FILES missing
This commit is contained in:
parent
d3b156d694
commit
fde8c772fb
@ -0,0 +1,7 @@
|
|||||||
|
generatorName: cpp-pistache-server
|
||||||
|
outputDir: samples/server/petstore/cpp-pistache-everything
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issues-anytype-object-set-petstore-everything.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/cpp-pistache-server
|
||||||
|
additionalProperties:
|
||||||
|
useStructModel: "false"
|
||||||
|
addExternalLibs: "true"
|
@ -28,7 +28,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
|||||||
|
|
||||||
| Type/Alias | Imports |
|
| Type/Alias | Imports |
|
||||||
| ---------- | ------- |
|
| ---------- | ------- |
|
||||||
|Object|#include "Object.h"|
|
|
||||||
|nlohmann::json|#include <nlohmann/json.hpp>|
|
|nlohmann::json|#include <nlohmann/json.hpp>|
|
||||||
|std::map|#include <map>|
|
|std::map|#include <map>|
|
||||||
|std::string|#include <string>|
|
|std::string|#include <string>|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package org.openapitools.codegen.languages;
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.Operation;
|
import io.swagger.v3.oas.models.Operation;
|
||||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||||
import io.swagger.v3.oas.models.servers.Server;
|
import io.swagger.v3.oas.models.servers.Server;
|
||||||
@ -53,6 +52,27 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
protected final String PREFIX = "";
|
protected final String PREFIX = "";
|
||||||
protected String helpersPackage = "";
|
protected String helpersPackage = "";
|
||||||
|
|
||||||
|
/** OpenApi types that shouldn't have a namespace added with getTypeDeclaration() at generation time (for nlohmann::json) */
|
||||||
|
private final Set<String> openAPITypesWithoutModelNamespace = new HashSet<>();
|
||||||
|
|
||||||
|
/** int32_t (for integer) */
|
||||||
|
private static final String INT32_T = "int32_t";
|
||||||
|
|
||||||
|
/** int64_t (for long) */
|
||||||
|
private static final String INT64_T = "int64_t";
|
||||||
|
|
||||||
|
/** nlohmann::json (for object, AnyType) */
|
||||||
|
private static final String NLOHMANN_JSON = "nlohmann::json";
|
||||||
|
|
||||||
|
/** std:string (for date, DateTime, string, file, binary, UUID, URI, ByteArray) */
|
||||||
|
private static final String STD_STRING = "std::string";
|
||||||
|
|
||||||
|
/** std:map (for map) */
|
||||||
|
private static final String STD_MAP = "std::map";
|
||||||
|
|
||||||
|
/** std:vector (for array, set) */
|
||||||
|
private static final String STD_VECTOR = "std::vector";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenType getTag() {
|
public CodegenType getTag() {
|
||||||
return CodegenType.SERVER;
|
return CodegenType.SERVER;
|
||||||
@ -117,33 +137,35 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
setupSupportingFiles();
|
setupSupportingFiles();
|
||||||
|
|
||||||
languageSpecificPrimitives = new HashSet<>(
|
languageSpecificPrimitives = new HashSet<>(
|
||||||
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
|
Arrays.asList("int", "char", "bool", "long", "float", "double", INT32_T, INT64_T));
|
||||||
|
|
||||||
typeMapping = new HashMap<>();
|
typeMapping = new HashMap<>();
|
||||||
typeMapping.put("date", "std::string");
|
typeMapping.put("date", STD_STRING);
|
||||||
typeMapping.put("DateTime", "std::string");
|
typeMapping.put("DateTime", STD_STRING);
|
||||||
typeMapping.put("string", "std::string");
|
typeMapping.put("string", STD_STRING);
|
||||||
typeMapping.put("integer", "int32_t");
|
typeMapping.put("integer", INT32_T);
|
||||||
typeMapping.put("long", "int64_t");
|
typeMapping.put("long", INT64_T);
|
||||||
typeMapping.put("boolean", "bool");
|
typeMapping.put("boolean", "bool");
|
||||||
typeMapping.put("array", "std::vector");
|
typeMapping.put("array", STD_VECTOR);
|
||||||
typeMapping.put("map", "std::map");
|
typeMapping.put("map", STD_MAP);
|
||||||
typeMapping.put("set", "std::vector");
|
typeMapping.put("set", STD_VECTOR);
|
||||||
typeMapping.put("file", "std::string");
|
typeMapping.put("file", STD_STRING);
|
||||||
typeMapping.put("object", "Object");
|
typeMapping.put("object", NLOHMANN_JSON);
|
||||||
typeMapping.put("binary", "std::string");
|
typeMapping.put("binary", STD_STRING);
|
||||||
typeMapping.put("number", "double");
|
typeMapping.put("number", "double");
|
||||||
typeMapping.put("UUID", "std::string");
|
typeMapping.put("UUID", STD_STRING);
|
||||||
typeMapping.put("URI", "std::string");
|
typeMapping.put("URI", STD_STRING);
|
||||||
typeMapping.put("ByteArray", "std::string");
|
typeMapping.put("ByteArray", STD_STRING);
|
||||||
typeMapping.put("AnyType", "nlohmann::json");
|
typeMapping.put("AnyType", NLOHMANN_JSON);
|
||||||
|
|
||||||
super.importMapping = new HashMap<>();
|
super.importMapping = new HashMap<>();
|
||||||
importMapping.put("std::vector", "#include <vector>");
|
importMapping.put(STD_VECTOR, "#include <vector>");
|
||||||
importMapping.put("std::map", "#include <map>");
|
importMapping.put(STD_MAP, "#include <map>");
|
||||||
importMapping.put("std::string", "#include <string>");
|
importMapping.put(STD_STRING, "#include <string>");
|
||||||
importMapping.put("Object", "#include \"Object.h\"");
|
importMapping.put(NLOHMANN_JSON, "#include <nlohmann/json.hpp>");
|
||||||
importMapping.put("nlohmann::json", "#include <nlohmann/json.hpp>");
|
|
||||||
|
// nlohmann:json doesn't belong to model package
|
||||||
|
this.openAPITypesWithoutModelNamespace.add(NLOHMANN_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSupportingFiles() {
|
private void setupSupportingFiles() {
|
||||||
@ -202,8 +224,16 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toModelImport(String name) {
|
public String toModelImport(String name) {
|
||||||
|
// Do not reattempt to add #include on an already solved #include
|
||||||
|
if (name.startsWith("#include")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (importMapping.containsKey(name)) {
|
if (importMapping.containsKey(name)) {
|
||||||
return importMapping.get(name);
|
return importMapping.get(name);
|
||||||
} else {
|
} else {
|
||||||
@ -214,20 +244,23 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Schema model) {
|
public CodegenModel fromModel(String name, Schema model) {
|
||||||
|
// Exchange import directives from core model with ours
|
||||||
CodegenModel codegenModel = super.fromModel(name, model);
|
CodegenModel codegenModel = super.fromModel(name, model);
|
||||||
|
|
||||||
Set<String> oldImports = codegenModel.imports;
|
Set<String> oldImports = codegenModel.imports;
|
||||||
codegenModel.imports = new HashSet<>();
|
codegenModel.imports = new HashSet<>();
|
||||||
|
|
||||||
for (String imp : oldImports) {
|
for (String imp : oldImports) {
|
||||||
String newImp = toModelImport(imp);
|
String newImp = toModelImport(imp);
|
||||||
if (!newImp.isEmpty()) {
|
|
||||||
|
if (newImp != null && !newImp.isEmpty()) {
|
||||||
codegenModel.imports.add(newImp);
|
codegenModel.imports.add(newImp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!codegenModel.isEnum
|
if(!codegenModel.isEnum
|
||||||
&& codegenModel.anyOf.size()>1
|
&& codegenModel.anyOf.size()>1
|
||||||
&& codegenModel.anyOf.contains("std::string")
|
&& codegenModel.anyOf.contains(STD_STRING)
|
||||||
&& !codegenModel.anyOf.contains("AnyType")
|
&& !codegenModel.anyOf.contains("AnyType")
|
||||||
&& codegenModel.interfaces.size()==1
|
&& codegenModel.interfaces.size()==1
|
||||||
){
|
){
|
||||||
@ -388,7 +421,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||||
return "std::string";
|
return STD_STRING;
|
||||||
}
|
}
|
||||||
if (ModelUtils.isStringSchema(p)
|
if (ModelUtils.isStringSchema(p)
|
||||||
|| ModelUtils.isDateSchema(p)
|
|| ModelUtils.isDateSchema(p)
|
||||||
@ -397,8 +430,14 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
return toModelName(openAPIType);
|
return toModelName(openAPIType);
|
||||||
}
|
}
|
||||||
|
|
||||||
String namespace = (String)additionalProperties.get("modelNamespace");
|
// Some types might not support namespace
|
||||||
return namespace + "::" + openAPIType;
|
if (this.openAPITypesWithoutModelNamespace.contains(openAPIType)) {
|
||||||
|
return openAPIType;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String namespace = (String) additionalProperties.get("modelNamespace");
|
||||||
|
return namespace + "::" + openAPIType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.cpppistache;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.*;
|
||||||
|
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract test class to make one or multiple generators generate files for one specific input spec
|
||||||
|
*/
|
||||||
|
public abstract class AbstractGeneratorsTest {
|
||||||
|
/**
|
||||||
|
* Test each with a given input spec
|
||||||
|
* @param inputSpec The input spec to use
|
||||||
|
* @return Map of generator and files
|
||||||
|
* @throws IOException if the test directory cannot be created
|
||||||
|
*/
|
||||||
|
protected Map<String, List<File>> eachWith(String inputSpec) throws IOException {
|
||||||
|
Objects.requireNonNull(inputSpec, "Specify an inputspec to run that test");
|
||||||
|
Map<String, List<File>> generatedFilesByGenerator = new HashMap<>();
|
||||||
|
|
||||||
|
for (final CodegenConfig codegenConfig : CodegenConfigLoader.getAll()) {
|
||||||
|
generatedFilesByGenerator.put(codegenConfig.getName(), oneWith(codegenConfig.getName(), inputSpec));
|
||||||
|
}
|
||||||
|
|
||||||
|
return generatedFilesByGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test each with a given input spec
|
||||||
|
* @param generatorName the generator name to use
|
||||||
|
* @param inputSpec The input spec to use
|
||||||
|
* @return List of generated files
|
||||||
|
* @throws IOException if the test directory cannot be created
|
||||||
|
*/
|
||||||
|
protected List<File> oneWith(String generatorName, String inputSpec) throws IOException {
|
||||||
|
Objects.requireNonNull(generatorName, "Specify a generatorName to run that test");
|
||||||
|
Objects.requireNonNull(inputSpec, "Specify an inputspec to run that test");
|
||||||
|
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setGeneratorName(generatorName)
|
||||||
|
.setInputSpec(inputSpec)
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
return generator.opts(clientOptInput).generate();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.cpppistache;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.slf4j.*;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.asserts.SoftAssert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate from an input spec containing various abstract objects and sets
|
||||||
|
*/
|
||||||
|
public class ObjectAnyTypeSetTest extends AbstractGeneratorsTest {
|
||||||
|
/** Logger. */
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectAnyTypeSetTest.class);
|
||||||
|
|
||||||
|
/** A Petstore inputspec with abstract properties added in the Pet */
|
||||||
|
private static final String INPUT_SPEC = "src/test/resources/3_0/issues-anytype-object-set-petstore-everything.yaml";
|
||||||
|
|
||||||
|
/** Soft assert to check all the generators before eventually failing a test */
|
||||||
|
private final SoftAssert softAssert = new SoftAssert();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test some generators with an input spec requiring generation of abstract properties
|
||||||
|
* @throws IOException if the test folder cannot be created
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSomeWithPetstoreWithAbstract() throws IOException {
|
||||||
|
// assertGeneratedFiles("c");
|
||||||
|
// assertGeneratedFiles("cpp-restsdk");
|
||||||
|
generateFiles("cpp-pistache-server");
|
||||||
|
// assertGeneratedFiles("typescript");
|
||||||
|
this.softAssert.assertAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that a generator has produced some files
|
||||||
|
* @param generatorName The generator name to test
|
||||||
|
* @return List of files generated
|
||||||
|
* @throws IOException if the test folder cannot be created
|
||||||
|
*/
|
||||||
|
private List<File> generateFiles(String generatorName) throws IOException {
|
||||||
|
Objects.requireNonNull(generatorName, "A generator name is expected for this assertion");
|
||||||
|
return oneWith(generatorName, INPUT_SPEC);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
These test aren't useful yet
|
||||||
|
they only run the generator for a single case
|
@ -0,0 +1,815 @@
|
|||||||
|
openapi: 3.0.0
|
||||||
|
servers:
|
||||||
|
- url: 'http://petstore.swagger.io/v2'
|
||||||
|
info:
|
||||||
|
description: >-
|
||||||
|
This is a sample server Petstore server. For this sample, you can use the api key
|
||||||
|
`special-key` to test the authorization filters.
|
||||||
|
version: 1.0.0
|
||||||
|
title: OpenAPI Petstore
|
||||||
|
license:
|
||||||
|
name: Apache-2.0
|
||||||
|
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
|
||||||
|
tags:
|
||||||
|
- name: pet
|
||||||
|
description: Everything about your Pets
|
||||||
|
- name: store
|
||||||
|
description: Access to Petstore orders
|
||||||
|
- name: user
|
||||||
|
description: Operations about user
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/pet:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Add a new pet to the store
|
||||||
|
description: ''
|
||||||
|
operationId: addPet
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
'405':
|
||||||
|
description: Invalid input
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
requestBody:
|
||||||
|
$ref: '#/components/requestBodies/Pet'
|
||||||
|
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Update an existing pet
|
||||||
|
description: ''
|
||||||
|
operationId: updatePet
|
||||||
|
externalDocs:
|
||||||
|
url: "http://petstore.swagger.io/v2/doc/updatePet"
|
||||||
|
description: "API documentation for the updatePet operation"
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Pet not found
|
||||||
|
'405':
|
||||||
|
description: Validation exception
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
requestBody:
|
||||||
|
$ref: '#/components/requestBodies/Pet'
|
||||||
|
|
||||||
|
/pet/findByStatus:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Finds Pets by status
|
||||||
|
description: Multiple status values can be provided with comma separated strings
|
||||||
|
operationId: findPetsByStatus
|
||||||
|
parameters:
|
||||||
|
- name: status
|
||||||
|
in: query
|
||||||
|
description: Status values that need to be considered for filter
|
||||||
|
required: true
|
||||||
|
style: form
|
||||||
|
explode: false
|
||||||
|
deprecated: true
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- available
|
||||||
|
- pending
|
||||||
|
- sold
|
||||||
|
default: available
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid status value
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'read:pets'
|
||||||
|
|
||||||
|
/pet/findByTags:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Finds Pets by tags
|
||||||
|
description: >-
|
||||||
|
Multiple tags can be provided with comma separated strings. Use tag1,
|
||||||
|
tag2, tag3 for testing.
|
||||||
|
operationId: findPetsByTags
|
||||||
|
parameters:
|
||||||
|
- name: tags
|
||||||
|
in: query
|
||||||
|
description: Tags to filter by
|
||||||
|
required: true
|
||||||
|
style: form
|
||||||
|
explode: false
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid tag value
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'read:pets'
|
||||||
|
deprecated: true
|
||||||
|
|
||||||
|
'/pet/{petId}':
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Find pet by ID
|
||||||
|
description: Returns a single pet
|
||||||
|
operationId: getPetById
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: ID of pet to return
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Pet not found
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Updates a pet in the store with form data
|
||||||
|
description: ''
|
||||||
|
operationId: updatePetWithForm
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: ID of pet that needs to be updated
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'405':
|
||||||
|
description: Invalid input
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/x-www-form-urlencoded:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
description: Updated name of the pet
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
description: Updated status of the pet
|
||||||
|
type: string
|
||||||
|
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: Deletes a pet
|
||||||
|
description: ''
|
||||||
|
operationId: deletePet
|
||||||
|
parameters:
|
||||||
|
- name: api_key
|
||||||
|
in: header
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: Pet id to delete
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid pet value
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
|
||||||
|
'/pet/{petId}/uploadImage':
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- pet
|
||||||
|
summary: uploads an image
|
||||||
|
description: ''
|
||||||
|
operationId: uploadFile
|
||||||
|
parameters:
|
||||||
|
- name: petId
|
||||||
|
in: path
|
||||||
|
description: ID of pet to update
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ApiResponse'
|
||||||
|
security:
|
||||||
|
- petstore_auth:
|
||||||
|
- 'write:pets'
|
||||||
|
- 'read:pets'
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
multipart/form-data:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
additionalMetadata:
|
||||||
|
description: Additional data to pass to server
|
||||||
|
type: string
|
||||||
|
file:
|
||||||
|
description: file to upload
|
||||||
|
type: string
|
||||||
|
format: binary
|
||||||
|
|
||||||
|
/store/inventory:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Returns pet inventories by status
|
||||||
|
description: Returns a map of status codes to quantities
|
||||||
|
operationId: getInventory
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
|
||||||
|
/store/order:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Place an order for a pet
|
||||||
|
description: ''
|
||||||
|
operationId: placeOrder
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Order'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Order'
|
||||||
|
'400':
|
||||||
|
description: Invalid Order
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Order'
|
||||||
|
description: order placed for purchasing the pet
|
||||||
|
required: true
|
||||||
|
|
||||||
|
'/store/order/{orderId}':
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Find purchase order by ID
|
||||||
|
description: >-
|
||||||
|
For valid response try integer IDs with value <= 5 or > 10. Other values
|
||||||
|
will generate exceptions
|
||||||
|
operationId: getOrderById
|
||||||
|
parameters:
|
||||||
|
- name: orderId
|
||||||
|
in: path
|
||||||
|
description: ID of pet that needs to be fetched
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 1
|
||||||
|
maximum: 5
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Order'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Order'
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Order not found
|
||||||
|
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- store
|
||||||
|
summary: Delete purchase order by ID
|
||||||
|
description: >-
|
||||||
|
For valid response try integer IDs with value < 1000. Anything above
|
||||||
|
1000 or nonintegers will generate API errors
|
||||||
|
operationId: deleteOrder
|
||||||
|
parameters:
|
||||||
|
- name: orderId
|
||||||
|
in: path
|
||||||
|
description: ID of the order that needs to be deleted
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid ID supplied
|
||||||
|
'404':
|
||||||
|
description: Order not found
|
||||||
|
|
||||||
|
/user:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Create user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: createUser
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
description: Created user object
|
||||||
|
required: true
|
||||||
|
|
||||||
|
/user/createWithArray:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Creates list of users with given input array
|
||||||
|
description: ''
|
||||||
|
operationId: createUsersWithArrayInput
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
requestBody:
|
||||||
|
$ref: '#/components/requestBodies/UserArray'
|
||||||
|
|
||||||
|
/user/createWithList:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Creates list of users with given input array
|
||||||
|
description: ''
|
||||||
|
operationId: createUsersWithListInput
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
requestBody:
|
||||||
|
$ref: '#/components/requestBodies/UserArray'
|
||||||
|
|
||||||
|
/user/login:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Logs user into the system
|
||||||
|
description: ''
|
||||||
|
operationId: loginUser
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: query
|
||||||
|
description: The user name for login
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$'
|
||||||
|
- name: password
|
||||||
|
in: query
|
||||||
|
description: The password for login in clear text
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
headers:
|
||||||
|
Set-Cookie:
|
||||||
|
description: >-
|
||||||
|
Cookie authentication key for use with the `api_key`
|
||||||
|
apiKey authentication.
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
example: AUTH_KEY=abcde12345; Path=/; HttpOnly
|
||||||
|
X-Rate-Limit:
|
||||||
|
description: calls per hour allowed by the user
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
X-Expires-After:
|
||||||
|
description: date in UTC when token expires
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
'400':
|
||||||
|
description: Invalid username/password supplied
|
||||||
|
|
||||||
|
/user/logout:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Logs out current logged in user session
|
||||||
|
description: ''
|
||||||
|
operationId: logoutUser
|
||||||
|
responses:
|
||||||
|
default:
|
||||||
|
description: successful operation
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
|
||||||
|
'/user/{username}':
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Get user by user name
|
||||||
|
description: ''
|
||||||
|
operationId: getUserByName
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: path
|
||||||
|
description: The name that needs to be fetched. Use user1 for testing.
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successful operation
|
||||||
|
content:
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
'400':
|
||||||
|
description: Invalid username supplied
|
||||||
|
'404':
|
||||||
|
description: User not found
|
||||||
|
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Updated user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: updateUser
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: path
|
||||||
|
description: name that need to be deleted
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid user supplied
|
||||||
|
'404':
|
||||||
|
description: User not found
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
description: Updated user object
|
||||||
|
required: true
|
||||||
|
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
summary: Delete user
|
||||||
|
description: This can only be done by the logged in user.
|
||||||
|
operationId: deleteUser
|
||||||
|
parameters:
|
||||||
|
- name: username
|
||||||
|
in: path
|
||||||
|
description: The name that needs to be deleted
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
'400':
|
||||||
|
description: Invalid username supplied
|
||||||
|
'404':
|
||||||
|
description: User not found
|
||||||
|
security:
|
||||||
|
- api_key: []
|
||||||
|
|
||||||
|
externalDocs:
|
||||||
|
description: Find out more about Swagger
|
||||||
|
url: 'http://swagger.io'
|
||||||
|
|
||||||
|
components:
|
||||||
|
requestBodies:
|
||||||
|
UserArray:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
description: List of user object
|
||||||
|
required: true
|
||||||
|
|
||||||
|
Pet:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
application/xml:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
description: Pet object that needs to be added to the store
|
||||||
|
required: true
|
||||||
|
|
||||||
|
securitySchemes:
|
||||||
|
petstore_auth:
|
||||||
|
type: oauth2
|
||||||
|
flows:
|
||||||
|
implicit:
|
||||||
|
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
|
||||||
|
scopes:
|
||||||
|
'write:pets': modify pets in your account
|
||||||
|
'read:pets': read your pets
|
||||||
|
api_key:
|
||||||
|
type: apiKey
|
||||||
|
name: api_key
|
||||||
|
in: header
|
||||||
|
|
||||||
|
schemas:
|
||||||
|
Order:
|
||||||
|
title: Pet Order
|
||||||
|
description: An order for a pets from the pet store
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
petId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
quantity:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
shipDate:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Order Status
|
||||||
|
enum:
|
||||||
|
- placed
|
||||||
|
- approved
|
||||||
|
- delivered
|
||||||
|
complete:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
xml:
|
||||||
|
name: Order
|
||||||
|
|
||||||
|
Category:
|
||||||
|
title: Pet category
|
||||||
|
description: A category for a pet
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$'
|
||||||
|
xml:
|
||||||
|
name: Category
|
||||||
|
|
||||||
|
User:
|
||||||
|
title: a User
|
||||||
|
description: A User who is purchasing from the pet store
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
phone:
|
||||||
|
type: string
|
||||||
|
userStatus:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
description: User Status
|
||||||
|
xml:
|
||||||
|
name: User
|
||||||
|
|
||||||
|
Tag:
|
||||||
|
title: Pet Tag
|
||||||
|
description: A tag for a pet
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
xml:
|
||||||
|
name: Tag
|
||||||
|
|
||||||
|
Pet:
|
||||||
|
title: a Pet
|
||||||
|
description: A pet for sale in the pet store
|
||||||
|
type: object
|
||||||
|
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
- photoUrls
|
||||||
|
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
|
||||||
|
category:
|
||||||
|
$ref: '#/components/schemas/Category'
|
||||||
|
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
example: doggie
|
||||||
|
|
||||||
|
photoUrls:
|
||||||
|
type: array
|
||||||
|
xml:
|
||||||
|
name: photoUrl
|
||||||
|
wrapped: true
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
tags:
|
||||||
|
type: array
|
||||||
|
xml:
|
||||||
|
name: tag
|
||||||
|
wrapped: true
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Tag'
|
||||||
|
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: pet status in the store
|
||||||
|
deprecated: true
|
||||||
|
enum:
|
||||||
|
- available
|
||||||
|
- pending
|
||||||
|
- sold
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Properties that dedicate this configuration to this issue
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
# https://github.com/OpenAPITools/openapi-generator/issues/2769
|
||||||
|
# object property (leading to Object.h)
|
||||||
|
veterinarianVisit:
|
||||||
|
type: object
|
||||||
|
description: last veterinarian visit advice
|
||||||
|
|
||||||
|
# leading to Anytype.h
|
||||||
|
# https://github.com/OpenAPITools/openapi-generator/issues/10266
|
||||||
|
goodies:
|
||||||
|
type: array
|
||||||
|
items: {}
|
||||||
|
nullable: true
|
||||||
|
description: to help you installing your pet at home
|
||||||
|
|
||||||
|
# Leading to Set.h
|
||||||
|
# https://github.com/OpenAPITools/openapi-generator/issues/14234
|
||||||
|
bestFriends:
|
||||||
|
description: Pet best friends!
|
||||||
|
type: object
|
||||||
|
|
||||||
|
required:
|
||||||
|
- bestFriends
|
||||||
|
|
||||||
|
properties:
|
||||||
|
bestFriends:
|
||||||
|
type: array
|
||||||
|
uniqueItems: true
|
||||||
|
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
xml:
|
||||||
|
name: Pet
|
||||||
|
|
||||||
|
ApiResponse:
|
||||||
|
title: An uploaded response
|
||||||
|
description: Describes the result of uploading an image resource
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
message:
|
||||||
|
type: string
|
@ -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
|
@ -0,0 +1,32 @@
|
|||||||
|
CMakeLists.txt
|
||||||
|
README.md
|
||||||
|
api/ApiBase.h
|
||||||
|
api/PetApi.cpp
|
||||||
|
api/PetApi.h
|
||||||
|
api/StoreApi.cpp
|
||||||
|
api/StoreApi.h
|
||||||
|
api/UserApi.cpp
|
||||||
|
api/UserApi.h
|
||||||
|
impl/PetApiImpl.cpp
|
||||||
|
impl/PetApiImpl.h
|
||||||
|
impl/StoreApiImpl.cpp
|
||||||
|
impl/StoreApiImpl.h
|
||||||
|
impl/UserApiImpl.cpp
|
||||||
|
impl/UserApiImpl.h
|
||||||
|
main-api-server.cpp
|
||||||
|
model/ApiResponse.cpp
|
||||||
|
model/ApiResponse.h
|
||||||
|
model/Category.cpp
|
||||||
|
model/Category.h
|
||||||
|
model/Helpers.cpp
|
||||||
|
model/Helpers.h
|
||||||
|
model/Order.cpp
|
||||||
|
model/Order.h
|
||||||
|
model/Pet.cpp
|
||||||
|
model/Pet.h
|
||||||
|
model/Pet_bestFriends.cpp
|
||||||
|
model/Pet_bestFriends.h
|
||||||
|
model/Tag.cpp
|
||||||
|
model/Tag.h
|
||||||
|
model/User.cpp
|
||||||
|
model/User.h
|
@ -0,0 +1 @@
|
|||||||
|
7.6.0-SNAPSHOT
|
@ -0,0 +1,38 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.2)
|
||||||
|
|
||||||
|
project(api-server)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pg -g3" )
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||||
|
|
||||||
|
ExternalProject_Add(PISTACHE
|
||||||
|
GIT_REPOSITORY https://github.com/pistacheio/pistache.git
|
||||||
|
BUILD_IN_SOURCE true
|
||||||
|
INSTALL_COMMAND meson setup build --prefix=${EXTERNAL_INSTALL_LOCATION} --libdir=lib && meson install -C build
|
||||||
|
)
|
||||||
|
|
||||||
|
ExternalProject_Add(NLOHMANN
|
||||||
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||||
|
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DJSON_BuildTests=OFF
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
||||||
|
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
||||||
|
|
||||||
|
include_directories(model)
|
||||||
|
include_directories(api)
|
||||||
|
include_directories(impl)
|
||||||
|
|
||||||
|
file(GLOB SRCS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${SRCS} )
|
||||||
|
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
|
||||||
|
target_link_libraries(${PROJECT_NAME} pistache pthread)
|
48
samples/server/petstore/cpp-pistache-everything/README.md
Normal file
48
samples/server/petstore/cpp-pistache-everything/README.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# REST API Server for OpenAPI Petstore
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||||
|
It uses the [Pistache](https://github.com/oktal/pistache) Framework.
|
||||||
|
|
||||||
|
## Files organization
|
||||||
|
The Pistache C++ REST server generator creates three folders:
|
||||||
|
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
|
||||||
|
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
|
||||||
|
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
|
||||||
|
by the developer (a basic implementation is provided under the `impl` folder)
|
||||||
|
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
|
||||||
|
which extends the main API class and implements the abstract methods.
|
||||||
|
Every method receives the path and body parameters as constant reference variables and a reference to the response
|
||||||
|
object, that should be filled with the right response and sent at the end of the method with the command:
|
||||||
|
response.send(returnCode, responseBody, [mimeType])
|
||||||
|
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
|
||||||
|
|
||||||
|
The main folder contains also a file with a main that can be used to start the server.
|
||||||
|
Of course, is you should customize this file based on your needs
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
First of all, you need to download and install the libraries listed [here](#libraries-required).
|
||||||
|
|
||||||
|
Once the libraries are installed, in order to compile and run the server please follow the steps below:
|
||||||
|
```bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
Once compiled run the server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd build
|
||||||
|
./api-server
|
||||||
|
```
|
||||||
|
|
||||||
|
## Libraries required
|
||||||
|
- [pistache](http://pistache.io/quickstart)
|
||||||
|
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
|
||||||
|
put it under the model/nlohmann folder
|
||||||
|
|
||||||
|
## Namespaces
|
||||||
|
org.openapitools.server.api
|
||||||
|
org.openapitools.server.model
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* ApiBase.h
|
||||||
|
*
|
||||||
|
* Generalization of the Api classes
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ApiBase_H_
|
||||||
|
#define ApiBase_H_
|
||||||
|
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
class ApiBase {
|
||||||
|
public:
|
||||||
|
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
|
||||||
|
virtual ~ApiBase() = default;
|
||||||
|
virtual void init() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const std::shared_ptr<Pistache::Rest::Router> router;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
#endif /* ApiBase_H_ */
|
284
samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp
Normal file
284
samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp
Normal file
@ -0,0 +1,284 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PetApi.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::helpers;
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
const std::string PetApi::base = "/v2";
|
||||||
|
|
||||||
|
PetApi::PetApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
|
||||||
|
: ApiBase(rtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PetApi::init() {
|
||||||
|
setupRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PetApi::setupRoutes() {
|
||||||
|
using namespace Pistache::Rest;
|
||||||
|
|
||||||
|
Routes::Post(*router, base + "/pet", Routes::bind(&PetApi::add_pet_handler, this));
|
||||||
|
Routes::Delete(*router, base + "/pet/:petId", Routes::bind(&PetApi::delete_pet_handler, this));
|
||||||
|
Routes::Get(*router, base + "/pet/findByStatus", Routes::bind(&PetApi::find_pets_by_status_handler, this));
|
||||||
|
Routes::Get(*router, base + "/pet/findByTags", Routes::bind(&PetApi::find_pets_by_tags_handler, this));
|
||||||
|
Routes::Get(*router, base + "/pet/:petId", Routes::bind(&PetApi::get_pet_by_id_handler, this));
|
||||||
|
Routes::Put(*router, base + "/pet", Routes::bind(&PetApi::update_pet_handler, this));
|
||||||
|
Routes::Post(*router, base + "/pet/:petId", Routes::bind(&PetApi::update_pet_with_form_handler, this));
|
||||||
|
Routes::Post(*router, base + "/pet/:petId/uploadImage", Routes::bind(&PetApi::upload_file_handler, this));
|
||||||
|
|
||||||
|
// Default handler, called when a route is not found
|
||||||
|
router->addCustomHandler(Routes::bind(&PetApi::pet_api_default_handler, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Pistache::Http::Code, std::string> PetApi::handleParsingException(const std::exception& ex) const noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
throw;
|
||||||
|
} catch (nlohmann::detail::exception &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
} catch (org::openapitools::server::helpers::ValidationException &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Pistache::Http::Code, std::string> PetApi::handleOperationException(const std::exception& ex) const noexcept
|
||||||
|
{
|
||||||
|
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
|
||||||
|
Pet pet;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(pet);
|
||||||
|
pet.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->add_pet(pet, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto petId = request.param(":petId").as<int64_t>();
|
||||||
|
|
||||||
|
// Getting the header params
|
||||||
|
auto apiKey = request.headers().tryGetRaw("api_key");
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->delete_pet(petId, apiKey, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the query params
|
||||||
|
auto statusQuery = request.query().get("status");
|
||||||
|
std::optional<std::vector<std::string>> status;
|
||||||
|
if(statusQuery.has_value()){
|
||||||
|
std::vector<std::string> valueQuery_instance;
|
||||||
|
if(fromStringValue(statusQuery.value(), valueQuery_instance)){
|
||||||
|
status = valueQuery_instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->find_pets_by_status(status, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the query params
|
||||||
|
auto tagsQuery = request.query().get("tags");
|
||||||
|
std::optional<std::vector<std::string>> tags;
|
||||||
|
if(tagsQuery.has_value()){
|
||||||
|
std::vector<std::string> valueQuery_instance;
|
||||||
|
if(fromStringValue(tagsQuery.value(), valueQuery_instance)){
|
||||||
|
tags = valueQuery_instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->find_pets_by_tags(tags, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto petId = request.param(":petId").as<int64_t>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->get_pet_by_id(petId, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
|
||||||
|
Pet pet;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(pet);
|
||||||
|
pet.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->update_pet(pet, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->update_pet_with_form(request, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->upload_file(request, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PetApi::pet_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||||
|
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
143
samples/server/petstore/cpp-pistache-everything/api/PetApi.h
Normal file
143
samples/server/petstore/cpp-pistache-everything/api/PetApi.h
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* PetApi.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PetApi_H_
|
||||||
|
#define PetApi_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "ApiBase.h"
|
||||||
|
|
||||||
|
#include <pistache/http.h>
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <pistache/http_headers.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "ApiResponse.h"
|
||||||
|
#include "Pet.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
class PetApi : public ApiBase {
|
||||||
|
public:
|
||||||
|
explicit PetApi(const std::shared_ptr<Pistache::Rest::Router>& rtr);
|
||||||
|
~PetApi() override = default;
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
static const std::string base;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupRoutes();
|
||||||
|
|
||||||
|
void add_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void delete_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void find_pets_by_status_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void find_pets_by_tags_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void get_pet_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void update_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void pet_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||||
|
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||||
|
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||||
|
/// </summary>
|
||||||
|
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||||
|
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||||
|
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||||
|
/// </summary>
|
||||||
|
virtual std::pair<Pistache::Http::Code, std::string> handleOperationException(const std::exception& ex) const noexcept;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new pet to the store
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="pet">Pet object that needs to be added to the store</param>
|
||||||
|
virtual void add_pet(const org::openapitools::server::model::Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a pet
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="petId">Pet id to delete</param>
|
||||||
|
/// <param name="apiKey"> (optional, default to "")</param>
|
||||||
|
virtual void delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Finds Pets by status
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Multiple status values can be provided with comma separated strings
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="status">Status values that need to be considered for filter</param>
|
||||||
|
virtual void find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Finds Pets by tags
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="tags">Tags to filter by</param>
|
||||||
|
virtual void find_pets_by_tags(const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Find pet by ID
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Returns a single pet
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="petId">ID of pet to return</param>
|
||||||
|
virtual void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Update an existing pet
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="pet">Pet object that needs to be added to the store</param>
|
||||||
|
virtual void update_pet(const org::openapitools::server::model::Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a pet in the store with form data
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
virtual void update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// uploads an image
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
virtual void upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
#endif /* PetApi_H_ */
|
||||||
|
|
166
samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp
Normal file
166
samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StoreApi.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::helpers;
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
const std::string StoreApi::base = "/v2";
|
||||||
|
|
||||||
|
StoreApi::StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
|
||||||
|
: ApiBase(rtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoreApi::init() {
|
||||||
|
setupRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoreApi::setupRoutes() {
|
||||||
|
using namespace Pistache::Rest;
|
||||||
|
|
||||||
|
Routes::Delete(*router, base + "/store/order/:orderId", Routes::bind(&StoreApi::delete_order_handler, this));
|
||||||
|
Routes::Get(*router, base + "/store/inventory", Routes::bind(&StoreApi::get_inventory_handler, this));
|
||||||
|
Routes::Get(*router, base + "/store/order/:orderId", Routes::bind(&StoreApi::get_order_by_id_handler, this));
|
||||||
|
Routes::Post(*router, base + "/store/order", Routes::bind(&StoreApi::place_order_handler, this));
|
||||||
|
|
||||||
|
// Default handler, called when a route is not found
|
||||||
|
router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(const std::exception& ex) const noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
throw;
|
||||||
|
} catch (nlohmann::detail::exception &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
} catch (org::openapitools::server::helpers::ValidationException &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Pistache::Http::Code, std::string> StoreApi::handleOperationException(const std::exception& ex) const noexcept
|
||||||
|
{
|
||||||
|
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto orderId = request.param(":orderId").as<std::string>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->delete_order(orderId, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->get_inventory(response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto orderId = request.param(":orderId").as<int64_t>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->get_order_by_id(orderId, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
|
||||||
|
Order order;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(order);
|
||||||
|
order.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->place_order(order, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoreApi::store_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||||
|
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
106
samples/server/petstore/cpp-pistache-everything/api/StoreApi.h
Normal file
106
samples/server/petstore/cpp-pistache-everything/api/StoreApi.h
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* StoreApi.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef StoreApi_H_
|
||||||
|
#define StoreApi_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "ApiBase.h"
|
||||||
|
|
||||||
|
#include <pistache/http.h>
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <pistache/http_headers.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "Order.h"
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
class StoreApi : public ApiBase {
|
||||||
|
public:
|
||||||
|
explicit StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr);
|
||||||
|
~StoreApi() override = default;
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
static const std::string base;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupRoutes();
|
||||||
|
|
||||||
|
void delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void get_inventory_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||||
|
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||||
|
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||||
|
/// </summary>
|
||||||
|
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||||
|
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||||
|
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||||
|
/// </summary>
|
||||||
|
virtual std::pair<Pistache::Http::Code, std::string> handleOperationException(const std::exception& ex) const noexcept;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete purchase order by ID
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||||
|
virtual void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Returns pet inventories by status
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Returns a map of status codes to quantities
|
||||||
|
/// </remarks>
|
||||||
|
virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Find purchase order by ID
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||||
|
virtual void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Place an order for a pet
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="order">order placed for purchasing the pet</param>
|
||||||
|
virtual void place_order(const org::openapitools::server::model::Order &order, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
#endif /* StoreApi_H_ */
|
||||||
|
|
309
samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp
Normal file
309
samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UserApi.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::helpers;
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
const std::string UserApi::base = "/v2";
|
||||||
|
|
||||||
|
UserApi::UserApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
|
||||||
|
: ApiBase(rtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserApi::init() {
|
||||||
|
setupRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserApi::setupRoutes() {
|
||||||
|
using namespace Pistache::Rest;
|
||||||
|
|
||||||
|
Routes::Post(*router, base + "/user", Routes::bind(&UserApi::create_user_handler, this));
|
||||||
|
Routes::Post(*router, base + "/user/createWithArray", Routes::bind(&UserApi::create_users_with_array_input_handler, this));
|
||||||
|
Routes::Post(*router, base + "/user/createWithList", Routes::bind(&UserApi::create_users_with_list_input_handler, this));
|
||||||
|
Routes::Delete(*router, base + "/user/:username", Routes::bind(&UserApi::delete_user_handler, this));
|
||||||
|
Routes::Get(*router, base + "/user/:username", Routes::bind(&UserApi::get_user_by_name_handler, this));
|
||||||
|
Routes::Get(*router, base + "/user/login", Routes::bind(&UserApi::login_user_handler, this));
|
||||||
|
Routes::Get(*router, base + "/user/logout", Routes::bind(&UserApi::logout_user_handler, this));
|
||||||
|
Routes::Put(*router, base + "/user/:username", Routes::bind(&UserApi::update_user_handler, this));
|
||||||
|
|
||||||
|
// Default handler, called when a route is not found
|
||||||
|
router->addCustomHandler(Routes::bind(&UserApi::user_api_default_handler, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Pistache::Http::Code, std::string> UserApi::handleParsingException(const std::exception& ex) const noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
throw;
|
||||||
|
} catch (nlohmann::detail::exception &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
} catch (org::openapitools::server::helpers::ValidationException &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<Pistache::Http::Code, std::string> UserApi::handleOperationException(const std::exception& ex) const noexcept
|
||||||
|
{
|
||||||
|
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
|
||||||
|
User user;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(user);
|
||||||
|
user.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->create_user(user, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
std::vector<User> user;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(user);
|
||||||
|
for (const auto& validationParam : user)
|
||||||
|
validationParam.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->create_users_with_array_input(user, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
std::vector<User> user;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(user);
|
||||||
|
for (const auto& validationParam : user)
|
||||||
|
validationParam.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->create_users_with_list_input(user, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto username = request.param(":username").as<std::string>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->delete_user(username, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto username = request.param(":username").as<std::string>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->get_user_by_name(username, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
// Getting the query params
|
||||||
|
auto usernameQuery = request.query().get("username");
|
||||||
|
std::optional<std::string> username;
|
||||||
|
if(usernameQuery.has_value()){
|
||||||
|
std::string valueQuery_instance;
|
||||||
|
if(fromStringValue(usernameQuery.value(), valueQuery_instance)){
|
||||||
|
username = valueQuery_instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto passwordQuery = request.query().get("password");
|
||||||
|
std::optional<std::string> password;
|
||||||
|
if(passwordQuery.has_value()){
|
||||||
|
std::string valueQuery_instance;
|
||||||
|
if(fromStringValue(passwordQuery.value(), valueQuery_instance)){
|
||||||
|
password = valueQuery_instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->login_user(username, password, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->logout_user(response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Getting the path params
|
||||||
|
auto username = request.param(":username").as<std::string>();
|
||||||
|
|
||||||
|
// Getting the body param
|
||||||
|
|
||||||
|
User user;
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json::parse(request.body()).get_to(user);
|
||||||
|
user.validate();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this->update_user(username, user, response);
|
||||||
|
} catch (Pistache::Http::HttpError &e) {
|
||||||
|
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||||
|
return;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||||
|
response.send(errorInfo.first, errorInfo.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserApi::user_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||||
|
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
144
samples/server/petstore/cpp-pistache-everything/api/UserApi.h
Normal file
144
samples/server/petstore/cpp-pistache-everything/api/UserApi.h
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* UserApi.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UserApi_H_
|
||||||
|
#define UserApi_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "ApiBase.h"
|
||||||
|
|
||||||
|
#include <pistache/http.h>
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <pistache/http_headers.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "User.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
class UserApi : public ApiBase {
|
||||||
|
public:
|
||||||
|
explicit UserApi(const std::shared_ptr<Pistache::Rest::Router>& rtr);
|
||||||
|
~UserApi() override = default;
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
static const std::string base;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupRoutes();
|
||||||
|
|
||||||
|
void create_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void delete_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void get_user_by_name_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void login_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void logout_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
void user_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||||
|
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||||
|
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||||
|
/// </summary>
|
||||||
|
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||||
|
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||||
|
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||||
|
/// </summary>
|
||||||
|
virtual std::pair<Pistache::Http::Code, std::string> handleOperationException(const std::exception& ex) const noexcept;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create user
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This can only be done by the logged in user.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="user">Created user object</param>
|
||||||
|
virtual void create_user(const org::openapitools::server::model::User &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Creates list of users with given input array
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="user">List of user object</param>
|
||||||
|
virtual void create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Creates list of users with given input array
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="user">List of user object</param>
|
||||||
|
virtual void create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Delete user
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This can only be done by the logged in user.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="username">The name that needs to be deleted</param>
|
||||||
|
virtual void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Get user by user name
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
|
||||||
|
virtual void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Logs user into the system
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="username">The user name for login</param>
|
||||||
|
/// <param name="password">The password for login in clear text</param>
|
||||||
|
virtual void login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Logs out current logged in user session
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
virtual void logout_user(Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Updated user
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This can only be done by the logged in user.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="username">name that need to be deleted</param>
|
||||||
|
/// <param name="user">Updated user object</param>
|
||||||
|
virtual void update_user(const std::string &username, const org::openapitools::server::model::User &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
#endif /* UserApi_H_ */
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PetApiImpl.h"
|
||||||
|
|
||||||
|
namespace org {
|
||||||
|
namespace openapitools {
|
||||||
|
namespace server {
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
PetApiImpl::PetApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
|
||||||
|
: PetApi(rtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PetApiImpl::add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::find_pets_by_tags(const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void PetApiImpl::upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PetApiImpl.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PET_API_IMPL_H_
|
||||||
|
#define PET_API_IMPL_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <pistache/endpoint.h>
|
||||||
|
#include <pistache/http.h>
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include <PetApi.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "ApiResponse.h"
|
||||||
|
#include "Pet.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
class PetApiImpl : public org::openapitools::server::api::PetApi {
|
||||||
|
public:
|
||||||
|
explicit PetApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr);
|
||||||
|
~PetApiImpl() override = default;
|
||||||
|
|
||||||
|
void add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response);
|
||||||
|
void delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response);
|
||||||
|
void find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response);
|
||||||
|
void find_pets_by_tags(const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response);
|
||||||
|
void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response);
|
||||||
|
void update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response);
|
||||||
|
void update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
|
||||||
|
void upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StoreApiImpl.h"
|
||||||
|
|
||||||
|
namespace org {
|
||||||
|
namespace openapitools {
|
||||||
|
namespace server {
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
StoreApiImpl::StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
|
||||||
|
: StoreApi(rtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoreApiImpl::delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void StoreApiImpl::get_inventory(Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void StoreApiImpl::get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void StoreApiImpl::place_order(const Order &order, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* StoreApiImpl.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef STORE_API_IMPL_H_
|
||||||
|
#define STORE_API_IMPL_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <pistache/endpoint.h>
|
||||||
|
#include <pistache/http.h>
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include <StoreApi.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Order.h"
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
class StoreApiImpl : public org::openapitools::server::api::StoreApi {
|
||||||
|
public:
|
||||||
|
explicit StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr);
|
||||||
|
~StoreApiImpl() override = default;
|
||||||
|
|
||||||
|
void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response);
|
||||||
|
void get_inventory(Pistache::Http::ResponseWriter &response);
|
||||||
|
void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response);
|
||||||
|
void place_order(const Order &order, Pistache::Http::ResponseWriter &response);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UserApiImpl.h"
|
||||||
|
|
||||||
|
namespace org {
|
||||||
|
namespace openapitools {
|
||||||
|
namespace server {
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
UserApiImpl::UserApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
|
||||||
|
: UserApi(rtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserApiImpl::create_user(const User &user, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::logout_user(Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
void UserApiImpl::update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response) {
|
||||||
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* UserApiImpl.h
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef USER_API_IMPL_H_
|
||||||
|
#define USER_API_IMPL_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <pistache/endpoint.h>
|
||||||
|
#include <pistache/http.h>
|
||||||
|
#include <pistache/router.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include <UserApi.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "User.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::api
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::model;
|
||||||
|
|
||||||
|
class UserApiImpl : public org::openapitools::server::api::UserApi {
|
||||||
|
public:
|
||||||
|
explicit UserApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr);
|
||||||
|
~UserApiImpl() override = default;
|
||||||
|
|
||||||
|
void create_user(const User &user, Pistache::Http::ResponseWriter &response);
|
||||||
|
void create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response);
|
||||||
|
void create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response);
|
||||||
|
void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response);
|
||||||
|
void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response);
|
||||||
|
void login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response);
|
||||||
|
void logout_user(Pistache::Http::ResponseWriter &response);
|
||||||
|
void update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::api
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,97 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "pistache/endpoint.h"
|
||||||
|
#include "pistache/http.h"
|
||||||
|
#include "pistache/router.h"
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <vector>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ApiBase.h"
|
||||||
|
|
||||||
|
#include "PetApiImpl.h"
|
||||||
|
#include "StoreApiImpl.h"
|
||||||
|
#include "UserApiImpl.h"
|
||||||
|
|
||||||
|
#define PISTACHE_SERVER_THREADS 2
|
||||||
|
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
|
||||||
|
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
|
||||||
|
|
||||||
|
static Pistache::Http::Endpoint *httpEndpoint;
|
||||||
|
#ifdef __linux__
|
||||||
|
static void sigHandler [[noreturn]] (int sig){
|
||||||
|
switch(sig){
|
||||||
|
case SIGINT:
|
||||||
|
case SIGQUIT:
|
||||||
|
case SIGTERM:
|
||||||
|
case SIGHUP:
|
||||||
|
default:
|
||||||
|
httpEndpoint->shutdown();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setUpUnixSignals(std::vector<int> quitSignals) {
|
||||||
|
sigset_t blocking_mask;
|
||||||
|
sigemptyset(&blocking_mask);
|
||||||
|
for (auto sig : quitSignals)
|
||||||
|
sigaddset(&blocking_mask, sig);
|
||||||
|
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_handler = sigHandler;
|
||||||
|
sa.sa_mask = blocking_mask;
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
|
||||||
|
for (auto sig : quitSignals)
|
||||||
|
sigaction(sig, &sa, nullptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace org::openapitools::server::api;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#ifdef __linux__
|
||||||
|
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
|
||||||
|
setUpUnixSignals(sigs);
|
||||||
|
#endif
|
||||||
|
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080));
|
||||||
|
|
||||||
|
httpEndpoint = new Pistache::Http::Endpoint((addr));
|
||||||
|
auto router = std::make_shared<Pistache::Rest::Router>();
|
||||||
|
|
||||||
|
auto opts = Pistache::Http::Endpoint::options()
|
||||||
|
.threads(PISTACHE_SERVER_THREADS);
|
||||||
|
opts.flags(Pistache::Tcp::Options::ReuseAddr);
|
||||||
|
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
|
||||||
|
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
|
||||||
|
httpEndpoint->init(opts);
|
||||||
|
|
||||||
|
auto apiImpls = std::vector<std::shared_ptr<ApiBase>>();
|
||||||
|
|
||||||
|
apiImpls.push_back(std::make_shared<PetApiImpl>(router));
|
||||||
|
apiImpls.push_back(std::make_shared<StoreApiImpl>(router));
|
||||||
|
apiImpls.push_back(std::make_shared<UserApiImpl>(router));
|
||||||
|
|
||||||
|
for (auto api : apiImpls) {
|
||||||
|
api->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
httpEndpoint->setHandler(router->handler());
|
||||||
|
httpEndpoint->serve();
|
||||||
|
|
||||||
|
httpEndpoint->shutdown();
|
||||||
|
}
|
@ -0,0 +1,164 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ApiResponse.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
ApiResponse::ApiResponse()
|
||||||
|
{
|
||||||
|
m_Code = 0;
|
||||||
|
m_CodeIsSet = false;
|
||||||
|
m_Type = "";
|
||||||
|
m_TypeIsSet = false;
|
||||||
|
m_Message = "";
|
||||||
|
m_MessageIsSet = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiResponse::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApiResponse::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApiResponse::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "ApiResponse" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApiResponse::operator==(const ApiResponse& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
((!codeIsSet() && !rhs.codeIsSet()) || (codeIsSet() && rhs.codeIsSet() && getCode() == rhs.getCode())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!typeIsSet() && !rhs.typeIsSet()) || (typeIsSet() && rhs.typeIsSet() && getType() == rhs.getType())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!messageIsSet() && !rhs.messageIsSet()) || (messageIsSet() && rhs.messageIsSet() && getMessage() == rhs.getMessage()))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApiResponse::operator!=(const ApiResponse& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const ApiResponse& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
if(o.codeIsSet())
|
||||||
|
j["code"] = o.m_Code;
|
||||||
|
if(o.typeIsSet())
|
||||||
|
j["type"] = o.m_Type;
|
||||||
|
if(o.messageIsSet())
|
||||||
|
j["message"] = o.m_Message;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, ApiResponse& o)
|
||||||
|
{
|
||||||
|
if(j.find("code") != j.end())
|
||||||
|
{
|
||||||
|
j.at("code").get_to(o.m_Code);
|
||||||
|
o.m_CodeIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("type") != j.end())
|
||||||
|
{
|
||||||
|
j.at("type").get_to(o.m_Type);
|
||||||
|
o.m_TypeIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("message") != j.end())
|
||||||
|
{
|
||||||
|
j.at("message").get_to(o.m_Message);
|
||||||
|
o.m_MessageIsSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ApiResponse::getCode() const
|
||||||
|
{
|
||||||
|
return m_Code;
|
||||||
|
}
|
||||||
|
void ApiResponse::setCode(int32_t const value)
|
||||||
|
{
|
||||||
|
m_Code = value;
|
||||||
|
m_CodeIsSet = true;
|
||||||
|
}
|
||||||
|
bool ApiResponse::codeIsSet() const
|
||||||
|
{
|
||||||
|
return m_CodeIsSet;
|
||||||
|
}
|
||||||
|
void ApiResponse::unsetCode()
|
||||||
|
{
|
||||||
|
m_CodeIsSet = false;
|
||||||
|
}
|
||||||
|
std::string ApiResponse::getType() const
|
||||||
|
{
|
||||||
|
return m_Type;
|
||||||
|
}
|
||||||
|
void ApiResponse::setType(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Type = value;
|
||||||
|
m_TypeIsSet = true;
|
||||||
|
}
|
||||||
|
bool ApiResponse::typeIsSet() const
|
||||||
|
{
|
||||||
|
return m_TypeIsSet;
|
||||||
|
}
|
||||||
|
void ApiResponse::unsetType()
|
||||||
|
{
|
||||||
|
m_TypeIsSet = false;
|
||||||
|
}
|
||||||
|
std::string ApiResponse::getMessage() const
|
||||||
|
{
|
||||||
|
return m_Message;
|
||||||
|
}
|
||||||
|
void ApiResponse::setMessage(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Message = value;
|
||||||
|
m_MessageIsSet = true;
|
||||||
|
}
|
||||||
|
bool ApiResponse::messageIsSet() const
|
||||||
|
{
|
||||||
|
return m_MessageIsSet;
|
||||||
|
}
|
||||||
|
void ApiResponse::unsetMessage()
|
||||||
|
{
|
||||||
|
m_MessageIsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
@ -0,0 +1,97 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* ApiResponse.h
|
||||||
|
*
|
||||||
|
* Describes the result of uploading an image resource
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ApiResponse_H_
|
||||||
|
#define ApiResponse_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Describes the result of uploading an image resource
|
||||||
|
/// </summary>
|
||||||
|
class ApiResponse
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ApiResponse();
|
||||||
|
virtual ~ApiResponse() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const ApiResponse& rhs) const;
|
||||||
|
bool operator!=(const ApiResponse& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// ApiResponse members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int32_t getCode() const;
|
||||||
|
void setCode(int32_t const value);
|
||||||
|
bool codeIsSet() const;
|
||||||
|
void unsetCode();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getType() const;
|
||||||
|
void setType(std::string const& value);
|
||||||
|
bool typeIsSet() const;
|
||||||
|
void unsetType();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getMessage() const;
|
||||||
|
void setMessage(std::string const& value);
|
||||||
|
bool messageIsSet() const;
|
||||||
|
void unsetMessage();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const ApiResponse& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, ApiResponse& o);
|
||||||
|
protected:
|
||||||
|
int32_t m_Code;
|
||||||
|
bool m_CodeIsSet;
|
||||||
|
std::string m_Type;
|
||||||
|
bool m_TypeIsSet;
|
||||||
|
std::string m_Message;
|
||||||
|
bool m_MessageIsSet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* ApiResponse_H_ */
|
@ -0,0 +1,144 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Category.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
Category::Category()
|
||||||
|
{
|
||||||
|
m_Id = 0L;
|
||||||
|
m_IdIsSet = false;
|
||||||
|
m_Name = "";
|
||||||
|
m_NameIsSet = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Category::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Category::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Category::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "Category" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
if (nameIsSet())
|
||||||
|
{
|
||||||
|
const std::string& value = m_Name;
|
||||||
|
const std::string currentValuePath = _pathPrefix + ".name";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Category::operator==(const Category& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
((!idIsSet() && !rhs.idIsSet()) || (idIsSet() && rhs.idIsSet() && getId() == rhs.getId())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!nameIsSet() && !rhs.nameIsSet()) || (nameIsSet() && rhs.nameIsSet() && getName() == rhs.getName()))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Category::operator!=(const Category& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const Category& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
if(o.idIsSet())
|
||||||
|
j["id"] = o.m_Id;
|
||||||
|
if(o.nameIsSet())
|
||||||
|
j["name"] = o.m_Name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, Category& o)
|
||||||
|
{
|
||||||
|
if(j.find("id") != j.end())
|
||||||
|
{
|
||||||
|
j.at("id").get_to(o.m_Id);
|
||||||
|
o.m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("name") != j.end())
|
||||||
|
{
|
||||||
|
j.at("name").get_to(o.m_Name);
|
||||||
|
o.m_NameIsSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Category::getId() const
|
||||||
|
{
|
||||||
|
return m_Id;
|
||||||
|
}
|
||||||
|
void Category::setId(int64_t const value)
|
||||||
|
{
|
||||||
|
m_Id = value;
|
||||||
|
m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
bool Category::idIsSet() const
|
||||||
|
{
|
||||||
|
return m_IdIsSet;
|
||||||
|
}
|
||||||
|
void Category::unsetId()
|
||||||
|
{
|
||||||
|
m_IdIsSet = false;
|
||||||
|
}
|
||||||
|
std::string Category::getName() const
|
||||||
|
{
|
||||||
|
return m_Name;
|
||||||
|
}
|
||||||
|
void Category::setName(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Name = value;
|
||||||
|
m_NameIsSet = true;
|
||||||
|
}
|
||||||
|
bool Category::nameIsSet() const
|
||||||
|
{
|
||||||
|
return m_NameIsSet;
|
||||||
|
}
|
||||||
|
void Category::unsetName()
|
||||||
|
{
|
||||||
|
m_NameIsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Category.h
|
||||||
|
*
|
||||||
|
* A category for a pet
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Category_H_
|
||||||
|
#define Category_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A category for a pet
|
||||||
|
/// </summary>
|
||||||
|
class Category
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Category();
|
||||||
|
virtual ~Category() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const Category& rhs) const;
|
||||||
|
bool operator!=(const Category& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// Category members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int64_t getId() const;
|
||||||
|
void setId(int64_t const value);
|
||||||
|
bool idIsSet() const;
|
||||||
|
void unsetId();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getName() const;
|
||||||
|
void setName(std::string const& value);
|
||||||
|
bool nameIsSet() const;
|
||||||
|
void unsetName();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Category& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Category& o);
|
||||||
|
protected:
|
||||||
|
int64_t m_Id;
|
||||||
|
bool m_IdIsSet;
|
||||||
|
std::string m_Name;
|
||||||
|
bool m_NameIsSet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* Category_H_ */
|
@ -0,0 +1,148 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
#include "Helpers.h"
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::helpers
|
||||||
|
{
|
||||||
|
|
||||||
|
const std::regex regexRfc3339_date(R"(^(\d{4})\-(\d{2})\-(\d{2})$)");
|
||||||
|
const std::regex regexRfc3339_date_time(
|
||||||
|
R"(^(\d{4})\-(\d{2})\-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|([\+\-])(\d{2}):(\d{2}))$)"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Determine if given year is a leap year
|
||||||
|
// See RFC 3339, Appendix C https://tools.ietf.org/html/rfc3339#appendix-C
|
||||||
|
bool isLeapYear(const uint16_t year) {
|
||||||
|
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateDateValues(const uint16_t year, const uint16_t month, const uint16_t day) {
|
||||||
|
return !(
|
||||||
|
(month == 0 || month > 12)
|
||||||
|
|| (day == 0)
|
||||||
|
|| (month == 2 && day > (28 + (isLeapYear(year) ? 1 : 0)))
|
||||||
|
|| (month <= 7 && day > (30 + month % 2))
|
||||||
|
|| (month >= 8 && day > (31 - month % 2))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateTimeValues(const uint16_t hours, const uint16_t minutes, const uint16_t seconds) {
|
||||||
|
return (hours <= 23) && (minutes <= 59) && (seconds <= 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateRfc3339_date(const std::string& str) {
|
||||||
|
std::smatch match;
|
||||||
|
const bool found = std::regex_search(str, match, regexRfc3339_date);
|
||||||
|
return found && validateDateValues(static_cast<uint16_t>(std::stoi(match[1])),
|
||||||
|
static_cast<uint16_t>(std::stoi(match[2])),
|
||||||
|
static_cast<uint16_t>(std::stoi(match[3])));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateRfc3339_date_time(const std::string& str) {
|
||||||
|
std::smatch match;
|
||||||
|
const bool found = std::regex_search(str, match, regexRfc3339_date_time);
|
||||||
|
return found
|
||||||
|
&& validateDateValues(static_cast<uint16_t>(std::stoi(match[1])),
|
||||||
|
static_cast<uint16_t>(std::stoi(match[2])),
|
||||||
|
static_cast<uint16_t>(std::stoi(match[3])))
|
||||||
|
&& validateTimeValues(static_cast<uint16_t>(std::stoi(match[4])),
|
||||||
|
static_cast<uint16_t>(std::stoi(match[5])),
|
||||||
|
static_cast<uint16_t>(std::stoi(match[6])));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const std::string &value){
|
||||||
|
return std::string(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const int32_t value){
|
||||||
|
return std::to_string(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const int64_t value){
|
||||||
|
return std::to_string(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const bool value){
|
||||||
|
return value ? std::string("true") : std::string("false");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const float value){
|
||||||
|
return std::to_string(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const double value){
|
||||||
|
return std::to_string(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, std::string &value){
|
||||||
|
value = std::string(inStr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, int32_t &value){
|
||||||
|
try {
|
||||||
|
value = std::stoi( inStr );
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, int64_t &value){
|
||||||
|
try {
|
||||||
|
value = std::stol( inStr );
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, bool &value){
|
||||||
|
if (inStr == "true") {
|
||||||
|
value = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (inStr == "false") {
|
||||||
|
value = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, float &value){
|
||||||
|
try {
|
||||||
|
value = std::stof( inStr );
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, double &value){
|
||||||
|
try {
|
||||||
|
value = std::stod( inStr );
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::helpers
|
136
samples/server/petstore/cpp-pistache-everything/model/Helpers.h
Normal file
136
samples/server/petstore/cpp-pistache-everything/model/Helpers.h
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Helpers.h
|
||||||
|
*
|
||||||
|
* This is the helper class for models and primitives
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Helpers_H_
|
||||||
|
#define Helpers_H_
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::helpers
|
||||||
|
{
|
||||||
|
|
||||||
|
class ValidationException : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ValidationException(const std::string& what)
|
||||||
|
: std::runtime_error(what)
|
||||||
|
{ }
|
||||||
|
~ValidationException() override = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate a string against the full-date definition of RFC 3339, section 5.6.
|
||||||
|
/// </summary>
|
||||||
|
bool validateRfc3339_date(const std::string& str);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate a string against the date-time definition of RFC 3339, section 5.6.
|
||||||
|
/// </summary>
|
||||||
|
bool validateRfc3339_date_time(const std::string& str);
|
||||||
|
|
||||||
|
namespace sfinae_helpers
|
||||||
|
{
|
||||||
|
struct NoType {};
|
||||||
|
template <typename T1, typename T2> NoType operator==(const T1&, const T2&);
|
||||||
|
|
||||||
|
template <typename T1, typename T2> class EqualsOperatorAvailable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
value = !std::is_same< decltype(std::declval<T1>() == std::declval<T2>()), NoType >::value
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} // namespace sfinae_helpers
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determine if the given vector<T> only has unique elements. T must provide the == operator.
|
||||||
|
/// </summary>
|
||||||
|
template <typename T>
|
||||||
|
bool hasOnlyUniqueItems(const std::vector<T>& vec)
|
||||||
|
{
|
||||||
|
static_assert(sfinae_helpers::EqualsOperatorAvailable<T, T>::value,
|
||||||
|
"hasOnlyUniqueItems<T> cannot be called, passed template type does not provide == operator.");
|
||||||
|
if (vec.size() <= 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Compare every element of vec to every other element of vec.
|
||||||
|
// This isn't an elegant way to do this, since it's O(n^2),
|
||||||
|
// but it's the best solution working only with the == operator.
|
||||||
|
// This could be greatly improved if our models provided a valid hash
|
||||||
|
// and/or the < operator
|
||||||
|
for (size_t i = 0; i < vec.size() - 1; i++)
|
||||||
|
{
|
||||||
|
for (size_t j = i + 1; j < vec.size(); j++)
|
||||||
|
{
|
||||||
|
if (vec[i] == vec[j])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toStringValue(const std::string &value);
|
||||||
|
std::string toStringValue(const int32_t value);
|
||||||
|
std::string toStringValue(const int64_t value);
|
||||||
|
std::string toStringValue(const bool value);
|
||||||
|
std::string toStringValue(const float value);
|
||||||
|
std::string toStringValue(const double value);
|
||||||
|
|
||||||
|
bool fromStringValue(const std::string &inStr, std::string &value);
|
||||||
|
bool fromStringValue(const std::string &inStr, int32_t &value);
|
||||||
|
bool fromStringValue(const std::string &inStr, int64_t &value);
|
||||||
|
bool fromStringValue(const std::string &inStr, bool &value);
|
||||||
|
bool fromStringValue(const std::string &inStr, float &value);
|
||||||
|
bool fromStringValue(const std::string &inStr, double &value);
|
||||||
|
template<typename T>
|
||||||
|
bool fromStringValue(const std::vector<std::string> &inStr, std::vector<T> &value){
|
||||||
|
try{
|
||||||
|
for(auto & item : inStr){
|
||||||
|
T itemValue;
|
||||||
|
if(fromStringValue(item, itemValue)){
|
||||||
|
value.push_back(itemValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(...){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return value.size() > 0;
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
bool fromStringValue(const std::string &inStr, std::vector<T> &value, char separator = ','){
|
||||||
|
std::vector<std::string> inStrings;
|
||||||
|
std::istringstream f(inStr);
|
||||||
|
std::string s;
|
||||||
|
while (std::getline(f, s, separator)) {
|
||||||
|
inStrings.push_back(s);
|
||||||
|
}
|
||||||
|
return fromStringValue(inStrings, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::helpers
|
||||||
|
|
||||||
|
#endif // Helpers_H_
|
251
samples/server/petstore/cpp-pistache-everything/model/Order.cpp
Normal file
251
samples/server/petstore/cpp-pistache-everything/model/Order.cpp
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Order.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
Order::Order()
|
||||||
|
{
|
||||||
|
m_Id = 0L;
|
||||||
|
m_IdIsSet = false;
|
||||||
|
m_PetId = 0L;
|
||||||
|
m_PetIdIsSet = false;
|
||||||
|
m_Quantity = 0;
|
||||||
|
m_QuantityIsSet = false;
|
||||||
|
m_ShipDate = "";
|
||||||
|
m_ShipDateIsSet = false;
|
||||||
|
m_Status = "";
|
||||||
|
m_StatusIsSet = false;
|
||||||
|
m_Complete = false;
|
||||||
|
m_CompleteIsSet = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Order::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Order::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Order::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "Order" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Order::operator==(const Order& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
((!idIsSet() && !rhs.idIsSet()) || (idIsSet() && rhs.idIsSet() && getId() == rhs.getId())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!petIdIsSet() && !rhs.petIdIsSet()) || (petIdIsSet() && rhs.petIdIsSet() && getPetId() == rhs.getPetId())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!quantityIsSet() && !rhs.quantityIsSet()) || (quantityIsSet() && rhs.quantityIsSet() && getQuantity() == rhs.getQuantity())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!shipDateIsSet() && !rhs.shipDateIsSet()) || (shipDateIsSet() && rhs.shipDateIsSet() && getShipDate() == rhs.getShipDate())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!statusIsSet() && !rhs.statusIsSet()) || (statusIsSet() && rhs.statusIsSet() && getStatus() == rhs.getStatus())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!completeIsSet() && !rhs.completeIsSet()) || (completeIsSet() && rhs.completeIsSet() && isComplete() == rhs.isComplete()))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Order::operator!=(const Order& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const Order& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
if(o.idIsSet())
|
||||||
|
j["id"] = o.m_Id;
|
||||||
|
if(o.petIdIsSet())
|
||||||
|
j["petId"] = o.m_PetId;
|
||||||
|
if(o.quantityIsSet())
|
||||||
|
j["quantity"] = o.m_Quantity;
|
||||||
|
if(o.shipDateIsSet())
|
||||||
|
j["shipDate"] = o.m_ShipDate;
|
||||||
|
if(o.statusIsSet())
|
||||||
|
j["status"] = o.m_Status;
|
||||||
|
if(o.completeIsSet())
|
||||||
|
j["complete"] = o.m_Complete;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, Order& o)
|
||||||
|
{
|
||||||
|
if(j.find("id") != j.end())
|
||||||
|
{
|
||||||
|
j.at("id").get_to(o.m_Id);
|
||||||
|
o.m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("petId") != j.end())
|
||||||
|
{
|
||||||
|
j.at("petId").get_to(o.m_PetId);
|
||||||
|
o.m_PetIdIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("quantity") != j.end())
|
||||||
|
{
|
||||||
|
j.at("quantity").get_to(o.m_Quantity);
|
||||||
|
o.m_QuantityIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("shipDate") != j.end())
|
||||||
|
{
|
||||||
|
j.at("shipDate").get_to(o.m_ShipDate);
|
||||||
|
o.m_ShipDateIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("status") != j.end())
|
||||||
|
{
|
||||||
|
j.at("status").get_to(o.m_Status);
|
||||||
|
o.m_StatusIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("complete") != j.end())
|
||||||
|
{
|
||||||
|
j.at("complete").get_to(o.m_Complete);
|
||||||
|
o.m_CompleteIsSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Order::getId() const
|
||||||
|
{
|
||||||
|
return m_Id;
|
||||||
|
}
|
||||||
|
void Order::setId(int64_t const value)
|
||||||
|
{
|
||||||
|
m_Id = value;
|
||||||
|
m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
bool Order::idIsSet() const
|
||||||
|
{
|
||||||
|
return m_IdIsSet;
|
||||||
|
}
|
||||||
|
void Order::unsetId()
|
||||||
|
{
|
||||||
|
m_IdIsSet = false;
|
||||||
|
}
|
||||||
|
int64_t Order::getPetId() const
|
||||||
|
{
|
||||||
|
return m_PetId;
|
||||||
|
}
|
||||||
|
void Order::setPetId(int64_t const value)
|
||||||
|
{
|
||||||
|
m_PetId = value;
|
||||||
|
m_PetIdIsSet = true;
|
||||||
|
}
|
||||||
|
bool Order::petIdIsSet() const
|
||||||
|
{
|
||||||
|
return m_PetIdIsSet;
|
||||||
|
}
|
||||||
|
void Order::unsetPetId()
|
||||||
|
{
|
||||||
|
m_PetIdIsSet = false;
|
||||||
|
}
|
||||||
|
int32_t Order::getQuantity() const
|
||||||
|
{
|
||||||
|
return m_Quantity;
|
||||||
|
}
|
||||||
|
void Order::setQuantity(int32_t const value)
|
||||||
|
{
|
||||||
|
m_Quantity = value;
|
||||||
|
m_QuantityIsSet = true;
|
||||||
|
}
|
||||||
|
bool Order::quantityIsSet() const
|
||||||
|
{
|
||||||
|
return m_QuantityIsSet;
|
||||||
|
}
|
||||||
|
void Order::unsetQuantity()
|
||||||
|
{
|
||||||
|
m_QuantityIsSet = false;
|
||||||
|
}
|
||||||
|
std::string Order::getShipDate() const
|
||||||
|
{
|
||||||
|
return m_ShipDate;
|
||||||
|
}
|
||||||
|
void Order::setShipDate(std::string const& value)
|
||||||
|
{
|
||||||
|
m_ShipDate = value;
|
||||||
|
m_ShipDateIsSet = true;
|
||||||
|
}
|
||||||
|
bool Order::shipDateIsSet() const
|
||||||
|
{
|
||||||
|
return m_ShipDateIsSet;
|
||||||
|
}
|
||||||
|
void Order::unsetShipDate()
|
||||||
|
{
|
||||||
|
m_ShipDateIsSet = false;
|
||||||
|
}
|
||||||
|
std::string Order::getStatus() const
|
||||||
|
{
|
||||||
|
return m_Status;
|
||||||
|
}
|
||||||
|
void Order::setStatus(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Status = value;
|
||||||
|
m_StatusIsSet = true;
|
||||||
|
}
|
||||||
|
bool Order::statusIsSet() const
|
||||||
|
{
|
||||||
|
return m_StatusIsSet;
|
||||||
|
}
|
||||||
|
void Order::unsetStatus()
|
||||||
|
{
|
||||||
|
m_StatusIsSet = false;
|
||||||
|
}
|
||||||
|
bool Order::isComplete() const
|
||||||
|
{
|
||||||
|
return m_Complete;
|
||||||
|
}
|
||||||
|
void Order::setComplete(bool const value)
|
||||||
|
{
|
||||||
|
m_Complete = value;
|
||||||
|
m_CompleteIsSet = true;
|
||||||
|
}
|
||||||
|
bool Order::completeIsSet() const
|
||||||
|
{
|
||||||
|
return m_CompleteIsSet;
|
||||||
|
}
|
||||||
|
void Order::unsetComplete()
|
||||||
|
{
|
||||||
|
m_CompleteIsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
124
samples/server/petstore/cpp-pistache-everything/model/Order.h
Normal file
124
samples/server/petstore/cpp-pistache-everything/model/Order.h
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Order.h
|
||||||
|
*
|
||||||
|
* An order for a pets from the pet store
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Order_H_
|
||||||
|
#define Order_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An order for a pets from the pet store
|
||||||
|
/// </summary>
|
||||||
|
class Order
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Order();
|
||||||
|
virtual ~Order() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const Order& rhs) const;
|
||||||
|
bool operator!=(const Order& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// Order members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int64_t getId() const;
|
||||||
|
void setId(int64_t const value);
|
||||||
|
bool idIsSet() const;
|
||||||
|
void unsetId();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int64_t getPetId() const;
|
||||||
|
void setPetId(int64_t const value);
|
||||||
|
bool petIdIsSet() const;
|
||||||
|
void unsetPetId();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int32_t getQuantity() const;
|
||||||
|
void setQuantity(int32_t const value);
|
||||||
|
bool quantityIsSet() const;
|
||||||
|
void unsetQuantity();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getShipDate() const;
|
||||||
|
void setShipDate(std::string const& value);
|
||||||
|
bool shipDateIsSet() const;
|
||||||
|
void unsetShipDate();
|
||||||
|
/// <summary>
|
||||||
|
/// Order Status
|
||||||
|
/// </summary>
|
||||||
|
std::string getStatus() const;
|
||||||
|
void setStatus(std::string const& value);
|
||||||
|
bool statusIsSet() const;
|
||||||
|
void unsetStatus();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
bool isComplete() const;
|
||||||
|
void setComplete(bool const value);
|
||||||
|
bool completeIsSet() const;
|
||||||
|
void unsetComplete();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Order& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Order& o);
|
||||||
|
protected:
|
||||||
|
int64_t m_Id;
|
||||||
|
bool m_IdIsSet;
|
||||||
|
int64_t m_PetId;
|
||||||
|
bool m_PetIdIsSet;
|
||||||
|
int32_t m_Quantity;
|
||||||
|
bool m_QuantityIsSet;
|
||||||
|
std::string m_ShipDate;
|
||||||
|
bool m_ShipDateIsSet;
|
||||||
|
std::string m_Status;
|
||||||
|
bool m_StatusIsSet;
|
||||||
|
bool m_Complete;
|
||||||
|
bool m_CompleteIsSet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* Order_H_ */
|
365
samples/server/petstore/cpp-pistache-everything/model/Pet.cpp
Normal file
365
samples/server/petstore/cpp-pistache-everything/model/Pet.cpp
Normal file
@ -0,0 +1,365 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Pet.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
Pet::Pet()
|
||||||
|
{
|
||||||
|
m_Id = 0L;
|
||||||
|
m_IdIsSet = false;
|
||||||
|
m_CategoryIsSet = false;
|
||||||
|
m_Name = "";
|
||||||
|
m_TagsIsSet = false;
|
||||||
|
m_Status = "";
|
||||||
|
m_StatusIsSet = false;
|
||||||
|
m_VeterinarianVisitIsSet = false;
|
||||||
|
m_GoodiesIsSet = false;
|
||||||
|
m_BestFriendsIsSet = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pet::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "Pet" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* PhotoUrls */ {
|
||||||
|
const std::vector<std::string>& value = m_PhotoUrls;
|
||||||
|
const std::string currentValuePath = _pathPrefix + ".photoUrls";
|
||||||
|
|
||||||
|
|
||||||
|
{ // Recursive validation of array elements
|
||||||
|
const std::string oldValuePath = currentValuePath;
|
||||||
|
int i = 0;
|
||||||
|
for (const std::string& value : value)
|
||||||
|
{
|
||||||
|
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tagsIsSet())
|
||||||
|
{
|
||||||
|
const std::vector<org::openapitools::server::model::Tag>& value = m_Tags;
|
||||||
|
const std::string currentValuePath = _pathPrefix + ".tags";
|
||||||
|
|
||||||
|
|
||||||
|
{ // Recursive validation of array elements
|
||||||
|
const std::string oldValuePath = currentValuePath;
|
||||||
|
int i = 0;
|
||||||
|
for (const org::openapitools::server::model::Tag& value : value)
|
||||||
|
{
|
||||||
|
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
|
||||||
|
|
||||||
|
success = value.validate(msg, currentValuePath + ".tags") && success;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goodiesIsSet())
|
||||||
|
{
|
||||||
|
const std::vector<nlohmann::json>& value = m_Goodies;
|
||||||
|
const std::string currentValuePath = _pathPrefix + ".goodies";
|
||||||
|
|
||||||
|
|
||||||
|
{ // Recursive validation of array elements
|
||||||
|
const std::string oldValuePath = currentValuePath;
|
||||||
|
int i = 0;
|
||||||
|
for (const nlohmann::json& value : value)
|
||||||
|
{
|
||||||
|
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet::operator==(const Pet& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
((!idIsSet() && !rhs.idIsSet()) || (idIsSet() && rhs.idIsSet() && getId() == rhs.getId())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!categoryIsSet() && !rhs.categoryIsSet()) || (categoryIsSet() && rhs.categoryIsSet() && getCategory() == rhs.getCategory())) &&
|
||||||
|
|
||||||
|
(getName() == rhs.getName())
|
||||||
|
&&
|
||||||
|
|
||||||
|
(getPhotoUrls() == rhs.getPhotoUrls())
|
||||||
|
&&
|
||||||
|
|
||||||
|
|
||||||
|
((!tagsIsSet() && !rhs.tagsIsSet()) || (tagsIsSet() && rhs.tagsIsSet() && getTags() == rhs.getTags())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!statusIsSet() && !rhs.statusIsSet()) || (statusIsSet() && rhs.statusIsSet() && getStatus() == rhs.getStatus())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!veterinarianVisitIsSet() && !rhs.veterinarianVisitIsSet()) || (veterinarianVisitIsSet() && rhs.veterinarianVisitIsSet() && getVeterinarianVisit() == rhs.getVeterinarianVisit())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!goodiesIsSet() && !rhs.goodiesIsSet()) || (goodiesIsSet() && rhs.goodiesIsSet() && getGoodies() == rhs.getGoodies())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!bestFriendsIsSet() && !rhs.bestFriendsIsSet()) || (bestFriendsIsSet() && rhs.bestFriendsIsSet() && getBestFriends() == rhs.getBestFriends()))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet::operator!=(const Pet& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const Pet& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
if(o.idIsSet())
|
||||||
|
j["id"] = o.m_Id;
|
||||||
|
if(o.categoryIsSet())
|
||||||
|
j["category"] = o.m_Category;
|
||||||
|
j["name"] = o.m_Name;
|
||||||
|
j["photoUrls"] = o.m_PhotoUrls;
|
||||||
|
if(o.tagsIsSet() || !o.m_Tags.empty())
|
||||||
|
j["tags"] = o.m_Tags;
|
||||||
|
if(o.statusIsSet())
|
||||||
|
j["status"] = o.m_Status;
|
||||||
|
if(o.veterinarianVisitIsSet())
|
||||||
|
j["veterinarianVisit"] = o.m_VeterinarianVisit;
|
||||||
|
if(o.goodiesIsSet() || !o.m_Goodies.empty())
|
||||||
|
j["goodies"] = o.m_Goodies;
|
||||||
|
if(o.bestFriendsIsSet())
|
||||||
|
j["bestFriends"] = o.m_BestFriends;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, Pet& o)
|
||||||
|
{
|
||||||
|
if(j.find("id") != j.end())
|
||||||
|
{
|
||||||
|
j.at("id").get_to(o.m_Id);
|
||||||
|
o.m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("category") != j.end())
|
||||||
|
{
|
||||||
|
j.at("category").get_to(o.m_Category);
|
||||||
|
o.m_CategoryIsSet = true;
|
||||||
|
}
|
||||||
|
j.at("name").get_to(o.m_Name);
|
||||||
|
j.at("photoUrls").get_to(o.m_PhotoUrls);
|
||||||
|
if(j.find("tags") != j.end())
|
||||||
|
{
|
||||||
|
j.at("tags").get_to(o.m_Tags);
|
||||||
|
o.m_TagsIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("status") != j.end())
|
||||||
|
{
|
||||||
|
j.at("status").get_to(o.m_Status);
|
||||||
|
o.m_StatusIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("veterinarianVisit") != j.end())
|
||||||
|
{
|
||||||
|
j.at("veterinarianVisit").get_to(o.m_VeterinarianVisit);
|
||||||
|
o.m_VeterinarianVisitIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("goodies") != j.end())
|
||||||
|
{
|
||||||
|
j.at("goodies").get_to(o.m_Goodies);
|
||||||
|
o.m_GoodiesIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("bestFriends") != j.end())
|
||||||
|
{
|
||||||
|
j.at("bestFriends").get_to(o.m_BestFriends);
|
||||||
|
o.m_BestFriendsIsSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Pet::getId() const
|
||||||
|
{
|
||||||
|
return m_Id;
|
||||||
|
}
|
||||||
|
void Pet::setId(int64_t const value)
|
||||||
|
{
|
||||||
|
m_Id = value;
|
||||||
|
m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::idIsSet() const
|
||||||
|
{
|
||||||
|
return m_IdIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetId()
|
||||||
|
{
|
||||||
|
m_IdIsSet = false;
|
||||||
|
}
|
||||||
|
org::openapitools::server::model::Category Pet::getCategory() const
|
||||||
|
{
|
||||||
|
return m_Category;
|
||||||
|
}
|
||||||
|
void Pet::setCategory(org::openapitools::server::model::Category const& value)
|
||||||
|
{
|
||||||
|
m_Category = value;
|
||||||
|
m_CategoryIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::categoryIsSet() const
|
||||||
|
{
|
||||||
|
return m_CategoryIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetCategory()
|
||||||
|
{
|
||||||
|
m_CategoryIsSet = false;
|
||||||
|
}
|
||||||
|
std::string Pet::getName() const
|
||||||
|
{
|
||||||
|
return m_Name;
|
||||||
|
}
|
||||||
|
void Pet::setName(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Name = value;
|
||||||
|
}
|
||||||
|
std::vector<std::string> Pet::getPhotoUrls() const
|
||||||
|
{
|
||||||
|
return m_PhotoUrls;
|
||||||
|
}
|
||||||
|
void Pet::setPhotoUrls(std::vector<std::string> const& value)
|
||||||
|
{
|
||||||
|
m_PhotoUrls = value;
|
||||||
|
}
|
||||||
|
std::vector<org::openapitools::server::model::Tag> Pet::getTags() const
|
||||||
|
{
|
||||||
|
return m_Tags;
|
||||||
|
}
|
||||||
|
void Pet::setTags(std::vector<org::openapitools::server::model::Tag> const& value)
|
||||||
|
{
|
||||||
|
m_Tags = value;
|
||||||
|
m_TagsIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::tagsIsSet() const
|
||||||
|
{
|
||||||
|
return m_TagsIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetTags()
|
||||||
|
{
|
||||||
|
m_TagsIsSet = false;
|
||||||
|
}
|
||||||
|
std::string Pet::getStatus() const
|
||||||
|
{
|
||||||
|
return m_Status;
|
||||||
|
}
|
||||||
|
void Pet::setStatus(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Status = value;
|
||||||
|
m_StatusIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::statusIsSet() const
|
||||||
|
{
|
||||||
|
return m_StatusIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetStatus()
|
||||||
|
{
|
||||||
|
m_StatusIsSet = false;
|
||||||
|
}
|
||||||
|
nlohmann::json Pet::getVeterinarianVisit() const
|
||||||
|
{
|
||||||
|
return m_VeterinarianVisit;
|
||||||
|
}
|
||||||
|
void Pet::setVeterinarianVisit(nlohmann::json const& value)
|
||||||
|
{
|
||||||
|
m_VeterinarianVisit = value;
|
||||||
|
m_VeterinarianVisitIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::veterinarianVisitIsSet() const
|
||||||
|
{
|
||||||
|
return m_VeterinarianVisitIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetVeterinarianVisit()
|
||||||
|
{
|
||||||
|
m_VeterinarianVisitIsSet = false;
|
||||||
|
}
|
||||||
|
std::vector<nlohmann::json> Pet::getGoodies() const
|
||||||
|
{
|
||||||
|
return m_Goodies;
|
||||||
|
}
|
||||||
|
void Pet::setGoodies(std::vector<nlohmann::json> const& value)
|
||||||
|
{
|
||||||
|
m_Goodies = value;
|
||||||
|
m_GoodiesIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::goodiesIsSet() const
|
||||||
|
{
|
||||||
|
return m_GoodiesIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetGoodies()
|
||||||
|
{
|
||||||
|
m_GoodiesIsSet = false;
|
||||||
|
}
|
||||||
|
org::openapitools::server::model::Pet_bestFriends Pet::getBestFriends() const
|
||||||
|
{
|
||||||
|
return m_BestFriends;
|
||||||
|
}
|
||||||
|
void Pet::setBestFriends(org::openapitools::server::model::Pet_bestFriends const& value)
|
||||||
|
{
|
||||||
|
m_BestFriends = value;
|
||||||
|
m_BestFriendsIsSet = true;
|
||||||
|
}
|
||||||
|
bool Pet::bestFriendsIsSet() const
|
||||||
|
{
|
||||||
|
return m_BestFriendsIsSet;
|
||||||
|
}
|
||||||
|
void Pet::unsetBestFriends()
|
||||||
|
{
|
||||||
|
m_BestFriendsIsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
152
samples/server/petstore/cpp-pistache-everything/model/Pet.h
Normal file
152
samples/server/petstore/cpp-pistache-everything/model/Pet.h
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Pet.h
|
||||||
|
*
|
||||||
|
* A pet for sale in the pet store
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Pet_H_
|
||||||
|
#define Pet_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "Tag.h"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "Pet_bestFriends.h"
|
||||||
|
#include <string>
|
||||||
|
#include "Category.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A pet for sale in the pet store
|
||||||
|
/// </summary>
|
||||||
|
class Pet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Pet();
|
||||||
|
virtual ~Pet() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const Pet& rhs) const;
|
||||||
|
bool operator!=(const Pet& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// Pet members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int64_t getId() const;
|
||||||
|
void setId(int64_t const value);
|
||||||
|
bool idIsSet() const;
|
||||||
|
void unsetId();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
org::openapitools::server::model::Category getCategory() const;
|
||||||
|
void setCategory(org::openapitools::server::model::Category const& value);
|
||||||
|
bool categoryIsSet() const;
|
||||||
|
void unsetCategory();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getName() const;
|
||||||
|
void setName(std::string const& value);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::vector<std::string> getPhotoUrls() const;
|
||||||
|
void setPhotoUrls(std::vector<std::string> const& value);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::vector<org::openapitools::server::model::Tag> getTags() const;
|
||||||
|
void setTags(std::vector<org::openapitools::server::model::Tag> const& value);
|
||||||
|
bool tagsIsSet() const;
|
||||||
|
void unsetTags();
|
||||||
|
/// <summary>
|
||||||
|
/// pet status in the store
|
||||||
|
/// </summary>
|
||||||
|
std::string getStatus() const;
|
||||||
|
void setStatus(std::string const& value);
|
||||||
|
bool statusIsSet() const;
|
||||||
|
void unsetStatus();
|
||||||
|
/// <summary>
|
||||||
|
/// last veterinarian visit advice
|
||||||
|
/// </summary>
|
||||||
|
nlohmann::json getVeterinarianVisit() const;
|
||||||
|
void setVeterinarianVisit(nlohmann::json const& value);
|
||||||
|
bool veterinarianVisitIsSet() const;
|
||||||
|
void unsetVeterinarianVisit();
|
||||||
|
/// <summary>
|
||||||
|
/// to help you installing your pet at home
|
||||||
|
/// </summary>
|
||||||
|
std::vector<nlohmann::json> getGoodies() const;
|
||||||
|
void setGoodies(std::vector<nlohmann::json> const& value);
|
||||||
|
bool goodiesIsSet() const;
|
||||||
|
void unsetGoodies();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
org::openapitools::server::model::Pet_bestFriends getBestFriends() const;
|
||||||
|
void setBestFriends(org::openapitools::server::model::Pet_bestFriends const& value);
|
||||||
|
bool bestFriendsIsSet() const;
|
||||||
|
void unsetBestFriends();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Pet& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Pet& o);
|
||||||
|
protected:
|
||||||
|
int64_t m_Id;
|
||||||
|
bool m_IdIsSet;
|
||||||
|
org::openapitools::server::model::Category m_Category;
|
||||||
|
bool m_CategoryIsSet;
|
||||||
|
std::string m_Name;
|
||||||
|
|
||||||
|
std::vector<std::string> m_PhotoUrls;
|
||||||
|
|
||||||
|
std::vector<org::openapitools::server::model::Tag> m_Tags;
|
||||||
|
bool m_TagsIsSet;
|
||||||
|
std::string m_Status;
|
||||||
|
bool m_StatusIsSet;
|
||||||
|
nlohmann::json m_VeterinarianVisit;
|
||||||
|
bool m_VeterinarianVisitIsSet;
|
||||||
|
std::vector<nlohmann::json> m_Goodies;
|
||||||
|
bool m_GoodiesIsSet;
|
||||||
|
org::openapitools::server::model::Pet_bestFriends m_BestFriends;
|
||||||
|
bool m_BestFriendsIsSet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* Pet_H_ */
|
@ -0,0 +1,116 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Pet_bestFriends.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
Pet_bestFriends::Pet_bestFriends()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pet_bestFriends::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet_bestFriends::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet_bestFriends::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "Pet_bestFriends" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* BestFriends */ {
|
||||||
|
const std::vector<std::string>& value = m_BestFriends;
|
||||||
|
const std::string currentValuePath = _pathPrefix + ".bestFriends";
|
||||||
|
|
||||||
|
|
||||||
|
if (!org::openapitools::server::helpers::hasOnlyUniqueItems(value))
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
msg << currentValuePath << ": may not contain the same item more than once;";
|
||||||
|
}
|
||||||
|
{ // Recursive validation of array elements
|
||||||
|
const std::string oldValuePath = currentValuePath;
|
||||||
|
int i = 0;
|
||||||
|
for (const std::string& value : value)
|
||||||
|
{
|
||||||
|
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet_bestFriends::operator==(const Pet_bestFriends& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
(getBestFriends() == rhs.getBestFriends())
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pet_bestFriends::operator!=(const Pet_bestFriends& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const Pet_bestFriends& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
j["bestFriends"] = o.m_BestFriends;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, Pet_bestFriends& o)
|
||||||
|
{
|
||||||
|
j.at("bestFriends").get_to(o.m_BestFriends);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Pet_bestFriends::getBestFriends() const
|
||||||
|
{
|
||||||
|
return m_BestFriends;
|
||||||
|
}
|
||||||
|
void Pet_bestFriends::setBestFriends(std::vector<std::string> const& value)
|
||||||
|
{
|
||||||
|
m_BestFriends = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Pet_bestFriends.h
|
||||||
|
*
|
||||||
|
* Pet best friends!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Pet_bestFriends_H_
|
||||||
|
#define Pet_bestFriends_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pet best friends!
|
||||||
|
/// </summary>
|
||||||
|
class Pet_bestFriends
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Pet_bestFriends();
|
||||||
|
virtual ~Pet_bestFriends() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const Pet_bestFriends& rhs) const;
|
||||||
|
bool operator!=(const Pet_bestFriends& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// Pet_bestFriends members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::vector<std::string> getBestFriends() const;
|
||||||
|
void setBestFriends(std::vector<std::string> const& value);
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Pet_bestFriends& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Pet_bestFriends& o);
|
||||||
|
protected:
|
||||||
|
std::vector<std::string> m_BestFriends;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* Pet_bestFriends_H_ */
|
135
samples/server/petstore/cpp-pistache-everything/model/Tag.cpp
Normal file
135
samples/server/petstore/cpp-pistache-everything/model/Tag.cpp
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Tag.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
Tag::Tag()
|
||||||
|
{
|
||||||
|
m_Id = 0L;
|
||||||
|
m_IdIsSet = false;
|
||||||
|
m_Name = "";
|
||||||
|
m_NameIsSet = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tag::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tag::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tag::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "Tag" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tag::operator==(const Tag& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
((!idIsSet() && !rhs.idIsSet()) || (idIsSet() && rhs.idIsSet() && getId() == rhs.getId())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!nameIsSet() && !rhs.nameIsSet()) || (nameIsSet() && rhs.nameIsSet() && getName() == rhs.getName()))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tag::operator!=(const Tag& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const Tag& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
if(o.idIsSet())
|
||||||
|
j["id"] = o.m_Id;
|
||||||
|
if(o.nameIsSet())
|
||||||
|
j["name"] = o.m_Name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, Tag& o)
|
||||||
|
{
|
||||||
|
if(j.find("id") != j.end())
|
||||||
|
{
|
||||||
|
j.at("id").get_to(o.m_Id);
|
||||||
|
o.m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("name") != j.end())
|
||||||
|
{
|
||||||
|
j.at("name").get_to(o.m_Name);
|
||||||
|
o.m_NameIsSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Tag::getId() const
|
||||||
|
{
|
||||||
|
return m_Id;
|
||||||
|
}
|
||||||
|
void Tag::setId(int64_t const value)
|
||||||
|
{
|
||||||
|
m_Id = value;
|
||||||
|
m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
bool Tag::idIsSet() const
|
||||||
|
{
|
||||||
|
return m_IdIsSet;
|
||||||
|
}
|
||||||
|
void Tag::unsetId()
|
||||||
|
{
|
||||||
|
m_IdIsSet = false;
|
||||||
|
}
|
||||||
|
std::string Tag::getName() const
|
||||||
|
{
|
||||||
|
return m_Name;
|
||||||
|
}
|
||||||
|
void Tag::setName(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Name = value;
|
||||||
|
m_NameIsSet = true;
|
||||||
|
}
|
||||||
|
bool Tag::nameIsSet() const
|
||||||
|
{
|
||||||
|
return m_NameIsSet;
|
||||||
|
}
|
||||||
|
void Tag::unsetName()
|
||||||
|
{
|
||||||
|
m_NameIsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
88
samples/server/petstore/cpp-pistache-everything/model/Tag.h
Normal file
88
samples/server/petstore/cpp-pistache-everything/model/Tag.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Tag.h
|
||||||
|
*
|
||||||
|
* A tag for a pet
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Tag_H_
|
||||||
|
#define Tag_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A tag for a pet
|
||||||
|
/// </summary>
|
||||||
|
class Tag
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tag();
|
||||||
|
virtual ~Tag() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const Tag& rhs) const;
|
||||||
|
bool operator!=(const Tag& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// Tag members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int64_t getId() const;
|
||||||
|
void setId(int64_t const value);
|
||||||
|
bool idIsSet() const;
|
||||||
|
void unsetId();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getName() const;
|
||||||
|
void setName(std::string const& value);
|
||||||
|
bool nameIsSet() const;
|
||||||
|
void unsetName();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Tag& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Tag& o);
|
||||||
|
protected:
|
||||||
|
int64_t m_Id;
|
||||||
|
bool m_IdIsSet;
|
||||||
|
std::string m_Name;
|
||||||
|
bool m_NameIsSet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* Tag_H_ */
|
309
samples/server/petstore/cpp-pistache-everything/model/User.cpp
Normal file
309
samples/server/petstore/cpp-pistache-everything/model/User.cpp
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "User.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
User::User()
|
||||||
|
{
|
||||||
|
m_Id = 0L;
|
||||||
|
m_IdIsSet = false;
|
||||||
|
m_Username = "";
|
||||||
|
m_UsernameIsSet = false;
|
||||||
|
m_FirstName = "";
|
||||||
|
m_FirstNameIsSet = false;
|
||||||
|
m_LastName = "";
|
||||||
|
m_LastNameIsSet = false;
|
||||||
|
m_Email = "";
|
||||||
|
m_EmailIsSet = false;
|
||||||
|
m_Password = "";
|
||||||
|
m_PasswordIsSet = false;
|
||||||
|
m_Phone = "";
|
||||||
|
m_PhoneIsSet = false;
|
||||||
|
m_UserStatus = 0;
|
||||||
|
m_UserStatusIsSet = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::validate() const
|
||||||
|
{
|
||||||
|
std::stringstream msg;
|
||||||
|
if (!validate(msg))
|
||||||
|
{
|
||||||
|
throw org::openapitools::server::helpers::ValidationException(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool User::validate(std::stringstream& msg) const
|
||||||
|
{
|
||||||
|
return validate(msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool User::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string _pathPrefix = pathPrefix.empty() ? "User" : pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool User::operator==(const User& rhs) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
((!idIsSet() && !rhs.idIsSet()) || (idIsSet() && rhs.idIsSet() && getId() == rhs.getId())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!usernameIsSet() && !rhs.usernameIsSet()) || (usernameIsSet() && rhs.usernameIsSet() && getUsername() == rhs.getUsername())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!firstNameIsSet() && !rhs.firstNameIsSet()) || (firstNameIsSet() && rhs.firstNameIsSet() && getFirstName() == rhs.getFirstName())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!lastNameIsSet() && !rhs.lastNameIsSet()) || (lastNameIsSet() && rhs.lastNameIsSet() && getLastName() == rhs.getLastName())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!emailIsSet() && !rhs.emailIsSet()) || (emailIsSet() && rhs.emailIsSet() && getEmail() == rhs.getEmail())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!passwordIsSet() && !rhs.passwordIsSet()) || (passwordIsSet() && rhs.passwordIsSet() && getPassword() == rhs.getPassword())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!phoneIsSet() && !rhs.phoneIsSet()) || (phoneIsSet() && rhs.phoneIsSet() && getPhone() == rhs.getPhone())) &&
|
||||||
|
|
||||||
|
|
||||||
|
((!userStatusIsSet() && !rhs.userStatusIsSet()) || (userStatusIsSet() && rhs.userStatusIsSet() && getUserStatus() == rhs.getUserStatus()))
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool User::operator!=(const User& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const User& o)
|
||||||
|
{
|
||||||
|
j = nlohmann::json::object();
|
||||||
|
if(o.idIsSet())
|
||||||
|
j["id"] = o.m_Id;
|
||||||
|
if(o.usernameIsSet())
|
||||||
|
j["username"] = o.m_Username;
|
||||||
|
if(o.firstNameIsSet())
|
||||||
|
j["firstName"] = o.m_FirstName;
|
||||||
|
if(o.lastNameIsSet())
|
||||||
|
j["lastName"] = o.m_LastName;
|
||||||
|
if(o.emailIsSet())
|
||||||
|
j["email"] = o.m_Email;
|
||||||
|
if(o.passwordIsSet())
|
||||||
|
j["password"] = o.m_Password;
|
||||||
|
if(o.phoneIsSet())
|
||||||
|
j["phone"] = o.m_Phone;
|
||||||
|
if(o.userStatusIsSet())
|
||||||
|
j["userStatus"] = o.m_UserStatus;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, User& o)
|
||||||
|
{
|
||||||
|
if(j.find("id") != j.end())
|
||||||
|
{
|
||||||
|
j.at("id").get_to(o.m_Id);
|
||||||
|
o.m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("username") != j.end())
|
||||||
|
{
|
||||||
|
j.at("username").get_to(o.m_Username);
|
||||||
|
o.m_UsernameIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("firstName") != j.end())
|
||||||
|
{
|
||||||
|
j.at("firstName").get_to(o.m_FirstName);
|
||||||
|
o.m_FirstNameIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("lastName") != j.end())
|
||||||
|
{
|
||||||
|
j.at("lastName").get_to(o.m_LastName);
|
||||||
|
o.m_LastNameIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("email") != j.end())
|
||||||
|
{
|
||||||
|
j.at("email").get_to(o.m_Email);
|
||||||
|
o.m_EmailIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("password") != j.end())
|
||||||
|
{
|
||||||
|
j.at("password").get_to(o.m_Password);
|
||||||
|
o.m_PasswordIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("phone") != j.end())
|
||||||
|
{
|
||||||
|
j.at("phone").get_to(o.m_Phone);
|
||||||
|
o.m_PhoneIsSet = true;
|
||||||
|
}
|
||||||
|
if(j.find("userStatus") != j.end())
|
||||||
|
{
|
||||||
|
j.at("userStatus").get_to(o.m_UserStatus);
|
||||||
|
o.m_UserStatusIsSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t User::getId() const
|
||||||
|
{
|
||||||
|
return m_Id;
|
||||||
|
}
|
||||||
|
void User::setId(int64_t const value)
|
||||||
|
{
|
||||||
|
m_Id = value;
|
||||||
|
m_IdIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::idIsSet() const
|
||||||
|
{
|
||||||
|
return m_IdIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetId()
|
||||||
|
{
|
||||||
|
m_IdIsSet = false;
|
||||||
|
}
|
||||||
|
std::string User::getUsername() const
|
||||||
|
{
|
||||||
|
return m_Username;
|
||||||
|
}
|
||||||
|
void User::setUsername(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Username = value;
|
||||||
|
m_UsernameIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::usernameIsSet() const
|
||||||
|
{
|
||||||
|
return m_UsernameIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetUsername()
|
||||||
|
{
|
||||||
|
m_UsernameIsSet = false;
|
||||||
|
}
|
||||||
|
std::string User::getFirstName() const
|
||||||
|
{
|
||||||
|
return m_FirstName;
|
||||||
|
}
|
||||||
|
void User::setFirstName(std::string const& value)
|
||||||
|
{
|
||||||
|
m_FirstName = value;
|
||||||
|
m_FirstNameIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::firstNameIsSet() const
|
||||||
|
{
|
||||||
|
return m_FirstNameIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetFirstName()
|
||||||
|
{
|
||||||
|
m_FirstNameIsSet = false;
|
||||||
|
}
|
||||||
|
std::string User::getLastName() const
|
||||||
|
{
|
||||||
|
return m_LastName;
|
||||||
|
}
|
||||||
|
void User::setLastName(std::string const& value)
|
||||||
|
{
|
||||||
|
m_LastName = value;
|
||||||
|
m_LastNameIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::lastNameIsSet() const
|
||||||
|
{
|
||||||
|
return m_LastNameIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetLastName()
|
||||||
|
{
|
||||||
|
m_LastNameIsSet = false;
|
||||||
|
}
|
||||||
|
std::string User::getEmail() const
|
||||||
|
{
|
||||||
|
return m_Email;
|
||||||
|
}
|
||||||
|
void User::setEmail(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Email = value;
|
||||||
|
m_EmailIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::emailIsSet() const
|
||||||
|
{
|
||||||
|
return m_EmailIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetEmail()
|
||||||
|
{
|
||||||
|
m_EmailIsSet = false;
|
||||||
|
}
|
||||||
|
std::string User::getPassword() const
|
||||||
|
{
|
||||||
|
return m_Password;
|
||||||
|
}
|
||||||
|
void User::setPassword(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Password = value;
|
||||||
|
m_PasswordIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::passwordIsSet() const
|
||||||
|
{
|
||||||
|
return m_PasswordIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetPassword()
|
||||||
|
{
|
||||||
|
m_PasswordIsSet = false;
|
||||||
|
}
|
||||||
|
std::string User::getPhone() const
|
||||||
|
{
|
||||||
|
return m_Phone;
|
||||||
|
}
|
||||||
|
void User::setPhone(std::string const& value)
|
||||||
|
{
|
||||||
|
m_Phone = value;
|
||||||
|
m_PhoneIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::phoneIsSet() const
|
||||||
|
{
|
||||||
|
return m_PhoneIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetPhone()
|
||||||
|
{
|
||||||
|
m_PhoneIsSet = false;
|
||||||
|
}
|
||||||
|
int32_t User::getUserStatus() const
|
||||||
|
{
|
||||||
|
return m_UserStatus;
|
||||||
|
}
|
||||||
|
void User::setUserStatus(int32_t const value)
|
||||||
|
{
|
||||||
|
m_UserStatus = value;
|
||||||
|
m_UserStatusIsSet = true;
|
||||||
|
}
|
||||||
|
bool User::userStatusIsSet() const
|
||||||
|
{
|
||||||
|
return m_UserStatusIsSet;
|
||||||
|
}
|
||||||
|
void User::unsetUserStatus()
|
||||||
|
{
|
||||||
|
m_UserStatusIsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
142
samples/server/petstore/cpp-pistache-everything/model/User.h
Normal file
142
samples/server/petstore/cpp-pistache-everything/model/User.h
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* User.h
|
||||||
|
*
|
||||||
|
* A User who is purchasing from the pet store
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef User_H_
|
||||||
|
#define User_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace org::openapitools::server::model
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A User who is purchasing from the pet store
|
||||||
|
/// </summary>
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
User();
|
||||||
|
virtual ~User() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Throws a ValidationException on failure.
|
||||||
|
/// </summary>
|
||||||
|
void validate() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate the current data in the model. Returns false on error and writes an error
|
||||||
|
/// message into the given stringstream.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper overload for validate. Used when one model stores another model and calls it's validate.
|
||||||
|
/// Not meant to be called outside that case.
|
||||||
|
/// </summary>
|
||||||
|
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
|
||||||
|
|
||||||
|
bool operator==(const User& rhs) const;
|
||||||
|
bool operator!=(const User& rhs) const;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
/// User members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
int64_t getId() const;
|
||||||
|
void setId(int64_t const value);
|
||||||
|
bool idIsSet() const;
|
||||||
|
void unsetId();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getUsername() const;
|
||||||
|
void setUsername(std::string const& value);
|
||||||
|
bool usernameIsSet() const;
|
||||||
|
void unsetUsername();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getFirstName() const;
|
||||||
|
void setFirstName(std::string const& value);
|
||||||
|
bool firstNameIsSet() const;
|
||||||
|
void unsetFirstName();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getLastName() const;
|
||||||
|
void setLastName(std::string const& value);
|
||||||
|
bool lastNameIsSet() const;
|
||||||
|
void unsetLastName();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getEmail() const;
|
||||||
|
void setEmail(std::string const& value);
|
||||||
|
bool emailIsSet() const;
|
||||||
|
void unsetEmail();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getPassword() const;
|
||||||
|
void setPassword(std::string const& value);
|
||||||
|
bool passwordIsSet() const;
|
||||||
|
void unsetPassword();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::string getPhone() const;
|
||||||
|
void setPhone(std::string const& value);
|
||||||
|
bool phoneIsSet() const;
|
||||||
|
void unsetPhone();
|
||||||
|
/// <summary>
|
||||||
|
/// User Status
|
||||||
|
/// </summary>
|
||||||
|
int32_t getUserStatus() const;
|
||||||
|
void setUserStatus(int32_t const value);
|
||||||
|
bool userStatusIsSet() const;
|
||||||
|
void unsetUserStatus();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const User& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, User& o);
|
||||||
|
protected:
|
||||||
|
int64_t m_Id;
|
||||||
|
bool m_IdIsSet;
|
||||||
|
std::string m_Username;
|
||||||
|
bool m_UsernameIsSet;
|
||||||
|
std::string m_FirstName;
|
||||||
|
bool m_FirstNameIsSet;
|
||||||
|
std::string m_LastName;
|
||||||
|
bool m_LastNameIsSet;
|
||||||
|
std::string m_Email;
|
||||||
|
bool m_EmailIsSet;
|
||||||
|
std::string m_Password;
|
||||||
|
bool m_PasswordIsSet;
|
||||||
|
std::string m_Phone;
|
||||||
|
bool m_PhoneIsSet;
|
||||||
|
int32_t m_UserStatus;
|
||||||
|
bool m_UserStatusIsSet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace org::openapitools::server::model
|
||||||
|
|
||||||
|
#endif /* User_H_ */
|
@ -1,13 +1,14 @@
|
|||||||
#/bin/bash
|
#!/bin/bash
|
||||||
# ref: http://pistache.io/quickstart#installing-pistache
|
# ref: http://pistache.io/quickstart#installing-pistache
|
||||||
#
|
#
|
||||||
echo "Installing Pistache ..."
|
echo "Installing Pistache ..."
|
||||||
|
|
||||||
git clone https://github.com/oktal/pistache.git || true
|
git clone https://github.com/oktal/pistache.git || true
|
||||||
cd pistache
|
cd pistache || (echo "Cannot find git clone pistache directory"; exit 1)
|
||||||
|
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build || (echo "Cannot find build directory"; exit 1)
|
||||||
|
|
||||||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
|
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
|
||||||
make
|
meson
|
||||||
sudo make install
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user