[JAVA] Prioritize mapped discriminators over generated (relates to issue #12777) (#15284)

* prioritize mapped discriminators over generated

* update samples with new ordering

* explain reason behind discriminator prioritization

* add new samples

* prioritize explicit mapping over any generated mappings

* update examples to reflect new logic

* update tests to reflect explicit mappings
This commit is contained in:
Robbert van Waveren 2023-09-27 11:50:39 +02:00 committed by GitHub
parent 4f8d61c05c
commit beb67aa74d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 693 additions and 18 deletions

View File

@ -123,9 +123,16 @@ public class CodegenDiscriminator {
private CodegenModel model; private CodegenModel model;
public MappedModel(String mappingName, String modelName) { private final boolean explicitMapping;
public MappedModel(String mappingName, String modelName, boolean explicitMapping) {
this.mappingName = mappingName; this.mappingName = mappingName;
this.modelName = modelName; this.modelName = modelName;
this.explicitMapping = explicitMapping;
}
public MappedModel(String mappingName, String modelName) {
this(mappingName, modelName, false);
} }
@Override @Override
@ -137,8 +144,15 @@ public class CodegenDiscriminator {
} else if (other.getMappingName() == null) { } else if (other.getMappingName() == null) {
return -1; return -1;
} }
// prioritize mappings based on mappings in the spec before any auto-generated
// so that during serialization the proper values are used in the json
if (explicitMapping != other.explicitMapping) {
return explicitMapping ? -1 : 1;
} else {
return getMappingName().compareTo(other.getMappingName()); return getMappingName().compareTo(other.getMappingName());
} }
}
public String getMappingName() { public String getMappingName() {
return mappingName; return mappingName;

View File

@ -3492,7 +3492,7 @@ public class DefaultCodegen implements CodegenConfig {
Map<String, Object> vendorExtensions = cs.getExtensions(); Map<String, Object> vendorExtensions = cs.getExtensions();
if (vendorExtensions != null && !vendorExtensions.isEmpty() && vendorExtensions.containsKey("x-discriminator-value")) { if (vendorExtensions != null && !vendorExtensions.isEmpty() && vendorExtensions.containsKey("x-discriminator-value")) {
String xDiscriminatorValue = (String) vendorExtensions.get("x-discriminator-value"); String xDiscriminatorValue = (String) vendorExtensions.get("x-discriminator-value");
mm = new MappedModel(xDiscriminatorValue, toModelName(modelName)); mm = new MappedModel(xDiscriminatorValue, toModelName(modelName), true);
descendentSchemas.add(mm); descendentSchemas.add(mm);
} }
} }
@ -3550,7 +3550,7 @@ public class DefaultCodegen implements CodegenConfig {
.map(ve -> ve.get("x-discriminator-value")) .map(ve -> ve.get("x-discriminator-value"))
.map(discriminatorValue -> (String) discriminatorValue) .map(discriminatorValue -> (String) discriminatorValue)
.orElse(currentSchemaName); .orElse(currentSchemaName);
MappedModel mm = new MappedModel(mappingName, toModelName(currentSchemaName)); MappedModel mm = new MappedModel(mappingName, toModelName(currentSchemaName), mappingName != currentSchemaName);
descendentSchemas.add(mm); descendentSchemas.add(mm);
} }
return descendentSchemas; return descendentSchemas;
@ -3604,7 +3604,7 @@ public class DefaultCodegen implements CodegenConfig {
} else { } else {
name = e.getValue(); name = e.getValue();
} }
uniqueDescendants.add(new MappedModel(e.getKey(), toModelName(name))); uniqueDescendants.add(new MappedModel(e.getKey(), toModelName(name), true));
} }
} }

View File

@ -1164,7 +1164,7 @@ public class DefaultCodegenTest {
sc = openAPI.getComponents().getSchemas().get(modelName); sc = openAPI.getComponents().getSchemas().get(modelName);
cm = codegen.fromModel(modelName, sc); cm = codegen.fromModel(modelName, sc);
hs.clear(); hs.clear();
hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"))); hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"), true));
hs.add(new CodegenDiscriminator.MappedModel("C", codegen.toModelName("C"))); hs.add(new CodegenDiscriminator.MappedModel("C", codegen.toModelName("C")));
Assert.assertEquals(cm.getHasDiscriminatorWithNonEmptyMapping(), true); Assert.assertEquals(cm.getHasDiscriminatorWithNonEmptyMapping(), true);
Assert.assertEquals(cm.discriminator.getMappedModels(), hs); Assert.assertEquals(cm.discriminator.getMappedModels(), hs);
@ -1174,7 +1174,7 @@ public class DefaultCodegenTest {
sc = openAPI.getComponents().getSchemas().get(modelName); sc = openAPI.getComponents().getSchemas().get(modelName);
cm = codegen.fromModel(modelName, sc); cm = codegen.fromModel(modelName, sc);
hs.clear(); hs.clear();
hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"))); hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"), true));
hs.add(new CodegenDiscriminator.MappedModel("C", codegen.toModelName("C"))); hs.add(new CodegenDiscriminator.MappedModel("C", codegen.toModelName("C")));
Assert.assertEquals(cm.getHasDiscriminatorWithNonEmptyMapping(), true); Assert.assertEquals(cm.getHasDiscriminatorWithNonEmptyMapping(), true);
Assert.assertEquals(cm.discriminator.getMappedModels(), hs); Assert.assertEquals(cm.discriminator.getMappedModels(), hs);
@ -1184,7 +1184,7 @@ public class DefaultCodegenTest {
sc = openAPI.getComponents().getSchemas().get(modelName); sc = openAPI.getComponents().getSchemas().get(modelName);
cm = codegen.fromModel(modelName, sc); cm = codegen.fromModel(modelName, sc);
hs.clear(); hs.clear();
hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"))); hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"), true));
Assert.assertEquals(cm.getHasDiscriminatorWithNonEmptyMapping(), true); Assert.assertEquals(cm.getHasDiscriminatorWithNonEmptyMapping(), true);
Assert.assertEquals(cm.discriminator.getMappedModels(), hs); Assert.assertEquals(cm.discriminator.getMappedModels(), hs);
} }
@ -1265,7 +1265,7 @@ public class DefaultCodegenTest {
sc = openAPI.getComponents().getSchemas().get(modelName); sc = openAPI.getComponents().getSchemas().get(modelName);
cm = codegen.fromModel(modelName, sc); cm = codegen.fromModel(modelName, sc);
hs.clear(); hs.clear();
hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"))); hs.add(new CodegenDiscriminator.MappedModel("b", codegen.toModelName("B"), true));
Assert.assertEquals(cm.discriminator.getMappedModels(), hs); Assert.assertEquals(cm.discriminator.getMappedModels(), hs);
// the mapping in b is in B // the mapping in b is in B
@ -1654,8 +1654,8 @@ public class DefaultCodegenTest {
discriminator.setPropertyBaseName(prop); discriminator.setPropertyBaseName(prop);
discriminator.setMapping(null); discriminator.setMapping(null);
discriminator.setMappedModels(new HashSet<CodegenDiscriminator.MappedModel>() {{ discriminator.setMappedModels(new HashSet<CodegenDiscriminator.MappedModel>() {{
add(new CodegenDiscriminator.MappedModel("daily", "DailySubObj")); add(new CodegenDiscriminator.MappedModel("daily", "DailySubObj", true));
add(new CodegenDiscriminator.MappedModel("sub-obj", "SubObj")); add(new CodegenDiscriminator.MappedModel("sub-obj", "SubObj", true));
}}); }});
assertEquals(cm.discriminator, discriminator); assertEquals(cm.discriminator, discriminator);
} }
@ -2049,8 +2049,8 @@ public class DefaultCodegenTest {
test.setMapping(new HashMap<>()); test.setMapping(new HashMap<>());
test.getMapping().put("a", "#/components/schemas/Adult"); test.getMapping().put("a", "#/components/schemas/Adult");
test.getMapping().put("c", "Child"); test.getMapping().put("c", "Child");
test.getMappedModels().add(new CodegenDiscriminator.MappedModel("a", "Adult")); test.getMappedModels().add(new CodegenDiscriminator.MappedModel("a", "Adult", true));
test.getMappedModels().add(new CodegenDiscriminator.MappedModel("c", "Child")); test.getMappedModels().add(new CodegenDiscriminator.MappedModel("c", "Child", true));
Assert.assertEquals(discriminator, test); Assert.assertEquals(discriminator, test);
} }

View File

@ -386,8 +386,8 @@ public class RubyClientCodegenTest {
CodegenDiscriminator codegenDiscriminator = person.getDiscriminator(); CodegenDiscriminator codegenDiscriminator = person.getDiscriminator();
Set<CodegenDiscriminator.MappedModel> mappedModels = new LinkedHashSet<CodegenDiscriminator.MappedModel>(); Set<CodegenDiscriminator.MappedModel> mappedModels = new LinkedHashSet<CodegenDiscriminator.MappedModel>();
mappedModels.add(new CodegenDiscriminator.MappedModel("a", "Adult")); mappedModels.add(new CodegenDiscriminator.MappedModel("a", "Adult", true));
mappedModels.add(new CodegenDiscriminator.MappedModel("c", "Child")); mappedModels.add(new CodegenDiscriminator.MappedModel("c", "Child", true));
Assert.assertEquals(codegenDiscriminator.getMappedModels(), mappedModels); Assert.assertEquals(codegenDiscriminator.getMappedModels(), mappedModels);
} }
@ -405,8 +405,8 @@ public class RubyClientCodegenTest {
CodegenDiscriminator codegenDiscriminator = person.getDiscriminator(); CodegenDiscriminator codegenDiscriminator = person.getDiscriminator();
Set<CodegenDiscriminator.MappedModel> mappedModels = new LinkedHashSet<CodegenDiscriminator.MappedModel>(); Set<CodegenDiscriminator.MappedModel> mappedModels = new LinkedHashSet<CodegenDiscriminator.MappedModel>();
mappedModels.add(new CodegenDiscriminator.MappedModel("a", "Adult")); mappedModels.add(new CodegenDiscriminator.MappedModel("a", "Adult", true));
mappedModels.add(new CodegenDiscriminator.MappedModel("c", "Child")); mappedModels.add(new CodegenDiscriminator.MappedModel("c", "Child", true));
Assert.assertEquals(codegenDiscriminator.getMappedModels(), mappedModels); Assert.assertEquals(codegenDiscriminator.getMappedModels(), mappedModels);
} }

View File

@ -0,0 +1,115 @@
Defaulting to user installation because normal site-packages is not writeable
Collecting tox
Downloading tox-4.4.12-py3-none-any.whl (148 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 149.0/149.0 KB 3.0 MB/s eta 0:00:00
Collecting flake8
Downloading flake8-6.0.0-py2.py3-none-any.whl (57 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.8/57.8 KB 10.7 MB/s eta 0:00:00
Collecting chardet>=5.1
Downloading chardet-5.1.0-py3-none-any.whl (199 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 199.1/199.1 KB 8.7 MB/s eta 0:00:00
Collecting tomli>=2.0.1
Downloading tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting filelock>=3.11
Downloading filelock-3.12.0-py3-none-any.whl (10 kB)
Collecting platformdirs>=3.2
Downloading platformdirs-3.2.0-py3-none-any.whl (14 kB)
Collecting pyproject-api>=1.5.1
Downloading pyproject_api-1.5.1-py3-none-any.whl (12 kB)
Collecting packaging>=23
Downloading packaging-23.1-py3-none-any.whl (48 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.9/48.9 KB 6.8 MB/s eta 0:00:00
Collecting pluggy>=1
Downloading pluggy-1.0.0-py2.py3-none-any.whl (13 kB)
Collecting virtualenv>=20.21
Downloading virtualenv-20.22.0-py3-none-any.whl (3.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 14.5 MB/s eta 0:00:00
Collecting colorama>=0.4.6
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting cachetools>=5.3
Downloading cachetools-5.3.0-py3-none-any.whl (9.3 kB)
Collecting mccabe<0.8.0,>=0.7.0
Downloading mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
Collecting pycodestyle<2.11.0,>=2.10.0
Downloading pycodestyle-2.10.0-py2.py3-none-any.whl (41 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.3/41.3 KB 5.0 MB/s eta 0:00:00
Collecting pyflakes<3.1.0,>=3.0.0
Downloading pyflakes-3.0.1-py2.py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.8/62.8 KB 14.3 MB/s eta 0:00:00
Requirement already satisfied: distlib<1,>=0.3.6 in /home/robbert/.local/lib/python3.10/site-packages (from virtualenv>=20.21->tox->-r dev-requirements.txt (line 1)) (0.3.6)
Installing collected packages: tomli, pyflakes, pycodestyle, pluggy, platformdirs, packaging, mccabe, filelock, colorama, chardet, cachetools, virtualenv, pyproject-api, flake8, tox
Attempting uninstall: filelock
Found existing installation: filelock 3.10.4
Uninstalling filelock-3.10.4:
Successfully uninstalled filelock-3.10.4
Attempting uninstall: virtualenv
Found existing installation: virtualenv 20.4.2
Uninstalling virtualenv-20.4.2:
Successfully uninstalled virtualenv-20.4.2
Successfully installed cachetools-5.3.0 chardet-5.1.0 colorama-0.4.6 filelock-3.12.0 flake8-6.0.0 mccabe-0.7.0 packaging-23.1 platformdirs-3.2.0 pluggy-1.0.0 pycodestyle-2.10.0 pyflakes-3.0.1 pyproject-api-1.5.1 tomli-2.0.1 tox-4.4.12 virtualenv-20.22.0
Collecting tox (from -r dev-requirements.txt (line 1))
Using cached tox-4.4.12-py3-none-any.whl (148 kB)
Collecting flake8 (from -r dev-requirements.txt (line 2))
Using cached flake8-6.0.0-py2.py3-none-any.whl (57 kB)
Collecting cachetools>=5.3 (from tox->-r dev-requirements.txt (line 1))
Using cached cachetools-5.3.0-py3-none-any.whl (9.3 kB)
Collecting chardet>=5.1 (from tox->-r dev-requirements.txt (line 1))
Using cached chardet-5.1.0-py3-none-any.whl (199 kB)
Collecting colorama>=0.4.6 (from tox->-r dev-requirements.txt (line 1))
Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting filelock>=3.11 (from tox->-r dev-requirements.txt (line 1))
Using cached filelock-3.12.0-py3-none-any.whl (10 kB)
Collecting packaging>=23 (from tox->-r dev-requirements.txt (line 1))
Using cached packaging-23.1-py3-none-any.whl (48 kB)
Collecting platformdirs>=3.2 (from tox->-r dev-requirements.txt (line 1))
Using cached platformdirs-3.2.0-py3-none-any.whl (14 kB)
Collecting pluggy>=1 (from tox->-r dev-requirements.txt (line 1))
Using cached pluggy-1.0.0-py2.py3-none-any.whl (13 kB)
Collecting pyproject-api>=1.5.1 (from tox->-r dev-requirements.txt (line 1))
Using cached pyproject_api-1.5.1-py3-none-any.whl (12 kB)
Collecting tomli>=2.0.1 (from tox->-r dev-requirements.txt (line 1))
Using cached tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting virtualenv>=20.21 (from tox->-r dev-requirements.txt (line 1))
Using cached virtualenv-20.22.0-py3-none-any.whl (3.2 MB)
Collecting mccabe<0.8.0,>=0.7.0 (from flake8->-r dev-requirements.txt (line 2))
Using cached mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
Collecting pycodestyle<2.11.0,>=2.10.0 (from flake8->-r dev-requirements.txt (line 2))
Using cached pycodestyle-2.10.0-py2.py3-none-any.whl (41 kB)
Collecting pyflakes<3.1.0,>=3.0.0 (from flake8->-r dev-requirements.txt (line 2))
Using cached pyflakes-3.0.1-py2.py3-none-any.whl (62 kB)
Collecting distlib<1,>=0.3.6 (from virtualenv>=20.21->tox->-r dev-requirements.txt (line 1))
Using cached distlib-0.3.6-py2.py3-none-any.whl (468 kB)
Installing collected packages: distlib, tomli, pyflakes, pycodestyle, pluggy, platformdirs, packaging, mccabe, filelock, colorama, chardet, cachetools, virtualenv, pyproject-api, flake8, tox
Successfully installed cachetools-5.3.0 chardet-5.1.0 colorama-0.4.6 distlib-0.3.6 filelock-3.12.0 flake8-6.0.0 mccabe-0.7.0 packaging-23.1 platformdirs-3.2.0 pluggy-1.0.0 pycodestyle-2.10.0 pyflakes-3.0.1 pyproject-api-1.5.1 tomli-2.0.1 tox-4.4.12 virtualenv-20.22.0
Requirement already satisfied: tox in ./venv/lib/python3.10/site-packages (from -r dev-requirements.txt (line 1)) (4.4.12)
Requirement already satisfied: flake8 in ./venv/lib/python3.10/site-packages (from -r dev-requirements.txt (line 2)) (6.0.0)
Requirement already satisfied: cachetools>=5.3 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (5.3.0)
Requirement already satisfied: chardet>=5.1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (5.1.0)
Requirement already satisfied: colorama>=0.4.6 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (0.4.6)
Requirement already satisfied: filelock>=3.11 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (3.12.0)
Requirement already satisfied: packaging>=23 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (23.1)
Requirement already satisfied: platformdirs>=3.2 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (3.2.0)
Requirement already satisfied: pluggy>=1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (1.0.0)
Requirement already satisfied: pyproject-api>=1.5.1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (1.5.1)
Requirement already satisfied: tomli>=2.0.1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (2.0.1)
Requirement already satisfied: virtualenv>=20.21 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (20.22.0)
Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in ./venv/lib/python3.10/site-packages (from flake8->-r dev-requirements.txt (line 2)) (0.7.0)
Requirement already satisfied: pycodestyle<2.11.0,>=2.10.0 in ./venv/lib/python3.10/site-packages (from flake8->-r dev-requirements.txt (line 2)) (2.10.0)
Requirement already satisfied: pyflakes<3.1.0,>=3.0.0 in ./venv/lib/python3.10/site-packages (from flake8->-r dev-requirements.txt (line 2)) (3.0.1)
Requirement already satisfied: distlib<1,>=0.3.6 in ./venv/lib/python3.10/site-packages (from virtualenv>=20.21->tox->-r dev-requirements.txt (line 1)) (0.3.6)
Requirement already satisfied: tox in ./venv/lib/python3.10/site-packages (from -r dev-requirements.txt (line 1)) (4.4.12)
Requirement already satisfied: flake8 in ./venv/lib/python3.10/site-packages (from -r dev-requirements.txt (line 2)) (6.0.0)
Requirement already satisfied: cachetools>=5.3 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (5.3.0)
Requirement already satisfied: chardet>=5.1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (5.1.0)
Requirement already satisfied: colorama>=0.4.6 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (0.4.6)
Requirement already satisfied: filelock>=3.11 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (3.12.0)
Requirement already satisfied: packaging>=23 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (23.1)
Requirement already satisfied: platformdirs>=3.2 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (3.2.0)
Requirement already satisfied: pluggy>=1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (1.0.0)
Requirement already satisfied: pyproject-api>=1.5.1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (1.5.1)
Requirement already satisfied: tomli>=2.0.1 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (2.0.1)
Requirement already satisfied: virtualenv>=20.21 in ./venv/lib/python3.10/site-packages (from tox->-r dev-requirements.txt (line 1)) (20.22.0)
Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in ./venv/lib/python3.10/site-packages (from flake8->-r dev-requirements.txt (line 2)) (0.7.0)
Requirement already satisfied: pycodestyle<2.11.0,>=2.10.0 in ./venv/lib/python3.10/site-packages (from flake8->-r dev-requirements.txt (line 2)) (2.10.0)
Requirement already satisfied: pyflakes<3.1.0,>=3.0.0 in ./venv/lib/python3.10/site-packages (from flake8->-r dev-requirements.txt (line 2)) (3.0.1)
Requirement already satisfied: distlib<1,>=0.3.6 in ./venv/lib/python3.10/site-packages (from virtualenv>=20.21->tox->-r dev-requirements.txt (line 1)) (0.3.6)

View File

@ -0,0 +1,13 @@
Metadata-Version: 2.1
Name: petstore-api
Version: 1.0.0
Summary: OpenAPI Petstore
Home-page:
Author: OpenAPI Generator community
Author-email: team@openapitools.org
License: Apache-2.0
Keywords: OpenAPI,OpenAPI-Generator,OpenAPI Petstore
Description-Content-Type: text/markdown
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \ # noqa: E501

View File

@ -0,0 +1,176 @@
README.md
pyproject.toml
setup.cfg
setup.py
petstore_api/__init__.py
petstore_api/api_client.py
petstore_api/configuration.py
petstore_api/exceptions.py
petstore_api/rest.py
petstore_api/signing.py
petstore_api.egg-info/PKG-INFO
petstore_api.egg-info/SOURCES.txt
petstore_api.egg-info/dependency_links.txt
petstore_api.egg-info/requires.txt
petstore_api.egg-info/top_level.txt
petstore_api/api/__init__.py
petstore_api/api/another_fake_api.py
petstore_api/api/default_api.py
petstore_api/api/fake_api.py
petstore_api/api/fake_classname_tags123_api.py
petstore_api/api/fake_classname_tags_123_api.py
petstore_api/api/pet_api.py
petstore_api/api/store_api.py
petstore_api/api/user_api.py
petstore_api/models/__init__.py
petstore_api/models/additional_properties_class.py
petstore_api/models/all_of_with_single_ref.py
petstore_api/models/animal.py
petstore_api/models/any_of_color.py
petstore_api/models/any_of_pig.py
petstore_api/models/api_response.py
petstore_api/models/array_of_array_of_number_only.py
petstore_api/models/array_of_number_only.py
petstore_api/models/array_test.py
petstore_api/models/basque_pig.py
petstore_api/models/capitalization.py
petstore_api/models/cat.py
petstore_api/models/cat_all_of.py
petstore_api/models/category.py
petstore_api/models/circular_reference_model.py
petstore_api/models/class_model.py
petstore_api/models/client.py
petstore_api/models/color.py
petstore_api/models/danish_pig.py
petstore_api/models/deprecated_object.py
petstore_api/models/dog.py
petstore_api/models/dog_all_of.py
petstore_api/models/dummy_model.py
petstore_api/models/enum_arrays.py
petstore_api/models/enum_class.py
petstore_api/models/enum_test.py
petstore_api/models/file.py
petstore_api/models/file_schema_test_class.py
petstore_api/models/first_ref.py
petstore_api/models/foo.py
petstore_api/models/foo_get_default_response.py
petstore_api/models/format_test.py
petstore_api/models/has_only_read_only.py
petstore_api/models/health_check_result.py
petstore_api/models/inner_dict_with_property.py
petstore_api/models/list.py
petstore_api/models/map_test.py
petstore_api/models/mixed_properties_and_additional_properties_class.py
petstore_api/models/model200_response.py
petstore_api/models/model_return.py
petstore_api/models/name.py
petstore_api/models/nullable_class.py
petstore_api/models/number_only.py
petstore_api/models/object_with_deprecated_fields.py
petstore_api/models/order.py
petstore_api/models/outer_composite.py
petstore_api/models/outer_enum.py
petstore_api/models/outer_enum_default_value.py
petstore_api/models/outer_enum_integer.py
petstore_api/models/outer_enum_integer_default_value.py
petstore_api/models/outer_object_with_enum_property.py
petstore_api/models/parent.py
petstore_api/models/parent_with_optional_dict.py
petstore_api/models/pet.py
petstore_api/models/pig.py
petstore_api/models/read_only_first.py
petstore_api/models/second_ref.py
petstore_api/models/self_reference_model.py
petstore_api/models/single_ref_type.py
petstore_api/models/special_character_enum.py
petstore_api/models/special_model_name.py
petstore_api/models/special_name.py
petstore_api/models/tag.py
petstore_api/models/user.py
petstore_api/models/with_nested_one_of.py
test/test_additional_properties_class.py
test/test_all_of_with_single_ref.py
test/test_animal.py
test/test_another_fake_api.py
test/test_any_of_color.py
test/test_any_of_pig.py
test/test_api_response.py
test/test_array_of_array_of_number_only.py
test/test_array_of_number_only.py
test/test_array_test.py
test/test_basque_pig.py
test/test_capitalization.py
test/test_cat.py
test/test_cat_all_of.py
test/test_category.py
test/test_circular_reference_model.py
test/test_class_model.py
test/test_client.py
test/test_color.py
test/test_configuration.py
test/test_danish_pig.py
test/test_default_api.py
test/test_deprecated_object.py
test/test_dog.py
test/test_dog_all_of.py
test/test_dummy_model.py
test/test_enum_arrays.py
test/test_enum_class.py
test/test_enum_test.py
test/test_fake_api.py
test/test_fake_classname_tags123_api.py
test/test_fake_classname_tags_123_api.py
test/test_file.py
test/test_file_schema_test_class.py
test/test_first_ref.py
test/test_foo.py
test/test_foo_get_default_response.py
test/test_format_test.py
test/test_has_only_read_only.py
test/test_health_check_result.py
test/test_inner_dict_with_property.py
test/test_list.py
test/test_map_test.py
test/test_mixed_properties_and_additional_properties_class.py
test/test_model200_response.py
test/test_model_return.py
test/test_name.py
test/test_nullable_class.py
test/test_number_only.py
test/test_object_with_deprecated_fields.py
test/test_order.py
test/test_outer_composite.py
test/test_outer_enum.py
test/test_outer_enum_default_value.py
test/test_outer_enum_integer.py
test/test_outer_enum_integer_default_value.py
test/test_outer_object_with_enum_property.py
test/test_parent.py
test/test_parent_with_optional_dict.py
test/test_pet.py
test/test_pet_api.py
test/test_pig.py
test/test_read_only_first.py
test/test_second_ref.py
test/test_self_reference_model.py
test/test_single_ref_type.py
test/test_special_character_enum.py
test/test_special_model_name.py
test/test_special_name.py
test/test_store_api.py
test/test_tag.py
test/test_user.py
test/test_user_api.py
test/test_with_nested_one_of.py
tests/test_api_client.py
tests/test_api_exception.py
tests/test_api_validation.py
tests/test_configuration.py
tests/test_deserialization.py
tests/test_http_signature.py
tests/test_map_test.py
tests/test_model.py
tests/test_order_model.py
tests/test_pet_api.py
tests/test_pet_model.py
tests/test_store_api.py

View File

@ -0,0 +1,6 @@
urllib3>=1.25.3
python-dateutil
pem>=19.3.0
pycryptodome>=3.9.0
pydantic<2,>=1.10.5
aenum

View File

@ -0,0 +1,349 @@
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
import re # noqa: F401
import sys # noqa: F401
from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
ModelNormal,
ModelSimple,
cached_property,
change_keys_js_to_python,
convert_js_args_to_python_args,
date,
datetime,
file_type,
none_type,
validate_get_composed_info,
OpenApiModel
)
from petstore_api.exceptions import ApiAttributeError
def lazy_import():
from petstore_api.model.pig import Pig
from petstore_api.model.whale import Whale
from petstore_api.model.zebra import Zebra
globals()['Pig'] = Pig
globals()['Whale'] = Whale
globals()['Zebra'] = Zebra
class Mammal(ModelComposed):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
Attributes:
allowed_values (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
with a capitalized key describing the allowed value and an allowed
value. These dicts store the allowed enum values.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
discriminator_value_class_map (dict): A dict to go from the discriminator
variable value to the discriminator class name.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum,
inclusive_minimum, and regex.
additional_properties_type (tuple): A tuple of classes accepted
as additional properties values.
"""
allowed_values = {
('type',): {
'PLAINS': "plains",
'MOUNTAIN': "mountain",
'GREVYS': "grevys",
},
}
validations = {
}
@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
lazy_import()
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
_nullable = False
@cached_property
def openapi_types():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
lazy_import()
return {
'class_name': (str,), # noqa: E501
'has_baleen': (bool,), # noqa: E501
'has_teeth': (bool,), # noqa: E501
'type': (str,), # noqa: E501
}
@cached_property
def discriminator():
lazy_import()
val = {
'whale': Whale,
'zebra': Zebra,
'Pig': Pig,
}
if not val:
return None
return {'class_name': val}
attribute_map = {
'class_name': 'className', # noqa: E501
'has_baleen': 'hasBaleen', # noqa: E501
'has_teeth': 'hasTeeth', # noqa: E501
'type': 'type', # noqa: E501
}
read_only_vars = {
}
@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
"""Mammal - a model defined in OpenAPI
Keyword Args:
class_name (str):
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Defaults to True
_path_to_item (tuple/list): This is a list of keys or values to
drill down to the model in received_data
when deserializing a response
_spec_property_naming (bool): True if the variable names in the input data
are serialized names, as specified in the OpenAPI document.
False if the variable names in the input data
are pythonic names, e.g. snake case (default)
_configuration (Configuration): the instance to use when
deserializing a file_type parameter.
If passed, type conversion is attempted
If omitted no type conversion is done.
_visited_composed_classes (tuple): This stores a tuple of
classes that we have traveled through so that
if we see that class again we will not use its
discriminator again.
When traveling through a discriminator, the
composed schema that is
is traveled through is added to this set.
For example if Animal has a discriminator
petType and we pass in "Dog", and the class Dog
allOf includes Animal, we move through Animal
once using the discriminator, and pick Dog.
Then in Dog, we will make an instance of the
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
has_baleen (bool): [optional] # noqa: E501
has_teeth (bool): [optional] # noqa: E501
type (str): [optional] # noqa: E501
"""
_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
_configuration = kwargs.pop('_configuration', None)
_visited_composed_classes = kwargs.pop('_visited_composed_classes', ())
self = super(OpenApiModel, cls).__new__(cls)
if args:
for arg in args:
if isinstance(arg, dict):
kwargs.update(arg)
else:
raise ApiTypeError(
"Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % (
args,
self.__class__.__name__,
),
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)
self._data_store = {}
self._check_type = _check_type
self._spec_property_naming = _spec_property_naming
self._path_to_item = _path_to_item
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
constant_args = {
'_check_type': _check_type,
'_path_to_item': _path_to_item,
'_spec_property_naming': _spec_property_naming,
'_configuration': _configuration,
'_visited_composed_classes': self._visited_composed_classes,
}
composed_info = validate_get_composed_info(
constant_args, kwargs, self)
self._composed_instances = composed_info[0]
self._var_name_to_model_instances = composed_info[1]
self._additional_properties_model_instances = composed_info[2]
discarded_args = composed_info[3]
for var_name, var_value in kwargs.items():
if var_name in discarded_args and \
self._configuration is not None and \
self._configuration.discard_unknown_keys and \
self._additional_properties_model_instances:
# discard variable.
continue
setattr(self, var_name, var_value)
return self
required_properties = set([
'_data_store',
'_check_type',
'_spec_property_naming',
'_path_to_item',
'_configuration',
'_visited_composed_classes',
'_composed_instances',
'_var_name_to_model_instances',
'_additional_properties_model_instances',
])
@convert_js_args_to_python_args
def __init__(self, *args, **kwargs): # noqa: E501
"""Mammal - a model defined in OpenAPI
Keyword Args:
class_name (str):
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Defaults to True
_path_to_item (tuple/list): This is a list of keys or values to
drill down to the model in received_data
when deserializing a response
_spec_property_naming (bool): True if the variable names in the input data
are serialized names, as specified in the OpenAPI document.
False if the variable names in the input data
are pythonic names, e.g. snake case (default)
_configuration (Configuration): the instance to use when
deserializing a file_type parameter.
If passed, type conversion is attempted
If omitted no type conversion is done.
_visited_composed_classes (tuple): This stores a tuple of
classes that we have traveled through so that
if we see that class again we will not use its
discriminator again.
When traveling through a discriminator, the
composed schema that is
is traveled through is added to this set.
For example if Animal has a discriminator
petType and we pass in "Dog", and the class Dog
allOf includes Animal, we move through Animal
once using the discriminator, and pick Dog.
Then in Dog, we will make an instance of the
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
has_baleen (bool): [optional] # noqa: E501
has_teeth (bool): [optional] # noqa: E501
type (str): [optional] # noqa: E501
"""
_check_type = kwargs.pop('_check_type', True)
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
_path_to_item = kwargs.pop('_path_to_item', ())
_configuration = kwargs.pop('_configuration', None)
_visited_composed_classes = kwargs.pop('_visited_composed_classes', ())
if args:
for arg in args:
if isinstance(arg, dict):
kwargs.update(arg)
else:
raise ApiTypeError(
"Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % (
args,
self.__class__.__name__,
),
path_to_item=_path_to_item,
valid_classes=(self.__class__,),
)
self._data_store = {}
self._check_type = _check_type
self._spec_property_naming = _spec_property_naming
self._path_to_item = _path_to_item
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
constant_args = {
'_check_type': _check_type,
'_path_to_item': _path_to_item,
'_spec_property_naming': _spec_property_naming,
'_configuration': _configuration,
'_visited_composed_classes': self._visited_composed_classes,
}
composed_info = validate_get_composed_info(
constant_args, kwargs, self)
self._composed_instances = composed_info[0]
self._var_name_to_model_instances = composed_info[1]
self._additional_properties_model_instances = composed_info[2]
discarded_args = composed_info[3]
for var_name, var_value in kwargs.items():
if var_name in discarded_args and \
self._configuration is not None and \
self._configuration.discard_unknown_keys and \
self._additional_properties_model_instances:
# discard variable.
continue
setattr(self, var_name, var_value)
if var_name in self.read_only_vars:
raise ApiAttributeError(f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate "
f"class with read only attributes.")
@cached_property
def _composed_schemas():
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
# when we invoke this method. If we kept this at the class
# level we would get an error because the class level
# code would be run when this module is imported, and these composed
# classes don't exist yet because their module has not finished
# loading
lazy_import()
return {
'anyOf': [
],
'allOf': [
],
'oneOf': [
Pig,
Whale,
Zebra,
],
}

View File

@ -29,8 +29,8 @@ import javax.annotation.Generated;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "fruitType", visible = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "fruitType", visible = true)
@JsonSubTypes({ @JsonSubTypes({
@JsonSubTypes.Type(value = Apple.class, name = "APPLE"), @JsonSubTypes.Type(value = Apple.class, name = "APPLE"),
@JsonSubTypes.Type(value = Apple.class, name = "Apple"),
@JsonSubTypes.Type(value = Banana.class, name = "BANANA"), @JsonSubTypes.Type(value = Banana.class, name = "BANANA"),
@JsonSubTypes.Type(value = Apple.class, name = "Apple"),
@JsonSubTypes.Type(value = Banana.class, name = "Banana") @JsonSubTypes.Type(value = Banana.class, name = "Banana")
}) })