|
| 1 | +/* |
| 2 | + * Copyright 2021 JBoss Inc |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.apicurio.hub.api.codegen.pre; |
| 18 | + |
| 19 | +import io.apicurio.datamodels.models.Schema; |
| 20 | +import io.apicurio.datamodels.models.openapi.v31.OpenApi31Schema; |
| 21 | +import io.apicurio.datamodels.models.union.BooleanUnionValueImpl; |
| 22 | +import io.apicurio.hub.api.codegen.jaxrs.TraversingOpenApi31VisitorAdapter; |
| 23 | + |
| 24 | +/** |
| 25 | + |
| 26 | + */ |
| 27 | +public class OpenApiAdditionalPropertiesDataTypeProcessor extends TraversingOpenApi31VisitorAdapter { |
| 28 | + |
| 29 | + /** |
| 30 | + * @see io.apicurio.datamodels.models.openapi.v31.visitors.OpenApi31VisitorAdapter#visitSchema(io.apicurio.datamodels.models.Schema) |
| 31 | + */ |
| 32 | + @Override |
| 33 | + public void visitSchema(Schema node) { |
| 34 | + OpenApi31Schema schema = (OpenApi31Schema) node; |
| 35 | + if (schema.getAdditionalProperties() != null && (schema.getAdditionalProperties().isSchema() || |
| 36 | + (schema.getAdditionalProperties().isBoolean() && schema.getAdditionalProperties().asBoolean()))) { |
| 37 | + // WORKAROUND: https://github.com/joelittlejohn/jsonschema2pojo/pull/1515 |
| 38 | + schema.setAdditionalProperties(new BooleanUnionValueImpl(Boolean.TRUE)); |
| 39 | + } else { |
| 40 | + schema.setAdditionalProperties(new BooleanUnionValueImpl(Boolean.FALSE)); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments