-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openapi) OpenAPI Schema extensions
- Loading branch information
Showing
10 changed files
with
86 additions
and
30 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
2 changes: 1 addition & 1 deletion
2
...capi/v3/schema/openapi/Discriminator.java → ...ema/openapi/properties/Discriminator.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
46 changes: 46 additions & 0 deletions
46
asyncapi-core/src/main/java/com/asyncapi/v3/schema/openapi/properties/Extensions.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 @@ | ||
package com.asyncapi.v3.schema.openapi.properties; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @see <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#specification-extensions">Specification Extensions</a> | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonIgnoreProperties({"extensions"}) | ||
public class Extensions { | ||
|
||
private static final Pattern extensionPropertyNamePattern = Pattern.compile("^x-.*"); | ||
|
||
/** | ||
* Extension fields in the form x-extension-field-name for the exposed API. | ||
*/ | ||
@Nullable | ||
@JsonAnyGetter | ||
protected Map<String, Object> extensions; | ||
|
||
@JsonAnySetter | ||
protected final void readExtensionProperty(String name, Object value) { | ||
if (extensionPropertyNamePattern.matcher(name).matches()) { | ||
if (extensions == null) { | ||
extensions = new HashMap<>(); | ||
} | ||
|
||
extensions.put(name, value); | ||
} else { | ||
throw new IllegalArgumentException(String.format("\"%s\" is not valid extension property", name)); | ||
} | ||
} | ||
|
||
} |
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
3 changes: 2 additions & 1 deletion
3
asyncapi-core/src/test/resources/json/v3/schema/openapi/externaldocumentation.json
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"description": "Find more info here", | ||
"url": "https://example.com" | ||
"url": "https://example.com", | ||
"x-extension-property": "value" | ||
} |
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