Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !9572
An error occurred while fetching the assigned milestone of the selected merge_request.

Fix python generation when custom files and templates are specified

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/shylasrinivas/fix_issue9570 into master 4 years ago
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 3

Created by: shylasrinivas

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Compare
  • master (base)

and
  • latest version
    2b1bcb03
    2 commits, 2 years ago

3 files
+ 60
- 3

    Preferences

    File browser
    Compare changes
docs/ge‎nerators‎
tiny-‎cpp.md‎ +1 -1
modules/openap‎i-generator/src‎
main/java/org/ope‎napitools/codegen‎
DefaultGen‎erator.java‎ +1 -1
test/java/org/ope‎napitools/codegen‎
DefaultGener‎atorTest.java‎ +58 -1
docs/generators/tiny-cpp.md
+ 1
- 1
  • View file @ 2b1bcb03

  • Edit in single-file editor

  • Open in Web IDE


@@ -165,7 +165,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Maps|✗|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✓|OAS2,OAS3
|Enum|✗|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java
+ 1
- 1
  • View file @ 2b1bcb03

  • Edit in single-file editor

  • Open in Web IDE


@@ -938,7 +938,7 @@ public class DefaultGenerator implements Generator {
// TODO: initial behavior is "merge" user defined with built-in templates. consider offering user a "replace" option.
if (userDefinedTemplates != null && !userDefinedTemplates.isEmpty()) {
Map<String, SupportingFile> supportingFilesMap = config.supportingFiles().stream()
.collect(Collectors.toMap(TemplateDefinition::getTemplateFile, Function.identity()));
.collect(Collectors.toMap(TemplateDefinition::getTemplateFile, Function.identity(), (oldValue, newValue) -> oldValue));
// TemplateFileType.SupportingFiles
userDefinedTemplates.stream()
modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java
+ 58
- 1
  • View file @ 2b1bcb03

  • Edit in single-file editor

  • Open in Web IDE


@@ -662,5 +662,62 @@ public class DefaultGeneratorTest {
Assert.assertEquals(servers.get(1).url, "http://trailingshlash.io:80/v1");
Assert.assertEquals(servers.get(2).url, "http://notrailingslash.io:80/v2");
}
}
@Test
public void testProcessUserDefinedTemplatesWithConfig() throws IOException {
Path target = Files.createTempDirectory("test");
Path templates = Files.createTempDirectory("templates");
File output = target.toFile();
try {
// Create custom template
File customTemplate = new File(templates.toFile(), "README.mustache");
new File(customTemplate.getParent()).mkdirs();
Files.write(customTemplate.toPath(),
"# {{someKey}}".getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE);
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("python")
.setInputSpec("src/test/resources/3_0/petstore.yaml")
.setPackageName("io.something")
.setTemplateDir(templates.toAbsolutePath().toString())
.addAdditionalProperty("files", "src/test/resources/sampleConfig.json:\n\t folder: supportingjson "+
"\n\t destinationFilename: supportingconfig.json \n\t templateType: SupportingFiles")
.setSkipOverwrite(false)
.setOutputDir(target.toAbsolutePath().toString());
final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator(false);
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.API_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.API_TESTS, "false");
List<File> files = generator.opts(clientOptInput).generate();
// remove commented code based on review - files does not seem to be supported in CodegenConfigurator
// supporting files sanity check
// TestUtils.ensureContainsFile(files, output, "sampleConfig.json");
// Assert.assertTrue(new File(output, "sampleConfig.json").exists());
// Generator should report api_client.py as a generated file
TestUtils.ensureContainsFile(files, output, "io/something/api_client.py");
// Generated file should exist on the filesystem after generation
File apiClient = new File(output, "io/something/api_client.py");
Assert.assertTrue(apiClient.exists());
// Generated file should contain our custom packageName
TestUtils.assertFileContains(apiClient.toPath(),
"from io.something import rest"
);
} finally {
output.delete();
templates.toFile().delete();
}
}
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference:
Source branch: github/fork/shylasrinivas/fix_issue9570

Menu

Explore Projects Groups Snippets