forked from loafle/openapi-generator-original
		
	[normalizer] Better handling of schema with just description (any type) (#20461)
* better handling of schema with just description * update
This commit is contained in:
		
							parent
							
								
									4259e92776
								
							
						
					
					
						commit
						760d5e8168
					
				@ -1935,7 +1935,7 @@ public class ModelUtils {
 | 
				
			|||||||
    private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
 | 
					    private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
 | 
				
			||||||
        setValidations.removeAll(effectiveValidations);
 | 
					        setValidations.removeAll(effectiveValidations);
 | 
				
			||||||
        setValidations.stream().forEach(validation -> {
 | 
					        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 class ModelUtils {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // for `type: null`
 | 
					            // 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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else { // 3.0.x or 2.x spec
 | 
					        } 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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -497,9 +497,22 @@ public class ModelUtilsTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        schema = openAPI.getComponents().getSchemas().get("AnyOfTest");
 | 
					        schema = openAPI.getComponents().getSchemas().get("AnyOfTest");
 | 
				
			||||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
 | 
					        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(1)));
 | 
				
			||||||
        assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2)));
 | 
					        assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2)));
 | 
				
			||||||
        assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(3)));
 | 
					        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
 | 
					    @Test
 | 
				
			||||||
 | 
				
			|||||||
@ -56,9 +56,9 @@ components:
 | 
				
			|||||||
      properties:
 | 
					      properties:
 | 
				
			||||||
        dummy:
 | 
					        dummy:
 | 
				
			||||||
          $ref: '#/components/schemas/IntegerRef'
 | 
					          $ref: '#/components/schemas/IntegerRef'
 | 
				
			||||||
        number:
 | 
					        string_ref:
 | 
				
			||||||
          anyOf:
 | 
					          anyOf:
 | 
				
			||||||
            - $ref: '#/components/schemas/Number'
 | 
					            - $ref: '#/components/schemas/StringRef'
 | 
				
			||||||
    AnyOfStringArrayOfString:
 | 
					    AnyOfStringArrayOfString:
 | 
				
			||||||
      anyOf:
 | 
					      anyOf:
 | 
				
			||||||
        - type: string
 | 
					        - type: string
 | 
				
			||||||
@ -85,6 +85,8 @@ components:
 | 
				
			|||||||
        - $ref: '#/components/schemas/IntegerRef'
 | 
					        - $ref: '#/components/schemas/IntegerRef'
 | 
				
			||||||
    IntegerRef:
 | 
					    IntegerRef:
 | 
				
			||||||
      type: integer
 | 
					      type: integer
 | 
				
			||||||
 | 
					    StringRef:
 | 
				
			||||||
 | 
					      type: string
 | 
				
			||||||
    OneOfAnyType:
 | 
					    OneOfAnyType:
 | 
				
			||||||
      oneOf:
 | 
					      oneOf:
 | 
				
			||||||
        - type: object
 | 
					        - type: object
 | 
				
			||||||
@ -94,3 +96,12 @@ components:
 | 
				
			|||||||
        - type: integer
 | 
					        - type: integer
 | 
				
			||||||
        - type: array
 | 
					        - type: array
 | 
				
			||||||
          items: {}
 | 
					          items: {}
 | 
				
			||||||
 | 
					    OneOfRef:
 | 
				
			||||||
 | 
					      oneOf:
 | 
				
			||||||
 | 
					        - $ref: '#/components/schemas/IntegerRef'
 | 
				
			||||||
 | 
					    OneOfMultiRef:
 | 
				
			||||||
 | 
					      oneOf:
 | 
				
			||||||
 | 
					        - $ref: '#/components/schemas/IntegerRef'
 | 
				
			||||||
 | 
					        - $ref: '#/components/schemas/StringRef'
 | 
				
			||||||
 | 
					    JustDescription:
 | 
				
			||||||
 | 
					      description: A schema with just description
 | 
				
			||||||
@ -173,7 +173,7 @@ export type PetsFilteredPatchRequestPetTypeEnum = typeof PetsFilteredPatchReques
 | 
				
			|||||||
 * @type PetsPatchRequest
 | 
					 * @type PetsPatchRequest
 | 
				
			||||||
 * @export
 | 
					 * @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.
 | 
					         * @param {*} [options] Override http request option.
 | 
				
			||||||
         * @throws {RequiredError}
 | 
					         * @throws {RequiredError}
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        petsFilteredPatch: async (petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
 | 
					        petsFilteredPatch: async (petsFilteredPatchRequest?: PetsFilteredPatchRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
 | 
				
			||||||
            const localVarPath = `/pets-filtered`;
 | 
					            const localVarPath = `/pets-filtered`;
 | 
				
			||||||
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
 | 
					            // use dummy base URL string because the URL constructor only accepts absolute URLs.
 | 
				
			||||||
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
 | 
					            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.
 | 
					         * @param {*} [options] Override http request option.
 | 
				
			||||||
         * @throws {RequiredError}
 | 
					         * @throws {RequiredError}
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        petsPatch: async (petsPatchRequest?: PetsPatchRequest | null, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
 | 
					        petsPatch: async (petsPatchRequest?: PetsPatchRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
 | 
				
			||||||
            const localVarPath = `/pets`;
 | 
					            const localVarPath = `/pets`;
 | 
				
			||||||
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
 | 
					            // use dummy base URL string because the URL constructor only accepts absolute URLs.
 | 
				
			||||||
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
 | 
					            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.
 | 
					         * @param {*} [options] Override http request option.
 | 
				
			||||||
         * @throws {RequiredError}
 | 
					         * @throws {RequiredError}
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        async petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
 | 
					        async petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
 | 
				
			||||||
            const localVarAxiosArgs = await localVarAxiosParamCreator.petsFilteredPatch(petsFilteredPatchRequest, options);
 | 
					            const localVarAxiosArgs = await localVarAxiosParamCreator.petsFilteredPatch(petsFilteredPatchRequest, options);
 | 
				
			||||||
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
 | 
					            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
 | 
				
			||||||
            const localVarOperationServerBasePath = operationServerMap['DefaultApi.petsFilteredPatch']?.[localVarOperationServerIndex]?.url;
 | 
					            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.
 | 
					         * @param {*} [options] Override http request option.
 | 
				
			||||||
         * @throws {RequiredError}
 | 
					         * @throws {RequiredError}
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        async petsPatch(petsPatchRequest?: PetsPatchRequest | null, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
 | 
					        async petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
 | 
				
			||||||
            const localVarAxiosArgs = await localVarAxiosParamCreator.petsPatch(petsPatchRequest, options);
 | 
					            const localVarAxiosArgs = await localVarAxiosParamCreator.petsPatch(petsPatchRequest, options);
 | 
				
			||||||
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
 | 
					            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
 | 
				
			||||||
            const localVarOperationServerBasePath = operationServerMap['DefaultApi.petsPatch']?.[localVarOperationServerIndex]?.url;
 | 
					            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.
 | 
					         * @param {*} [options] Override http request option.
 | 
				
			||||||
         * @throws {RequiredError}
 | 
					         * @throws {RequiredError}
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options?: RawAxiosRequestConfig): AxiosPromise<void> {
 | 
					        petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
 | 
				
			||||||
            return localVarFp.petsFilteredPatch(petsFilteredPatchRequest, options).then((request) => request(axios, basePath));
 | 
					            return localVarFp.petsFilteredPatch(petsFilteredPatchRequest, options).then((request) => request(axios, basePath));
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * 
 | 
					         * 
 | 
				
			||||||
         * @param {PetsPatchRequest | null} [petsPatchRequest] 
 | 
					         * @param {PetsPatchRequest} [petsPatchRequest] 
 | 
				
			||||||
         * @param {*} [options] Override http request option.
 | 
					         * @param {*} [options] Override http request option.
 | 
				
			||||||
         * @throws {RequiredError}
 | 
					         * @throws {RequiredError}
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        petsPatch(petsPatchRequest?: PetsPatchRequest | null, options?: RawAxiosRequestConfig): AxiosPromise<void> {
 | 
					        petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
 | 
				
			||||||
            return localVarFp.petsPatch(petsPatchRequest, options).then((request) => request(axios, basePath));
 | 
					            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.
 | 
					     * @param {*} [options] Override http request option.
 | 
				
			||||||
     * @throws {RequiredError}
 | 
					     * @throws {RequiredError}
 | 
				
			||||||
     * @memberof DefaultApi
 | 
					     * @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));
 | 
					        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.
 | 
					     * @param {*} [options] Override http request option.
 | 
				
			||||||
     * @throws {RequiredError}
 | 
					     * @throws {RequiredError}
 | 
				
			||||||
     * @memberof DefaultApi
 | 
					     * @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));
 | 
					        return DefaultApiFp(this.configuration).petsPatch(petsPatchRequest, options).then((request) => request(this.axios, this.basePath));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ import { HttpFile } from '../http/http';
 | 
				
			|||||||
 * Type
 | 
					 * Type
 | 
				
			||||||
 * @export
 | 
					 * @export
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export type PetsPatchRequest = Cat | Dog;
 | 
					export type PetsPatchRequest = Cat | Dog | any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @type PetsPatchRequestClass
 | 
					* @type PetsPatchRequestClass
 | 
				
			||||||
@ -31,3 +31,4 @@ export class PetsPatchRequestClass {
 | 
				
			|||||||
    static readonly mapping: {[index: string]: string} | undefined = undefined;
 | 
					    static readonly mapping: {[index: string]: string} | undefined = undefined;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user