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

Commit 2bac472

Browse files
committed
v2 class and method name cleanup (#112)
* from_openapi_data_oapg -> from_openapi_data_ * _verify_typed_dict_inputs_oapg -> _verify_typed_dict_inputs * _get_host_oapg -> _get_host * _{{operationId}}_oapg -> _{{operationId}} * _raise_validation_error_message_oapg -> _raise_validation_error_message * is_true_oapg -> is_true_ * is_false_oapg -> is_false_ * is_none_oapg -> is_none_ * as_date_oapg -> as_date_ * as_datetime_oapg -> as_datetime_ * as_decimal_oapg -> as_decimal_ * as_uuid_oapg -> as_uuid_ * as_float_oapg -> as_float_ * as_int_oapg -> as_int_ * _get_class_oapg -> _get_class * get_item_oapg -> get_item_ * _validate_oapg -> _validate * _process_schema_classes_oapg -> _process_schema_classes * _get_new_instance_without_conversion_oapg -> _get_new_instance_without_conversion * as_str_oapg -> as_str_ * _get_items_oapg -> _get_items * _get_properties_oapg -> _get_properties * Samples regenerated * Readme update * MetaOapg -> Schema_ * _configuration -> configuration_ * _arg -> arg_ * _args -> args_ * JsonSchema -> OpenApiSchema, OpenapiComponent -> OpenApiComponent
1 parent bb3a4ae commit 2bac472

File tree

1,432 files changed

+13287
-13315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,432 files changed

+13287
-13315
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Currently, the following languages/frameworks are supported:
4848
- Openapi spec inline schemas supported at any depth
4949
- If needed, validation of some json schema keywords can be deactivated via a configuration class
5050
- Payload values are not coerced when validated, so a datetime value can pass other validations that describe the payload only as type string
51-
- String transmission of numbers supported with type: string, format: number, value can be accessed as a Decimal with inst.as_decimal_oapg
51+
- String transmission of numbers supported with type: string, format: number, value can be accessed as a Decimal with inst.as_decimal_
5252
- Multiple content types supported for request and response bodies
5353
- Endpoint response always also includes the urllib3.HTTPResponse
5454
- Endpoint response deserialization can be skipped with the skip_deserialization argument

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenRequestBody.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.openapitools.codegen;
1919

20-
import org.openapitools.codegen.utils.ModelUtils;
21-
2220
import java.util.HashMap;
2321
import java.util.HashSet;
2422
import java.util.LinkedHashMap;
@@ -31,7 +29,7 @@
3129
* A unique parameter is defined by a combination of a name and location.
3230
* Parameters may be located in a path, query, header or cookie.
3331
*/
34-
public class CodegenRequestBody implements OpenapiComponent {
32+
public class CodegenRequestBody implements OpenApiComponent {
3533
protected String description, unescapedDescription;
3634

3735
protected CodegenKey name;

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.util.*;
2121

22-
public class CodegenResponse implements OpenapiComponent {
22+
public class CodegenResponse implements OpenApiComponent {
2323
private CodegenKey name;
2424
private Map<String, CodegenHeader> headers;
2525
public String message;

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenSchema.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import java.util.*;
2323

24-
public class CodegenSchema implements JsonSchema, OpenapiComponent {
24+
public class CodegenSchema implements OpenApiSchema, OpenApiComponent {
2525
// testCases are for autogenerated tests of schemas
2626
public HashMap<String, SchemaTestCase> testCases = new HashMap<>();
2727
private String componentModule;

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ protected String toComponentModule(String componentName, String priorJsonPathSeg
22112211
return packageName + "." + priorJsonPathSegment + "." + componentName;
22122212
}
22132213

2214-
protected void setAddProps(Schema schema, JsonSchema property, String sourceJsonPath, String currentJsonPath) {
2214+
protected void setAddProps(Schema schema, OpenApiSchema property, String sourceJsonPath, String currentJsonPath) {
22152215
if (schema.getAdditionalProperties() == null) {
22162216
return;
22172217
}
@@ -3905,11 +3905,11 @@ protected boolean shouldAddImport(String type) {
39053905
/**
39063906
* Add variables (properties) to codegen model (list of properties, various flags, etc)
39073907
*
3908-
* @param m Must be an instance of JsonSchema, may be model or property...
3908+
* @param m Must be an instance of OpenApiSchema, may be model or property...
39093909
* @param properties a map of properties (schema)
39103910
* @param mandatory a set of required properties' name
39113911
*/
3912-
protected void addProperties(JsonSchema m, Map<String, Schema> properties, Set<String> mandatory, String sourceJsonPath, String currentJsonPath) {
3912+
protected void addProperties(OpenApiSchema m, Map<String, Schema> properties, Set<String> mandatory, String sourceJsonPath, String currentJsonPath) {
39133913
if (properties == null) {
39143914
return;
39153915
}
@@ -5060,7 +5060,7 @@ protected String toRefModule(String ref, String sourceJsonPath, String expectedC
50605060
return null;
50615061
}
50625062

5063-
private void setLocationInfo(String ref, OpenapiComponent instance, String sourceJsonPath, String expectedComponentType) {
5063+
private void setLocationInfo(String ref, OpenApiComponent instance, String sourceJsonPath, String expectedComponentType) {
50645064
if (ref != null) {
50655065
instance.setRef(ref);
50665066
String refModule = toRefModule(ref, sourceJsonPath, expectedComponentType);
@@ -5156,7 +5156,7 @@ public CodegenKey getKey(String key) {
51565156
return ck;
51575157
}
51585158

5159-
protected void addRequiredProperties(Schema schema, JsonSchema property, String sourceJsonPath, String currentJsonPath) {
5159+
protected void addRequiredProperties(Schema schema, OpenApiSchema property, String sourceJsonPath, String currentJsonPath) {
51605160
/*
51615161
this should be called after vars and additionalProperties are set
51625162
Features added by storing codegenProperty values:
@@ -5211,7 +5211,7 @@ protected void addRequiredProperties(Schema schema, JsonSchema property, String
52115211
}
52125212
}
52135213

5214-
protected void addVarsRequiredVarsAdditionalProps(Schema schema, JsonSchema property, String sourceJsonPath, String currentJsonPath) {
5214+
protected void addVarsRequiredVarsAdditionalProps(Schema schema, OpenApiSchema property, String sourceJsonPath, String currentJsonPath) {
52155215
setAddProps(schema, property, sourceJsonPath, currentJsonPath);
52165216
Set<String> mandatory = schema.getRequired() == null ? Collections.emptySet()
52175217
: new TreeSet<>(schema.getRequired());
@@ -5609,7 +5609,7 @@ public String getAdditionalPropertiesName() {
56095609
* Used to ensure that null or Schema is returned given an input Boolean/Schema/null
56105610
* This will be used in openapi 3.1.0 spec processing to ensure that Booleans become Schemas
56115611
* Because our generators only understand Schemas
5612-
* Note: use getIsBooleanSchemaTrue or getIsBooleanSchemaFalse on the JsonSchema
5612+
* Note: use getIsBooleanSchemaTrue or getIsBooleanSchemaFalse on the OpenApiSchema
56135613
* if you need to be able to detect if the original schema's value was true or false
56145614
*
56155615
* @param schema the input Boolean or Schema data to convert to a Schema

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/OpenapiComponent.java renamed to modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/OpenApiComponent.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
package org.openapitools.codegen;
22

3-
import io.swagger.v3.oas.models.media.Schema;
4-
import org.openapitools.codegen.meta.FeatureSet;
5-
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
6-
import org.openapitools.codegen.utils.ModelUtils;
7-
8-
import java.util.Arrays;
9-
import java.util.Collections;
10-
import java.util.HashSet;
11-
import java.util.LinkedHashMap;
12-
import java.util.List;
13-
import java.util.Map;
14-
import java.util.Set;
15-
import java.util.stream.Stream;
16-
17-
public interface OpenapiComponent {
3+
public interface OpenApiComponent {
184
// set only if the instance is at the json path of a component
195
String getComponentModule();
206

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/JsonSchema.java renamed to modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/OpenApiSchema.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package org.openapitools.codegen;
22

3-
import java.util.Arrays;
4-
import java.util.Collections;
5-
import java.util.HashSet;
63
import java.util.LinkedHashMap;
74
import java.util.List;
8-
import java.util.Set;
9-
import java.util.stream.Stream;
105

116
import io.swagger.v3.oas.models.ExternalDocumentation;
127
import io.swagger.v3.oas.models.media.Schema;
13-
import org.openapitools.codegen.meta.FeatureSet;
14-
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
158
import org.openapitools.codegen.utils.ModelUtils;
169

17-
public interface JsonSchema {
10+
public interface OpenApiSchema {
1811
// 3.1.0
1912
CodegenSchema getContains();
2013

@@ -221,7 +214,7 @@ public interface JsonSchema {
221214
void setExternalDocumentation(ExternalDocumentation externalDocumentation);
222215

223216
/**
224-
* Syncs all the schema's type properties into the JsonSchema instance
217+
* Syncs all the schema's type properties into the OpenApiSchema instance
225218
* for now this only supports types without format information
226219
* TODO: in the future move the format handling in here too
227220
* @param p the schema which contains the type info

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import io.swagger.v3.oas.models.servers.Server;
2727

2828
import org.apache.commons.io.FileUtils;
29-
import org.openapitools.codegen.JsonSchema;
29+
import org.openapitools.codegen.OpenApiSchema;
3030
import org.openapitools.codegen.api.TemplatePathLocator;
3131
import org.openapitools.codegen.config.GlobalSettings;
3232
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
@@ -540,7 +540,7 @@ are defined in that schema (x.properties). We do this because validation should
540540
they are not.
541541
*/
542542
@Override
543-
protected void addVarsRequiredVarsAdditionalProps(Schema schema, JsonSchema property, String sourceJsonPath, String currentJsonPath){
543+
protected void addVarsRequiredVarsAdditionalProps(Schema schema, OpenApiSchema property, String sourceJsonPath, String currentJsonPath){
544544
setAddProps(schema, property, sourceJsonPath, currentJsonPath);
545545
if (ModelUtils.isAnyType(schema) && supportsAdditionalPropertiesWithComposedSchema) {
546546
// if anyType schema has properties then add them

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
import io.swagger.v3.parser.util.RemoteUrl;
3535
import io.swagger.v3.parser.util.SchemaTypeUtil;
3636
import org.apache.commons.lang3.StringUtils;
37-
import org.openapitools.codegen.CodegenSchema;
38-
import org.openapitools.codegen.JsonSchema;
37+
import org.openapitools.codegen.OpenApiSchema;
3938
import org.openapitools.codegen.config.GlobalSettings;
4039
import org.slf4j.Logger;
4140
import org.slf4j.LoggerFactory;
@@ -1463,8 +1462,8 @@ public static boolean isAnyType(Schema schema) {
14631462
return (schema.get$ref() == null && schema.getType() == null);
14641463
}
14651464

1466-
public static void syncValidationProperties(Schema schema, JsonSchema target) {
1467-
// TODO move this method to JsonSchema
1465+
public static void syncValidationProperties(Schema schema, OpenApiSchema target) {
1466+
// TODO move this method to OpenApiSchema
14681467
if (schema != null && target != null) {
14691468
if (isNullType(schema) || schema.get$ref() != null || isBooleanSchema(schema)) {
14701469
return;
@@ -1508,24 +1507,24 @@ public static void syncValidationProperties(Schema schema, JsonSchema target) {
15081507
}
15091508
}
15101509

1511-
private static void setArrayValidations(Integer minItems, Integer maxItems, Boolean uniqueItems, JsonSchema target) {
1510+
private static void setArrayValidations(Integer minItems, Integer maxItems, Boolean uniqueItems, OpenApiSchema target) {
15121511
if (minItems != null) target.setMinItems(minItems);
15131512
if (maxItems != null) target.setMaxItems(maxItems);
15141513
if (uniqueItems != null) target.setUniqueItems(uniqueItems);
15151514
}
15161515

1517-
private static void setObjectValidations(Integer minProperties, Integer maxProperties, JsonSchema target) {
1516+
private static void setObjectValidations(Integer minProperties, Integer maxProperties, OpenApiSchema target) {
15181517
if (minProperties != null) target.setMinProperties(minProperties);
15191518
if (maxProperties != null) target.setMaxProperties(maxProperties);
15201519
}
15211520

1522-
private static void setStringValidations(Integer minLength, Integer maxLength, String pattern, JsonSchema target) {
1521+
private static void setStringValidations(Integer minLength, Integer maxLength, String pattern, OpenApiSchema target) {
15231522
if (minLength != null) target.setMinLength(minLength);
15241523
if (maxLength != null) target.setMaxLength(maxLength);
15251524
if (pattern != null) target.setPattern(pattern);
15261525
}
15271526

1528-
private static void setNumericValidations(Schema schema, BigDecimal multipleOf, BigDecimal minimum, BigDecimal maximum, Boolean exclusiveMinimum, Boolean exclusiveMaximum, JsonSchema target) {
1527+
private static void setNumericValidations(Schema schema, BigDecimal multipleOf, BigDecimal minimum, BigDecimal maximum, Boolean exclusiveMinimum, Boolean exclusiveMaximum, OpenApiSchema target) {
15291528
if (multipleOf != null) target.setMultipleOf(multipleOf);
15301529
if (minimum != null) {
15311530
if (isIntegerSchema(schema)) {

modules/openapi-json-schema-generator/src/main/resources/python/README.handlebars

+10-11
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ Python {{generatorLanguageVersion}}
3535
- ingested None will subclass NoneClass
3636
- ingested True will subclass BoolClass
3737
- ingested False will subclass BoolClass
38-
- So if you need to check is True/False/None, instead use instance.is_true_oapg()/.is_false_oapg()/.is_none_oapg()
38+
- So if you need to check is True/False/None, instead use instance.is_true_()/.is_false_()/.is_none_()
3939
5. All validated class instances are immutable except for ones based on io.File
4040
- This is because if properties were changed after validation, that validation would no longer apply
4141
- So no changing values or property values after a class has been instantiated
4242
6. String + Number types with formats
4343
- String type data is stored as a string and if you need to access types based on its format like date,
4444
date-time, uuid, number etc then you will need to use accessor functions on the instance
45-
- type string + format: See .as_date_oapg, .as_datetime_oapg, .as_decimal_oapg, .as_uuid_oapg
46-
- type number + format: See .as_float_oapg, .as_int_oapg
45+
- type string + format: See .as_date_, .as_datetime_, .as_decimal_, .as_uuid_
46+
- type number + format: See .as_float_, .as_int_
4747
- this was done because openapi/json-schema defines constraints. string data may be type string with no format
4848
keyword in one schema, and include a format constraint in another schema
49-
- So if you need to access a string format based type, use as_date_oapg/as_datetime_oapg/as_decimal_oapg/as_uuid_oapg
50-
- So if you need to access a number format based type, use as_int_oapg/as_float_oapg
49+
- So if you need to access a string format based type, use as_date_/as_datetime_/as_decimal_/as_uuid_
50+
- So if you need to access a number format based type, use as_int_/as_float_
5151
7. Property access on AnyType(type unset) or object(dict) schemas
5252
- Only required keys with valid python names are properties like .someProp and have type hints
5353
- All optional keys may not exist, so properties are not defined for them
5454
- One can access optional values with dict_instance['optionalProp'] and KeyError will be raised if it does not exist
55-
- Use get_item_oapg if you need a way to always get a value whether or not the key exists
56-
- If the key does not exist, schemas.unset is returned from calling dict_instance.get_item_oapg('optionalProp')
55+
- Use get_item_ if you need a way to always get a value whether or not the key exists
56+
- If the key does not exist, schemas.unset is returned from calling dict_instance.get_item_('optionalProp')
5757
- All required and optional keys have type hints for this method, and @typing.overload is used
5858
- A type hint is also generated for additionalProperties accessed using this method
5959
- So you will need to update you code to use some_instance['optionalProp'] to access optional property
@@ -69,19 +69,18 @@ Python {{generatorLanguageVersion}}
6969
- Those apis will only load their needed models, which is less to load than all of the resources needed in a tag api
7070
- So you will need to update your import paths to the api classes
7171

72-
### Why are Oapg and _oapg used in class and method names?
72+
### Why are Leading and Trailing Underscores in class and method names?
7373
Classes can have arbitrarily named properties set on them
7474
Endpoints can have arbitrary operationId method names set
75-
For those reasons, I use the prefix Oapg and _oapg to greatly reduce the likelihood of collisions
75+
For those reasons, I use the prefix and suffix _ to greatly reduce the likelihood of collisions
7676
on protected + public classes/methods.
77-
oapg stands for OpenApi Python Generator.
7877

7978
### Object property spec case
8079
This was done because when payloads are ingested, they can be validated against N number of schemas.
8180
If the input signature used a different property name then that has mutated the payload.
8281
So SchemaA and SchemaB must both see the camelCase spec named variable.
8382
Also it is possible to send in two properties, named camelCase and camel_case in the same payload.
84-
That use case should be support so spec case is used.
83+
That use case should work, so spec case is used.
8584

8685
### Parameter spec case
8786
Parameters can be included in different locations including:

modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars

+7-7
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ class HeaderParameterWithoutName(ParameterBase, StyleSimpleSerializer):
670670
"""
671671
if cls.style:
672672
extracted_data = cls._deserialize_simple(in_data, name, cls.explode, False)
673-
return schema.from_openapi_data_oapg(extracted_data)
673+
return schema.from_openapi_data_(extracted_data)
674674
# cls.content will be length one
675675
for content_type, schema in cls.content.items():
676676
if cls._content_type_is_json(content_type):
677677
cast_in_data = json.loads(in_data)
678-
return schema.from_openapi_data_oapg(cast_in_data)
678+
return schema.from_openapi_data_(cast_in_data)
679679
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
680680

681681

@@ -753,7 +753,7 @@ class ApiResponseWithoutDeserialization(ApiResponse):
753753

754754
class TypedDictInputVerifier:
755755
@staticmethod
756-
def _verify_typed_dict_inputs_oapg(cls: typing.Type[typing_extensions.TypedDict], data: typing.Dict[str, typing.Any]):
756+
def _verify_typed_dict_inputs(cls: typing.Type[typing_extensions.TypedDict], data: typing.Dict[str, typing.Any]):
757757
"""
758758
Ensures that:
759759
- required keys are present
@@ -890,7 +890,7 @@ class OpenApiResponse(JSONDetector, TypedDictInputVerifier, typing.Generic[T]):
890890

891891
deserialized_headers = schemas.unset
892892
if cls.headers is not None:
893-
cls._verify_typed_dict_inputs_oapg(cls.response_cls.headers, response.headers)
893+
cls._verify_typed_dict_inputs(cls.response_cls.headers, response.headers)
894894
deserialized_headers = {}
895895
for header_name, header_param in self.headers.items():
896896
header_value = response.getheader(header_name)
@@ -923,8 +923,8 @@ class OpenApiResponse(JSONDetector, TypedDictInputVerifier, typing.Generic[T]):
923923
content_type = 'multipart/form-data'
924924
else:
925925
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
926-
deserialized_body = body_schema.from_openapi_data_oapg(
927-
body_data, _configuration=configuration)
926+
deserialized_body = body_schema.from_openapi_data_(
927+
body_data, configuration_=configuration)
928928
elif streamed:
929929
response.release_conn()
930930

@@ -1259,7 +1259,7 @@ class Api(TypedDictInputVerifier):
12591259
api_client = ApiClient()
12601260
self.api_client = api_client
12611261

1262-
def _get_host_oapg(
1262+
def _get_host(
12631263
self,
12641264
operation_id: str,
12651265
servers: typing.Tuple[typing.Dict[str, str], ...] = tuple(),

0 commit comments

Comments
 (0)