Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 9e320cc

Browse files
authored
Adds fix for route with just a slash (#161)
* Adds fix for route with just a slash * Sample regen * Removes unused test folder
1 parent 0b2f980 commit 9e320cc

File tree

17 files changed

+480
-11
lines changed

17 files changed

+480
-11
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ public String toModelName(String name, String jsonPath) {
781781
// camelize the model name
782782
// phone_number => PhoneNumber
783783
String camelizedName = camelize(nameWithPrefixSuffix);
784+
if (camelizedName.isEmpty()) {
785+
// happens with a name like "/"
786+
camelizedName = camelize(toEnumVarName(name, null).toLowerCase(Locale.ROOT));
787+
}
784788

785789
String[] pathPieces;
786790
boolean isComponent = false;

modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore_customized.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,15 @@ paths:
16921692
description: see other
16931693
3XX:
16941694
description: 3XX response
1695+
/:
1696+
get:
1697+
operationId: slashRoute
1698+
summary: slash route
1699+
tags:
1700+
- fake
1701+
responses:
1702+
200:
1703+
$ref: '#/components/responses/SuccessDescriptionOnly'
16951704
servers:
16961705
- url: 'http://{server}.swagger.io:{port}/v2'
16971706
description: petstore server

samples/openapi3/client/petstore/python/.openapi-generator/FILES

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ docs/paths/pet_pet_id/delete.md
216216
docs/paths/pet_pet_id/get.md
217217
docs/paths/pet_pet_id/post.md
218218
docs/paths/pet_pet_id_upload_image/post.md
219+
docs/paths/solidus/get.md
219220
docs/paths/store_inventory/get.md
220221
docs/paths/store_order/post.md
221222
docs/paths/store_order_order_id/delete.md
@@ -283,6 +284,7 @@ src/petstore_api/apis/paths/pet_find_by_status.py
283284
src/petstore_api/apis/paths/pet_find_by_tags.py
284285
src/petstore_api/apis/paths/pet_pet_id.py
285286
src/petstore_api/apis/paths/pet_pet_id_upload_image.py
287+
src/petstore_api/apis/paths/solidus.py
286288
src/petstore_api/apis/paths/store_inventory.py
287289
src/petstore_api/apis/paths/store_order.py
288290
src/petstore_api/apis/paths/store_order_order_id.py
@@ -1162,6 +1164,11 @@ src/petstore_api/paths/pet_pet_id_upload_image/post/responses/__init__.py
11621164
src/petstore_api/paths/pet_pet_id_upload_image/post/responses/response_200/__init__.py
11631165
src/petstore_api/paths/pet_pet_id_upload_image/post/security/__init__.py
11641166
src/petstore_api/paths/pet_pet_id_upload_image/post/security/security_requirement_object_0.py
1167+
src/petstore_api/paths/solidus/__init__.py
1168+
src/petstore_api/paths/solidus/get/__init__.py
1169+
src/petstore_api/paths/solidus/get/operation.py
1170+
src/petstore_api/paths/solidus/get/responses/__init__.py
1171+
src/petstore_api/paths/solidus/get/responses/response_200/__init__.py
11651172
src/petstore_api/paths/store_inventory/__init__.py
11661173
src/petstore_api/paths/store_inventory/get/__init__.py
11671174
src/petstore_api/paths/store_inventory/get/operation.py
@@ -1367,6 +1374,7 @@ test/test_paths/__init__.py
13671374
test/test_paths/__init__.py
13681375
test/test_paths/__init__.py
13691376
test/test_paths/__init__.py
1377+
test/test_paths/__init__.py
13701378
test/test_paths/test_another_fake_dummy/__init__.py
13711379
test/test_paths/test_another_fake_dummy/test_patch.py
13721380
test/test_paths/test_fake/__init__.py
@@ -1459,6 +1467,8 @@ test/test_paths/test_pet_pet_id/test_get.py
14591467
test/test_paths/test_pet_pet_id/test_post.py
14601468
test/test_paths/test_pet_pet_id_upload_image/__init__.py
14611469
test/test_paths/test_pet_pet_id_upload_image/test_post.py
1470+
test/test_paths/test_solidus/__init__.py
1471+
test/test_paths/test_solidus/test_get.py
14621472
test/test_paths/test_store_inventory/__init__.py
14631473
test/test_paths/test_store_inventory/test_get.py
14641474
test/test_paths/test_store_order/__init__.py

samples/openapi3/client/petstore/python/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,27 +174,22 @@ Please follow the [installation procedure](#installation) and then run the follo
174174
```python
175175
import petstore_api
176176
from petstore_api.configurations import api_configuration
177-
from petstore_api.apis.tags import another_fake_api
177+
from petstore_api.apis.tags import fake_api
178178
from pprint import pprint
179179
used_configuration = api_configuration.ApiConfiguration(
180180
)
181181
# Enter a context with an instance of the API client
182182
with petstore_api.ApiClient(used_configuration) as api_client:
183183
# Create an instance of the API class
184-
api_instance = another_fake_api.AnotherFakeApi(api_client)
184+
api_instance = fake_api.FakeApi(api_client)
185185

186-
# example passing only required values which don't have defaults set
187-
body = client.Client(
188-
client="client_example",
189-
)
186+
# example, this endpoint has no required or optional parameters
190187
try:
191-
# To test special tags
192-
api_response = api_instance.call_123_test__special_tags(
193-
body=body,
194-
)
188+
# slash route
189+
api_response = api_instance.slash_route()
195190
pprint(api_response)
196191
except petstore_api.ApiException as e:
197-
print("Exception when calling AnotherFakeApi->call_123_test__special_tags: %s\n" % e)
192+
print("Exception when calling FakeApi->slash_route: %s\n" % e)
198193
```
199194

200195
## Servers
@@ -213,6 +208,7 @@ All URIs are relative to the selected server
213208

214209
HTTP request | Method | Description
215210
------------ | ------ | -------------
211+
/ **get** | [FakeApi](docs/apis/tags/fake_api.md).[slash_route](docs/paths/solidus/get.md) | slash route
216212
/another-fake/dummy **patch** | [AnotherFakeApi](docs/apis/tags/another_fake_api.md).[call_123_test__special_tags](docs/paths/another_fake_dummy/patch.md) | To test special tags
217213
/fake **delete** | [FakeApi](docs/apis/tags/fake_api.md).[group_parameters](docs/paths/fake/delete.md) | Fake endpoint to test group parameters (optional)
218214
/fake **get** | [FakeApi](docs/apis/tags/fake_api.md).[enum_parameters](docs/paths/fake/get.md) | To test enum parameters

samples/openapi3/client/petstore/python/docs/apis/tags/fake_api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Method | Description
4040
[**redirection**](../../paths/fake_redirection/get.md) | operation with redirection responses
4141
[**ref_object_in_query**](../../paths/fake_ref_obj_in_query/get.md) | user list
4242
[**response_without_schema**](../../paths/fake_response_without_schema/get.md) | receives a response without schema
43+
[**slash_route**](../../paths/solidus/get.md) | slash route
4344
[**string**](../../paths/fake_refs_string/post.md) |
4445
[**string_enum**](../../paths/fake_refs_enum/post.md) |
4546
[**upload_download_file**](../../paths/fake_upload_download_file/post.md) | uploads a file and downloads a file using application/octet-stream
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
petstore_api.paths..operation
2+
# Operation Method Name
3+
4+
| Method Name | Api Class | Notes |
5+
| ----------- | --------- | ----- |
6+
| slash_route | [FakeApi](../../apis/tags/fake_api.md) | This api is only for tag=fake |
7+
| get | ApiForGet | This api is only for this endpoint |
8+
| get | | This api is only for path=/ |
9+
10+
## Table of Contents
11+
- [General Info](#general-info)
12+
- [Arguments](#arguments)
13+
- [Return Types](#return-types)
14+
- [Servers](#servers)
15+
- [Code Sample](#code-sample)
16+
17+
## General Info
18+
| Field | Value |
19+
| ----- | ----- |
20+
| Summary | slash route |
21+
| Path | "/" |
22+
| HTTP Method | get |
23+
24+
## Arguments
25+
26+
Name | Type | Description | Notes
27+
------------- | ------------- | ------------- | -------------
28+
server_index | typing.Optional[int] | default is None | Allows one to select a different server
29+
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
30+
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
31+
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned
32+
33+
## Return Types
34+
35+
HTTP Status Code | Class | Description
36+
------------- | ------------- | -------------
37+
n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned
38+
200 | [SuccessDescriptionOnly.response_cls](../../components/responses/response_success_description_only.md#response_success_description_onlyresponse_cls) | Success
39+
40+
## Servers
41+
42+
Set the available servers by defining your used servers in ApiConfiguration.server_info
43+
Then select your server by setting a server index in ApiConfiguration.server_index_info or by
44+
passing server_index in to the endpoint method.
45+
- these servers are the general api servers
46+
- defaults to server_index=0, server.url = http://petstore.swagger.io:80/v2
47+
48+
server_index | Class | Description
49+
------------ | ----- | ------------
50+
0 | [Server0](../../../servers/server_0.md) | petstore server
51+
1 | [Server1](../../../servers/server_1.md) | The local server
52+
2 | [Server2](../../../servers/server_2.md) | staging server with no variables
53+
54+
## Code Sample
55+
56+
```python
57+
import petstore_api
58+
from petstore_api.configurations import api_configuration
59+
from petstore_api.apis.tags import fake_api
60+
from pprint import pprint
61+
used_configuration = api_configuration.ApiConfiguration(
62+
)
63+
# Enter a context with an instance of the API client
64+
with petstore_api.ApiClient(used_configuration) as api_client:
65+
# Create an instance of the API class
66+
api_instance = fake_api.FakeApi(api_client)
67+
68+
# example, this endpoint has no required or optional parameters
69+
try:
70+
# slash route
71+
api_response = api_instance.slash_route()
72+
pprint(api_response)
73+
except petstore_api.ApiException as e:
74+
print("Exception when calling FakeApi->slash_route: %s\n" % e)
75+
```
76+
77+
[[Back to top]](#top)
78+
[[Back to FakeApi API]](../../apis/tags/fake_api.md)
79+
[[Back to Endpoints]](../../../README.md#Endpoints) [[Back to README]](../../../README.md)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
petstore_api.paths.solidus.operation
2+
# Operation Method Name
3+
4+
| Method Name | Api Class | Notes |
5+
| ----------- | --------- | ----- |
6+
| slash_route | [FakeApi](../../apis/tags/fake_api.md) | This api is only for tag=fake |
7+
| get | ApiForGet | This api is only for this endpoint |
8+
| get | Solidus | This api is only for path=/ |
9+
10+
## Table of Contents
11+
- [General Info](#general-info)
12+
- [Arguments](#arguments)
13+
- [Return Types](#return-types)
14+
- [Servers](#servers)
15+
- [Code Sample](#code-sample)
16+
17+
## General Info
18+
| Field | Value |
19+
| ----- | ----- |
20+
| Summary | slash route |
21+
| Path | "/" |
22+
| HTTP Method | get |
23+
24+
## Arguments
25+
26+
Name | Type | Description | Notes
27+
------------- | ------------- | ------------- | -------------
28+
server_index | typing.Optional[int] | default is None | Allows one to select a different server
29+
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
30+
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
31+
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned
32+
33+
## Return Types
34+
35+
HTTP Status Code | Class | Description
36+
------------- | ------------- | -------------
37+
n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned
38+
200 | [SuccessDescriptionOnly.response_cls](../../components/responses/response_success_description_only.md#response_success_description_onlyresponse_cls) | Success
39+
40+
## Servers
41+
42+
Set the available servers by defining your used servers in ApiConfiguration.server_info
43+
Then select your server by setting a server index in ApiConfiguration.server_index_info or by
44+
passing server_index in to the endpoint method.
45+
- these servers are the general api servers
46+
- defaults to server_index=0, server.url = http://petstore.swagger.io:80/v2
47+
48+
server_index | Class | Description
49+
------------ | ----- | ------------
50+
0 | [Server0](../../../servers/server_0.md) | petstore server
51+
1 | [Server1](../../../servers/server_1.md) | The local server
52+
2 | [Server2](../../../servers/server_2.md) | staging server with no variables
53+
54+
## Code Sample
55+
56+
```python
57+
import petstore_api
58+
from petstore_api.configurations import api_configuration
59+
from petstore_api.apis.tags import fake_api
60+
from pprint import pprint
61+
used_configuration = api_configuration.ApiConfiguration(
62+
)
63+
# Enter a context with an instance of the API client
64+
with petstore_api.ApiClient(used_configuration) as api_client:
65+
# Create an instance of the API class
66+
api_instance = fake_api.FakeApi(api_client)
67+
68+
# example, this endpoint has no required or optional parameters
69+
try:
70+
# slash route
71+
api_response = api_instance.slash_route()
72+
pprint(api_response)
73+
except petstore_api.ApiException as e:
74+
print("Exception when calling FakeApi->slash_route: %s\n" % e)
75+
```
76+
77+
[[Back to top]](#top)
78+
[[Back to FakeApi API]](../../apis/tags/fake_api.md)
79+
[[Back to Endpoints]](../../../README.md#Endpoints) [[Back to README]](../../../README.md)

samples/openapi3/client/petstore/python/src/petstore_api/apis/path_to_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typing
22
import typing_extensions
33

4+
from petstore_api.apis.paths.solidus import Solidus
45
from petstore_api.apis.paths.another_fake_dummy import AnotherFakeDummy
56
from petstore_api.apis.paths.fake import Fake
67
from petstore_api.apis.paths.fake_additional_properties_with_array_of_enums import FakeAdditionalPropertiesWithArrayOfEnums
@@ -57,6 +58,7 @@
5758
PathToApi = typing_extensions.TypedDict(
5859
'PathToApi',
5960
{
61+
"/": typing.Type[Solidus],
6062
"/another-fake/dummy": typing.Type[AnotherFakeDummy],
6163
"/fake": typing.Type[Fake],
6264
"/fake/additional-properties-with-array-of-enums": typing.Type[FakeAdditionalPropertiesWithArrayOfEnums],
@@ -114,6 +116,7 @@
114116

115117
path_to_api = PathToApi(
116118
{
119+
"/": Solidus,
117120
"/another-fake/dummy": AnotherFakeDummy,
118121
"/fake": Fake,
119122
"/fake/additional-properties-with-array-of-enums": FakeAdditionalPropertiesWithArrayOfEnums,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding: utf-8
2+
3+
"""
4+
5+
6+
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
7+
"""
8+
9+
from petstore_api.paths.solidus.get.operation import ApiForGet
10+
11+
12+
class Solidus(
13+
ApiForGet,
14+
):
15+
pass

samples/openapi3/client/petstore/python/src/petstore_api/apis/tags/fake_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from petstore_api.paths.fake_json_patch.patch.operation import JsonPatch
1818
from petstore_api.paths.fake_upload_files.post.operation import UploadFiles
1919
from petstore_api.paths.fake_json_form_data.get.operation import JsonFormData
20+
from petstore_api.paths.solidus.get.operation import SlashRoute
2021
from petstore_api.paths.fake_refs_string.post.operation import String
2122
from petstore_api.paths.fake_response_without_schema.get.operation import ResponseWithoutSchema
2223
from petstore_api.paths.fake_refs_object_model_with_ref_props.post.operation import ObjectModelWithRefProps
@@ -57,6 +58,7 @@ class FakeApi(
5758
JsonPatch,
5859
UploadFiles,
5960
JsonFormData,
61+
SlashRoute,
6062
String,
6163
ResponseWithoutSchema,
6264
ObjectModelWithRefProps,

0 commit comments

Comments
 (0)