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.
[elm][haskell-servant] Fix issue 3256 (OpenAPITools#3262)
* [elm] fix empty operation exception (OpenAPITools#3256) * [haskell-servant] fix empty operation type (OpenAPITools#3256) * [elm][haskell-servant] update samples
- Loading branch information
Showing
48 changed files
with
1,799 additions
and
178 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
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
108 changes: 108 additions & 0 deletions
108
...es/openapi-generator/src/test/java/org/openapitools/codegen/elm/ElmClientCodegenTest.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,108 @@ | ||
/* | ||
* Copyright 2019 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 | ||
* | ||
* http://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.elm; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static java.util.Collections.emptyList; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.openapitools.codegen.ClientOptInput; | ||
import org.openapitools.codegen.ClientOpts; | ||
import org.openapitools.codegen.CodegenOperation; | ||
import org.openapitools.codegen.MockDefaultGenerator; | ||
import org.openapitools.codegen.languages.ElmClientCodegen; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import io.swagger.parser.OpenAPIParser; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.parser.core.models.ParseOptions; | ||
|
||
public class ElmClientCodegenTest { | ||
|
||
@Test | ||
public void testPostProcessRootEndpoint() { | ||
// given | ||
final ElmClientCodegen codegen = new ElmClientCodegen(); | ||
|
||
CodegenOperation rootOp = new CodegenOperation() {{ path = "/"; }}; | ||
List<CodegenOperation> ops = newArrayList(rootOp); | ||
|
||
Map<String, Object> operations = new HashMap<>(); | ||
operations.put("operations", ImmutableMap | ||
.<String, Object>builder() | ||
.put("operation", ops) | ||
.build()); | ||
|
||
// when | ||
Map<String, Object> result = codegen.postProcessOperationsWithModels(operations, emptyList()); | ||
|
||
// then | ||
assertEquals(result.size(), 2); | ||
assertTrue(result.containsKey("operations")); | ||
assertTrue(result.containsKey("elmImports")); | ||
|
||
assertEquals(rootOp.path, "\"\""); | ||
} | ||
|
||
@Test | ||
public void testGenerateRootEndpoint() throws IOException { | ||
// given | ||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); | ||
output.deleteOnExit(); | ||
String outputPath = output.getAbsolutePath().replace('\\', '/'); | ||
|
||
final ElmClientCodegen codegen = new ElmClientCodegen(); | ||
codegen.setOutputDir(output.getAbsolutePath()); | ||
|
||
OpenAPI openAPI = new OpenAPIParser() | ||
.readLocation("src/test/resources/3_0/rootOperation.yaml", null, new ParseOptions()) | ||
.getOpenAPI(); | ||
|
||
ClientOpts opts = new ClientOpts(); | ||
|
||
ClientOptInput input = new ClientOptInput(); | ||
input.setOpenAPI(openAPI); | ||
input.setConfig(codegen); | ||
input.setOpts(opts); | ||
|
||
// when | ||
MockDefaultGenerator generator = new MockDefaultGenerator(); | ||
generator.opts(input).generate(); | ||
|
||
// then | ||
assertFileContains(generator, outputPath + "/src/Request/Default.elm", "rootGet", "[\"\"]"); | ||
} | ||
|
||
private static void assertFileContains(MockDefaultGenerator generator, String file, String... expected) { | ||
String content = generator.getFiles().get(file); | ||
assertNotNull(content, "The file \"" + file + "\" was not generated"); | ||
for (String line : expected) { | ||
assertTrue(content.contains(line), "The file \"" + file + "\" does not contain \"" + line + "\""); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...ator/src/test/java/org/openapitools/codegen/haskellservant/HaskellServantCodegenTest.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,75 @@ | ||
/* | ||
* Copyright 2019 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 | ||
* | ||
* http://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.haskellservant; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertNotNull; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Arrays; | ||
|
||
import org.openapitools.codegen.ClientOptInput; | ||
import org.openapitools.codegen.ClientOpts; | ||
import org.openapitools.codegen.MockDefaultGenerator; | ||
import org.openapitools.codegen.languages.HaskellServantCodegen; | ||
import org.testng.annotations.Test; | ||
|
||
import io.swagger.parser.OpenAPIParser; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.parser.core.models.ParseOptions; | ||
|
||
public class HaskellServantCodegenTest { | ||
|
||
@Test | ||
public void testGenerateRootEndpoint() throws IOException { | ||
// given | ||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); | ||
output.deleteOnExit(); | ||
String outputPath = output.getAbsolutePath().replace('\\', '/'); | ||
|
||
final HaskellServantCodegen codegen = new HaskellServantCodegen(); | ||
codegen.setOutputDir(output.getAbsolutePath()); | ||
|
||
OpenAPI openAPI = new OpenAPIParser() | ||
.readLocation("src/test/resources/3_0/rootOperation.yaml", null, new ParseOptions()) | ||
.getOpenAPI(); | ||
|
||
ClientOpts opts = new ClientOpts(); | ||
|
||
ClientOptInput input = new ClientOptInput(); | ||
input.setOpenAPI(openAPI); | ||
input.setConfig(codegen); | ||
input.setOpts(opts); | ||
|
||
// when | ||
MockDefaultGenerator generator = new MockDefaultGenerator(); | ||
generator.opts(input).generate(); | ||
|
||
// then | ||
assertFileNotContains(generator, outputPath + "/lib/RootOperation/API.hs", "\"\" :>"); | ||
} | ||
|
||
private static void assertFileNotContains(MockDefaultGenerator generator, String file, String... expected) { | ||
String content = generator.getFiles().get(file); | ||
assertNotNull(content, "The file \"" + file + "\" was not generated"); | ||
for (String line : expected) { | ||
assertFalse(content.contains(line), "The file \"" + file + "\" contains \"" + line + "\""); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/openapi-generator/src/test/resources/3_0/rootOperation.yaml
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,13 @@ | ||
openapi: 3.0.0 | ||
|
||
info: | ||
title: Root Operation | ||
version: 1.0.0 | ||
|
||
paths: | ||
/: | ||
get: | ||
summary: Simple root endpoint | ||
responses: | ||
204: | ||
description: No response body |
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 |
---|---|---|
@@ -1 +1 @@ | ||
4.0.0-SNAPSHOT | ||
4.0.3-SNAPSHOT |
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
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
Oops, something went wrong.