-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle all types in service deployment properties
- Loading branch information
Showing
21 changed files
with
144 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
modules/api/src/main/java/org/eclipse/xpanse/api/config/OpenApiCustomizerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
package org.eclipse.xpanse.api.config; | ||
|
||
import io.swagger.v3.oas.models.media.MapSchema; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import java.util.Map; | ||
import org.springdoc.core.customizers.OpenApiCustomizer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* This customization is needed to work around an open issue in swagger-core which is used by | ||
* spring-doc for generating the openapi schema. | ||
* <a href="https://github.com/swagger-api/swagger-core/issues/4316">...</a> | ||
* without this fix, the datatype for Object will be shown as Map always. So a | ||
* {@code Map<String, Object>}` | ||
* will be {@code Map<String, Map<String, Object>} and this causes issues in the client. | ||
*/ | ||
@Configuration | ||
public class OpenApiCustomizerConfig { | ||
|
||
@Bean | ||
public OpenApiCustomizer enableArbitraryObjects() { | ||
return openApi -> openApi.getComponents().getSchemas().values().forEach( | ||
this::enableArbitraryObjects); | ||
} | ||
|
||
private void enableArbitraryObjects(Schema<Object> schema) { | ||
if (schema instanceof MapSchema) { | ||
if (schema.getAdditionalProperties() instanceof Schema | ||
&& ((Schema<?>) schema.getAdditionalProperties()).getType() | ||
.equalsIgnoreCase("object")) { | ||
schema.setAdditionalProperties(true); | ||
} | ||
} else if (schema.getType() != null && schema.getType().equalsIgnoreCase("object") | ||
&& schema.getProperties() != null) { | ||
Map<String, Schema> properties = schema.getProperties(); | ||
properties.values().forEach(this::enableArbitraryObjects); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.