View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Portions Copyright 2026 Wren Security.
15   */
16  package org.forgerock.api.transform;
17  
18  import com.fasterxml.jackson.annotation.JsonIgnore;
19  import com.fasterxml.jackson.annotation.JsonProperty;
20  import io.swagger.v3.oas.models.media.Schema;
21  import java.util.Objects;
22  import org.forgerock.util.i18n.LocalizableString;
23  
24  /**
25   * Localizable {@link Schema} that replaces all previous Localizable property and model types.
26   * In OpenAPI 3.0, the unified Schema class replaces the separate Property and Model hierarchies.
27   */
28  @SuppressWarnings("rawtypes")
29  class LocalizableSchema extends Schema implements LocalizableTitleAndDescription<Schema> {
30  
31      private LocalizableString locTitle;
32  
33      private LocalizableString locDescription;
34  
35      @Override
36      public Schema title(LocalizableString title) {
37          this.locTitle = title;
38          return this;
39      }
40  
41      @Override
42      public Schema description(LocalizableString desc) {
43          this.locDescription = desc;
44          return this;
45      }
46  
47      @Override
48      public Schema title(String title) {
49          setTitle(title);
50          return this;
51      }
52  
53      @Override
54      public void setTitle(String title) {
55          super.setTitle(title);
56          this.locTitle = new LocalizableString(title);
57      }
58  
59      @Override
60      public Schema description(String description) {
61          setDescription(description);
62          return this;
63      }
64  
65      @Override
66      public void setDescription(String description) {
67          super.setDescription(description);
68          this.locDescription = new LocalizableString(description);
69      }
70  
71      @Override
72      @JsonProperty("title")
73      public LocalizableString getLocalizableTitle() {
74          return locTitle;
75      }
76  
77      @Override
78      @JsonProperty("description")
79      public LocalizableString getLocalizableDescription() {
80          return locDescription;
81      }
82  
83      @Override
84      @JsonIgnore
85      public String getTitle() {
86          return super.getTitle();
87      }
88  
89      @Override
90      @JsonIgnore
91      public String getDescription() {
92          return super.getDescription();
93      }
94  
95      @Override
96      public boolean equals(final Object o) {
97          if (!super.equals(o)) {
98              return false;
99          }
100         if (!(o instanceof LocalizableSchema)) {
101             return false;
102         }
103         final LocalizableSchema other = (LocalizableSchema) o;
104         if (!Objects.equals(locTitle, other.locTitle)) {
105             return false;
106         }
107         if (!Objects.equals(locDescription, other.locDescription)) {
108             return false;
109         }
110         return true;
111     }
112 
113     @Override
114     public int hashCode() {
115         return Objects.hash(super.hashCode(), locTitle, locDescription);
116     }
117 
118 }