forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] [C++][Pistache] cpp-pistache-server generating API include unde… (
OpenAPITools#18553) * [BUG] [C++][Pistache] cpp-pistache-server generating API include undefined "Object.h" (OpenAPITools#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 OpenAPITools#2769, OpenAPITools#10266, OpenAPITools#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
- Loading branch information
Showing
43 changed files
with
5,331 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...-generator/src/test/java/org/openapitools/codegen/cpppistache/AbstractGeneratorsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...pi-generator/src/test/java/org/openapitools/codegen/cpppistache/ObjectAnyTypeSetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
.../openapi-generator/src/test/java/org/openapitools/codegen/cpppistache/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
These test aren't useful yet | ||
they only run the generator for a single case |
Oops, something went wrong.