Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2492,10 +2492,10 @@ protected String getSingleSchemaType(Schema schema) {
private String getPrimitiveType(Schema schema) {
if (schema == null) {
throw new RuntimeException("schema cannot be null in getPrimitiveType");
} else if (typeMapping.containsKey(schema.getType() + "+" + schema.getFormat())) {
} else if (typeMapping.containsKey(ModelUtils.getType(schema) + "+" + schema.getFormat())) {
// allows custom type_format mapping.
// use {type}+{format}
return typeMapping.get(schema.getType() + "+" + schema.getFormat());
return typeMapping.get(ModelUtils.getType(schema) + "+" + schema.getFormat());
} else if (ModelUtils.isNullType(schema)) {
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
// though this tooling supports it.
Expand Down Expand Up @@ -2536,7 +2536,7 @@ private String getPrimitiveType(Schema schema) {
} else if (ModelUtils.isShortSchema(schema)) {// int32
return "integer";
} else {
return schema.getType(); // integer
return ModelUtils.getType(schema); // integer
}
} else if (ModelUtils.isMapSchema(schema)) {
return "map";
Expand Down Expand Up @@ -2567,11 +2567,11 @@ private String getPrimitiveType(Schema schema) {
return "object";
} else if (ModelUtils.isAnyType(schema)) {
return "AnyType";
} else if (StringUtils.isNotEmpty(schema.getType())) {
if (!schemaMapping.containsKey(schema.getType())) {
LOGGER.warn("Unknown type found in the schema: {}. To map it, please use the schema mapping option (e.g. --schema-mappings in CLI)", schema.getType());
} else if (StringUtils.isNotEmpty(ModelUtils.getType(schema))) {
if (!schemaMapping.containsKey(ModelUtils.getType(schema))) {
LOGGER.warn("Unknown type found in the schema: {}. To map it, please use the schema mapping option (e.g. --schema-mappings in CLI)", ModelUtils.getType(schema));
}
return schema.getType();
return ModelUtils.getType(schema);
}
// The 'type' attribute has not been set in the OAS schema, which means the value
// can be an arbitrary type, e.g. integer, string, object, array, number...
Expand Down Expand Up @@ -4019,10 +4019,10 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo

property.name = toVarName(name);
property.baseName = name;
if (p.getType() == null) {
if (ModelUtils.getType(p) == null) {
property.openApiType = getSchemaType(p);
} else {
property.openApiType = p.getType();
property.openApiType = ModelUtils.getType(p);
}
property.nameInPascalCase = camelize(property.name);
property.nameInCamelCase = camelize(property.name, LOWERCASE_FIRST_LETTER);
Expand Down Expand Up @@ -7128,7 +7128,7 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
Schema original = null;
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
if (ModelUtils.isAllOf(schema) && schema.getAllOf().size() == 1 &&
schema.getType() == null && schema.getTypes() == null) {
ModelUtils.getType(schema) == null) {
if (schema.getAllOf().get(0) instanceof Schema) {
original = schema;
schema = (Schema) schema.getAllOf().get(0);
Expand Down Expand Up @@ -7781,7 +7781,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
Schema original = null;
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
if (ModelUtils.isAllOf(schema) && schema.getAllOf().size() == 1 &&
schema.getType() == null && schema.getTypes() == null) {
ModelUtils.getType(schema) == null) {
if (schema.getAllOf().get(0) instanceof Schema) {
original = schema;
schema = (Schema) schema.getAllOf().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,7 @@ public static String getSimpleRef(String ref) {
* @return true if the specified schema is an Object schema.
*/
public static boolean isTypeObjectSchema(Schema schema) {
if (schema instanceof JsonSchema) { // 3.1 spec
if (schema.getTypes() != null && schema.getTypes().size() == 1) {
return SchemaTypeUtil.OBJECT_TYPE.equals(schema.getTypes().iterator().next());
} else {
// null type or multiple types, e.g. [string, integer]
return false;
}
} else { // 3.0.x or 2.0 spec
return SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType());
}
return SchemaTypeUtil.OBJECT_TYPE.equals(getType(schema));
}

/**
Expand Down Expand Up @@ -460,9 +451,9 @@ public static boolean isObjectSchema(Schema schema) {

return (schema instanceof ObjectSchema) ||
// must not be a map
(SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType()) && !(ModelUtils.isMapSchema(schema))) ||
(SchemaTypeUtil.OBJECT_TYPE.equals(getType(schema)) && !(ModelUtils.isMapSchema(schema))) ||
// must have at least one property
(schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
(getType(schema) == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
}

/**
Expand Down Expand Up @@ -594,17 +585,7 @@ public static boolean isArraySchema(Schema schema) {
if (schema == null) {
return false;
}

if (schema instanceof JsonSchema) { // 3.1 spec
if (schema.getTypes() != null && schema.getTypes().contains("array")) {
return true;
} else {
return false;
}
} else { // 3.0 spec
return (schema instanceof ArraySchema) || "array".equals(schema.getType());
}

return (schema instanceof ArraySchema) || "array".equals(getType(schema));
}

/**
Expand Down Expand Up @@ -636,89 +617,89 @@ public static boolean isSet(Schema schema) {
}

public static boolean isStringSchema(Schema schema) {
return schema instanceof StringSchema || SchemaTypeUtil.STRING_TYPE.equals(schema.getType());
return schema instanceof StringSchema || SchemaTypeUtil.STRING_TYPE.equals(getType(schema));
}

public static boolean isIntegerSchema(Schema schema) {
return schema instanceof IntegerSchema || SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType());
return schema instanceof IntegerSchema || SchemaTypeUtil.INTEGER_TYPE.equals(getType(schema));
}

public static boolean isShortSchema(Schema schema) {
// format: short (int32)
return SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType()) // type: integer
return SchemaTypeUtil.INTEGER_TYPE.equals(getType(schema)) // type: integer
&& SchemaTypeUtil.INTEGER32_FORMAT.equals(schema.getFormat());
}

public static boolean isUnsignedIntegerSchema(Schema schema) {
return SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType()) && // type: integer
return SchemaTypeUtil.INTEGER_TYPE.equals(getType(schema)) && // type: integer
("int32".equals(schema.getFormat()) || schema.getFormat() == null) && // format: int32
(schema.getExtensions() != null && (Boolean) schema.getExtensions().getOrDefault("x-unsigned", Boolean.FALSE));
}

public static boolean isLongSchema(Schema schema) {
// format: long (int64)
return SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType()) // type: integer
return SchemaTypeUtil.INTEGER_TYPE.equals(getType(schema)) // type: integer
&& SchemaTypeUtil.INTEGER64_FORMAT.equals(schema.getFormat());
}

public static boolean isUnsignedLongSchema(Schema schema) {
return SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType()) && // type: integer
return SchemaTypeUtil.INTEGER_TYPE.equals(getType(schema)) && // type: integer
"int64".equals(schema.getFormat()) && // format: int64
(schema.getExtensions() != null && (Boolean) schema.getExtensions().getOrDefault("x-unsigned", Boolean.FALSE));
}

public static boolean isBooleanSchema(Schema schema) {
return schema instanceof BooleanSchema || SchemaTypeUtil.BOOLEAN_TYPE.equals(schema.getType());
return schema instanceof BooleanSchema || SchemaTypeUtil.BOOLEAN_TYPE.equals(getType(schema));
}

public static boolean isNumberSchema(Schema schema) {
return schema instanceof NumberSchema || SchemaTypeUtil.NUMBER_TYPE.equals(schema.getType());
return schema instanceof NumberSchema || SchemaTypeUtil.NUMBER_TYPE.equals(getType(schema));
}

public static boolean isFloatSchema(Schema schema) {
// format: float
return SchemaTypeUtil.NUMBER_TYPE.equals(schema.getType())
return SchemaTypeUtil.NUMBER_TYPE.equals(getType(schema))
&& SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat());
}

public static boolean isDoubleSchema(Schema schema) {
// format: double
return SchemaTypeUtil.NUMBER_TYPE.equals(schema.getType())
return SchemaTypeUtil.NUMBER_TYPE.equals(getType(schema))
&& SchemaTypeUtil.DOUBLE_FORMAT.equals(schema.getFormat());
}

public static boolean isDateSchema(Schema schema) {
return (schema instanceof DateSchema) ||
// format: date
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.DATE_FORMAT.equals(schema.getFormat()));
}

public static boolean isDateTimeSchema(Schema schema) {
return (schema instanceof DateTimeSchema) ||
// format: date-time
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.DATE_TIME_FORMAT.equals(schema.getFormat()));
}

public static boolean isPasswordSchema(Schema schema) {
return (schema instanceof PasswordSchema) ||
// double
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.PASSWORD_FORMAT.equals(schema.getFormat()));
}

public static boolean isByteArraySchema(Schema schema) {
return (schema instanceof ByteArraySchema) ||
// format: byte
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.BYTE_FORMAT.equals(schema.getFormat()));
}

public static boolean isBinarySchema(Schema schema) {
return (schema instanceof BinarySchema) ||
// format: binary
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.BINARY_FORMAT.equals(schema.getFormat()));
}

Expand All @@ -731,26 +712,26 @@ public static boolean isFileSchema(Schema schema) {
public static boolean isUUIDSchema(Schema schema) {
return (schema instanceof UUIDSchema) ||
// format: uuid
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.UUID_FORMAT.equals(schema.getFormat()));
}

public static boolean isURISchema(Schema schema) {
// format: uri
return SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
return SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& URI_FORMAT.equals(schema.getFormat());
}

public static boolean isEmailSchema(Schema schema) {
return (schema instanceof EmailSchema) ||
// format: email
(SchemaTypeUtil.STRING_TYPE.equals(schema.getType())
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.EMAIL_FORMAT.equals(schema.getFormat()));
}

public static boolean isDecimalSchema(Schema schema) {
// format: number
return SchemaTypeUtil.STRING_TYPE.equals(schema.getType()) // type: string
return SchemaTypeUtil.STRING_TYPE.equals(getType(schema)) // type: string
&& "number".equals(schema.getFormat());
}

Expand Down Expand Up @@ -898,7 +879,7 @@ public static boolean isFreeFormObject(Schema schema) {
}

// has at least one property
if ("object".equals(schema.getType())) {
if ("object".equals(getType(schema))) {
// no properties
if ((schema.getProperties() == null || schema.getProperties().isEmpty())) {
Schema addlProps = ModelUtils.getAdditionalProperties(schema);
Expand Down Expand Up @@ -1782,7 +1763,7 @@ public static boolean isNullableComposedSchema(Schema schema) {
* @return true if the schema is the 'null' type
*/
public static boolean isNullType(Schema schema) {
return "null".equals(schema.getType());
return "null".equals(getType(schema));
}

/**
Expand All @@ -1798,7 +1779,7 @@ public static boolean isAnyType(Schema schema) {
// TODO remove the ref check here, or pass in the spec version
// openapi 3.1.0 specs allow ref to be adjacent to any keyword
// openapi 3.0.3 and earlier do not allow adjacent keywords to refs
return (schema.get$ref() == null && schema.getType() == null);
return (schema.get$ref() == null && getType(schema) == null);
}

public static void syncValidationProperties(Schema schema, IJsonSchemaValidationProperties target) {
Expand Down Expand Up @@ -1930,7 +1911,7 @@ private static void setNumericValidations(Schema schema, BigDecimal multipleOf,
private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
setValidations.removeAll(effectiveValidations);
setValidations.stream().forEach(validation -> {
LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + schema.getType() +"'. Ignoring!");
LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) +"'. Ignoring!");
});
}

Expand Down Expand Up @@ -2139,7 +2120,11 @@ public static String getType(Schema schema) {
}

if (schema instanceof JsonSchema) {
return String.valueOf(schema.getTypes().iterator().next());
if (schema.getTypes() != null) {
return String.valueOf(schema.getTypes().iterator().next());
} else {
return null;
}
} else {
return schema.getType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,15 @@ components:
- Code 1
- Code 2
- Code 3
SimpleModelWithArrayProperty:
type: object
required:
- arrayOfStrings
properties:
arrayOfStrings:
type: array
items:
type: string
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ README.md
api/openapi.yaml
build.gradle
build.sbt
docs/AllOfSimpleModel.md
docs/Animal.md
docs/AnyTypeTest.md
docs/ArrayOfSameRef.md
Expand All @@ -21,6 +22,7 @@ docs/OneOfStringOrInt.md
docs/Order.md
docs/Pet.md
docs/PetApi.md
docs/SimpleModelWithArrayProperty.md
docs/StoreApi.md
docs/StringOrInt.md
docs/Tag.md
Expand Down Expand Up @@ -61,6 +63,7 @@ src/main/java/org/openapitools/client/auth/OAuthFlow.java
src/main/java/org/openapitools/client/auth/OAuthOkHttpClient.java
src/main/java/org/openapitools/client/auth/RetryingOAuth.java
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
src/main/java/org/openapitools/client/model/AllOfSimpleModel.java
src/main/java/org/openapitools/client/model/Animal.java
src/main/java/org/openapitools/client/model/AnyTypeTest.java
src/main/java/org/openapitools/client/model/ArrayOfSameRef.java
Expand All @@ -75,6 +78,7 @@ src/main/java/org/openapitools/client/model/ModelApiResponse.java
src/main/java/org/openapitools/client/model/OneOfStringOrInt.java
src/main/java/org/openapitools/client/model/Order.java
src/main/java/org/openapitools/client/model/Pet.java
src/main/java/org/openapitools/client/model/SimpleModelWithArrayProperty.java
src/main/java/org/openapitools/client/model/StringOrInt.java
src/main/java/org/openapitools/client/model/Tag.java
src/main/java/org/openapitools/client/model/User.java
2 changes: 2 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Class | Method | HTTP request | Description

## Documentation for Models

- [AllOfSimpleModel](docs/AllOfSimpleModel.md)
- [Animal](docs/Animal.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [ArrayOfSameRef](docs/ArrayOfSameRef.md)
Expand All @@ -158,6 +159,7 @@ Class | Method | HTTP request | Description
- [OneOfStringOrInt](docs/OneOfStringOrInt.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
- [SimpleModelWithArrayProperty](docs/SimpleModelWithArrayProperty.md)
- [StringOrInt](docs/StringOrInt.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)
Expand Down
11 changes: 11 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,17 @@ components:
- Code 2
- Code 3
type: string
SimpleModelWithArrayProperty:
properties:
arrayOfStrings:
items:
type: string
type: array
required:
- arrayOfStrings
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
updatePetWithForm_request:
properties:
name:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# AllOfSimpleModel


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**arrayOfStrings** | **List&lt;String&gt;** | | |



Loading