diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index c46de7746322..def572e2ba97 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -1935,7 +1935,7 @@ private static void setNumericValidations(Schema schema, BigDecimal multipleOf, private static void logWarnMessagesForIneffectiveValidations(Set setValidations, Schema schema, Set effectiveValidations) { setValidations.removeAll(effectiveValidations); setValidations.stream().forEach(validation -> { - LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) +"'. Ignoring!"); + LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) + "'. Ignoring!"); }); } @@ -2260,11 +2260,14 @@ public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) { } // for `type: null` - if (schema.getTypes() == null && schema.get$ref() == null) { + if (schema.getTypes() == null && schema.get$ref() == null + && schema.getDescription() == null) { // ensure it's not schema with just a description) return true; } } else { // 3.0.x or 2.x spec - if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) { + if ((schema.getType() == null || schema.getType().equals("null")) + && schema.get$ref() == null + && schema.getDescription() == null) { // ensure it's not schema with just a description) return true; } } @@ -2290,7 +2293,7 @@ public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) { // dereference the schema schema = ModelUtils.getReferencedSchema(openAPI, schema); - if (schema.getTypes() == null && hasValidation(schema)) { + if (schema.getTypes() == null && hasValidation(schema)) { // just validation without type return true; } else if (schema.getIf() != null && schema.getThen() != null) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java index 05a3cb48d549..3405a3003623 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java @@ -497,9 +497,22 @@ public void isNullTypeSchemaTest() { schema = openAPI.getComponents().getSchemas().get("AnyOfTest"); assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema)); + // first element (getAnyOf().get(0)) is a string. no need to test assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(1))); assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2))); assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(3))); + + schema = openAPI.getComponents().getSchemas().get("OneOfRef"); + assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema)); + assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(0))); + + schema = openAPI.getComponents().getSchemas().get("OneOfMultiRef"); + assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema)); + assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(0))); + assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(1))); + + schema = openAPI.getComponents().getSchemas().get("JustDescription"); + assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema)); } @Test diff --git a/modules/openapi-generator/src/test/resources/3_0/null_schema_test.yaml b/modules/openapi-generator/src/test/resources/3_0/null_schema_test.yaml index b7c370080ca4..e403eeef1397 100644 --- a/modules/openapi-generator/src/test/resources/3_0/null_schema_test.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/null_schema_test.yaml @@ -56,9 +56,9 @@ components: properties: dummy: $ref: '#/components/schemas/IntegerRef' - number: + string_ref: anyOf: - - $ref: '#/components/schemas/Number' + - $ref: '#/components/schemas/StringRef' AnyOfStringArrayOfString: anyOf: - type: string @@ -85,6 +85,8 @@ components: - $ref: '#/components/schemas/IntegerRef' IntegerRef: type: integer + StringRef: + type: string OneOfAnyType: oneOf: - type: object @@ -93,4 +95,13 @@ components: - type: string - type: integer - type: array - items: {} \ No newline at end of file + items: {} + OneOfRef: + oneOf: + - $ref: '#/components/schemas/IntegerRef' + OneOfMultiRef: + oneOf: + - $ref: '#/components/schemas/IntegerRef' + - $ref: '#/components/schemas/StringRef' + JustDescription: + description: A schema with just description \ No newline at end of file diff --git a/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts b/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts index 1941b1646e7c..ec700d2cbdd2 100644 --- a/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts +++ b/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts @@ -173,7 +173,7 @@ export type PetsFilteredPatchRequestPetTypeEnum = typeof PetsFilteredPatchReques * @type PetsPatchRequest * @export */ -export type PetsPatchRequest = Cat | Dog; +export type PetsPatchRequest = Cat | Dog | any; /** @@ -217,11 +217,11 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati }, /** * - * @param {PetsFilteredPatchRequest | null} [petsFilteredPatchRequest] + * @param {PetsFilteredPatchRequest} [petsFilteredPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ - petsFilteredPatch: async (petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options: RawAxiosRequestConfig = {}): Promise => { + petsFilteredPatch: async (petsFilteredPatchRequest?: PetsFilteredPatchRequest, options: RawAxiosRequestConfig = {}): Promise => { const localVarPath = `/pets-filtered`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -250,11 +250,11 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati }, /** * - * @param {PetsPatchRequest | null} [petsPatchRequest] + * @param {PetsPatchRequest} [petsPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ - petsPatch: async (petsPatchRequest?: PetsPatchRequest | null, options: RawAxiosRequestConfig = {}): Promise => { + petsPatch: async (petsPatchRequest?: PetsPatchRequest, options: RawAxiosRequestConfig = {}): Promise => { const localVarPath = `/pets`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -305,11 +305,11 @@ export const DefaultApiFp = function(configuration?: Configuration) { }, /** * - * @param {PetsFilteredPatchRequest | null} [petsFilteredPatchRequest] + * @param {PetsFilteredPatchRequest} [petsFilteredPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.petsFilteredPatch(petsFilteredPatchRequest, options); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = operationServerMap['DefaultApi.petsFilteredPatch']?.[localVarOperationServerIndex]?.url; @@ -317,11 +317,11 @@ export const DefaultApiFp = function(configuration?: Configuration) { }, /** * - * @param {PetsPatchRequest | null} [petsPatchRequest] + * @param {PetsPatchRequest} [petsPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async petsPatch(petsPatchRequest?: PetsPatchRequest | null, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.petsPatch(petsPatchRequest, options); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = operationServerMap['DefaultApi.petsPatch']?.[localVarOperationServerIndex]?.url; @@ -348,20 +348,20 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa }, /** * - * @param {PetsFilteredPatchRequest | null} [petsFilteredPatchRequest] + * @param {PetsFilteredPatchRequest} [petsFilteredPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ - petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options?: RawAxiosRequestConfig): AxiosPromise { + petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig): AxiosPromise { return localVarFp.petsFilteredPatch(petsFilteredPatchRequest, options).then((request) => request(axios, basePath)); }, /** * - * @param {PetsPatchRequest | null} [petsPatchRequest] + * @param {PetsPatchRequest} [petsPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} */ - petsPatch(petsPatchRequest?: PetsPatchRequest | null, options?: RawAxiosRequestConfig): AxiosPromise { + petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig): AxiosPromise { return localVarFp.petsPatch(petsPatchRequest, options).then((request) => request(axios, basePath)); }, }; @@ -387,23 +387,23 @@ export class DefaultApi extends BaseAPI { /** * - * @param {PetsFilteredPatchRequest | null} [petsFilteredPatchRequest] + * @param {PetsFilteredPatchRequest} [petsFilteredPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof DefaultApi */ - public petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options?: RawAxiosRequestConfig) { + public petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig) { return DefaultApiFp(this.configuration).petsFilteredPatch(petsFilteredPatchRequest, options).then((request) => request(this.axios, this.basePath)); } /** * - * @param {PetsPatchRequest | null} [petsPatchRequest] + * @param {PetsPatchRequest} [petsPatchRequest] * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof DefaultApi */ - public petsPatch(petsPatchRequest?: PetsPatchRequest | null, options?: RawAxiosRequestConfig) { + public petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig) { return DefaultApiFp(this.configuration).petsPatch(petsPatchRequest, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts index 29d1f50c615e..26d1ecd4445e 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts @@ -19,7 +19,7 @@ import { HttpFile } from '../http/http'; * Type * @export */ -export type PetsPatchRequest = Cat | Dog; +export type PetsPatchRequest = Cat | Dog | any; /** * @type PetsPatchRequestClass @@ -31,3 +31,4 @@ export class PetsPatchRequestClass { static readonly mapping: {[index: string]: string} | undefined = undefined; } +