Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[normalizer] Better handling of schema with just description (any type) #20461

Merged
merged 2 commits into from
Jan 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,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 '" + getType(schema) +"'. Ignoring!");
LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) + "'. Ignoring!");
});
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -85,6 +85,8 @@ components:
- $ref: '#/components/schemas/IntegerRef'
IntegerRef:
type: integer
StringRef:
type: string
OneOfAnyType:
oneOf:
- type: object
Expand All @@ -93,4 +95,13 @@ components:
- type: string
- type: integer
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export type PetsFilteredPatchRequestPetTypeEnum = typeof PetsFilteredPatchReques
* @type PetsPatchRequest
* @export
*/
export type PetsPatchRequest = Cat | Dog;
export type PetsPatchRequest = Cat | Dog | any;


/**
Expand Down Expand Up @@ -217,11 +217,11 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
},
/**
*
* @param {PetsFilteredPatchRequest | null} [petsFilteredPatchRequest]
* @param {PetsFilteredPatchRequest} [petsFilteredPatchRequest]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. This fix the incorrect null (as any type is incorrectly treated as null in openapi normalizer)

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
petsFilteredPatch: async (petsFilteredPatchRequest?: PetsFilteredPatchRequest | null, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
petsFilteredPatch: async (petsFilteredPatchRequest?: PetsFilteredPatchRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
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);
Expand Down Expand Up @@ -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<RequestArgs> => {
petsPatch: async (petsPatchRequest?: PetsPatchRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/pets`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
Expand Down Expand Up @@ -305,23 +305,23 @@ 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<void>> {
async petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.petsFilteredPatch(petsFilteredPatchRequest, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['DefaultApi.petsFilteredPatch']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @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<void>> {
async petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.petsPatch(petsPatchRequest, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['DefaultApi.petsPatch']?.[localVarOperationServerIndex]?.url;
Expand All @@ -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<void> {
petsFilteredPatch(petsFilteredPatchRequest?: PetsFilteredPatchRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
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<void> {
petsPatch(petsPatchRequest?: PetsPatchRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
return localVarFp.petsPatch(petsPatchRequest, options).then((request) => request(axios, basePath));
},
};
Expand All @@ -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));
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading