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
  • !14539

[python-nextgen] fix issue on API example doc autogeneration

  • Review changes

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

Created by: itaru2622

This PR fixes the issue #14538 (closed) as described in the above issue, this PR makes auto generated API example doc runnable in success even when OpenAPI spec has no auth methods.

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 (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@spacether @wing328

Compare
  • master (base)

and
  • latest version
    6f5aa0bf
    3 commits, 2 years ago

12 files
+ 94
- 58

    Preferences

    File browser
    Compare changes
modules/openap‎i-generator/src‎
main/resources‎/python-nextgen‎
api_doc_exam‎ple.mustache‎ +0 -5
test/java/org/…‎/codegen/python‎
PythonNextgenClie‎ntCodegenTest.java‎ +42 -1
samples/openapi3‎/client/petstore‎
python-nextge‎n-aiohttp/docs‎
AnotherF‎akeApi.md‎ +1 -1
Defaul‎tApi.md‎ +1 -1
FakeA‎pi.md‎ +13 -13
Store‎Api.md‎ +3 -3
UserA‎pi.md‎ +8 -8
python-ne‎xtgen/docs‎
AnotherF‎akeApi.md‎ +1 -1
Defaul‎tApi.md‎ +1 -1
FakeA‎pi.md‎ +13 -13
Store‎Api.md‎ +3 -3
UserA‎pi.md‎ +8 -8
modules/openapi-generator/src/main/resources/python-nextgen/api_doc_example.mustache
+ 0
- 5
  • View file @ 6f5aa0bf

  • Edit in single-file editor

  • Open in Web IDE


@@ -7,12 +7,7 @@ from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
# Enter a context with an instance of the API client
{{#hasAuthMethods}}
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient(configuration) as api_client:
{{/hasAuthMethods}}
{{^hasAuthMethods}}
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient() as api_client:
{{/hasAuthMethods}}
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{#allParams}}
modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonNextgenClientCodegenTest.java
+ 42
- 1
  • View file @ 6f5aa0bf

  • Edit in single-file editor

  • Open in Web IDE


@@ -18,17 +18,28 @@
package org.openapitools.codegen.python;
import com.google.common.collect.Sets;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.PythonNextgenClientCodegen;
import org.openapitools.codegen.languages.features.CXFServerFeatures;
import static org.openapitools.codegen.TestUtils.assertFileContains;
import static org.openapitools.codegen.TestUtils.assertFileExists;
import org.openapitools.codegen.TestUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PythonNextgenClientCodegenTest {
@@ -382,4 +393,34 @@ public class PythonNextgenClientCodegenTest {
Assert.assertEquals(cm.parent, null);
Assert.assertEquals(cm.imports.size(), 0);
}
@Test(description ="check API example has input param(configuration) when it creates api_client")
public void apiExampleDocTest() throws Exception {
final DefaultCodegen codegen = new PythonNextgenClientCodegen();
final String outputPath = generateFiles(codegen, "src/test/resources/3_0/generic.yaml");
final Path p = Paths.get(outputPath + "docs/DefaultApi.md");
assertFileExists(p);
assertFileContains(p, "openapi_client.ApiClient(configuration) as api_client");
}
// Helper function, intended to reduce boilerplate
static private String generateFiles(DefaultCodegen codegen, String filePath) throws IOException {
final File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
final String outputPath = output.getAbsolutePath().replace('\\', '/');
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
final ClientOptInput input = new ClientOptInput();
final OpenAPI openAPI = new OpenAPIParser().readLocation(filePath, null, new ParseOptions()).getOpenAPI();
input.openAPI(openAPI);
input.config(codegen);
final DefaultGenerator generator = new DefaultGenerator();
final List<File> files = generator.opts(input).generate();
Assert.assertTrue(files.size() > 0);
return outputPath + "/";
}
}
samples/openapi3/client/petstore/python-nextgen/docs/AnotherFakeApi.md
+ 1
- 1
  • View file @ 6f5aa0bf

  • Edit in single-file editor

  • Open in Web IDE


@@ -31,7 +31,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(api_client)
client = petstore_api.Client() # Client | client model
samples/openapi3/client/petstore/python-nextgen/docs/DefaultApi.md
+ 1
- 1
  • View file @ 6f5aa0bf

  • Edit in single-file editor

  • Open in Web IDE


@@ -29,7 +29,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.DefaultApi(api_client)
samples/openapi3/client/petstore/python-nextgen/docs/FakeApi.md
+ 13
- 13
  • View file @ 6f5aa0bf

  • Edit in single-file editor

  • Open in Web IDE


@@ -44,7 +44,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
@@ -232,7 +232,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = True # bool | Input boolean as post body (optional)
@@ -295,7 +295,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
outer_composite = petstore_api.OuterComposite() # OuterComposite | Input composite as post body (optional)
@@ -358,7 +358,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = 3.4 # float | Input number as post body (optional)
@@ -421,7 +421,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = 'body_example' # str | Input string as post body (optional)
@@ -484,7 +484,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
outer_object_with_enum_property = petstore_api.OuterObjectWithEnumProperty() # OuterObjectWithEnumProperty | Input enum (int) as post body
@@ -547,7 +547,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = 'body_example' # str | image to upload
@@ -608,7 +608,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
file_schema_test_class = petstore_api.FileSchemaTestClass() # FileSchemaTestClass |
@@ -667,7 +667,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
query = 'query_example' # str |
@@ -730,7 +730,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
client = petstore_api.Client() # Client | client model
@@ -976,7 +976,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
request_body = {'key': 'request_body_example'} # Dict[str, str] | request body
@@ -1038,7 +1038,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
param = 'param_example' # str | field1
@@ -1102,7 +1102,7 @@ configuration = petstore_api.Configuration(
# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
pipe = ['pipe_example'] # List[str] |
0 Assignees
None
Assign to
Reviewer
William Cheng's avatar
William Cheng
Request review from
Labels
2
Issue: Bug python
2
Issue: Bug python
    Assign labels
  • Manage project labels

Milestone
6.3.0
6.3.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
2
2 participants
William Cheng
Administrator
Reference: OpenAPITools/openapi-generator!14539
Source branch: github/fork/itaru2622/issue14538

Menu

Explore Projects Groups Snippets